mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 17:14:08 +02:00
test running
This commit is contained in:
parent
4ad207f58d
commit
c2f85e009e
5 changed files with 135 additions and 14 deletions
34
src/cloud.rs
34
src/cloud.rs
|
|
@ -10,6 +10,7 @@ use camino::{Utf8Path, Utf8PathBuf};
|
|||
use color_eyre::{eyre::WrapErr, Report, Result};
|
||||
use futures_util::stream::StreamExt;
|
||||
use petname::petname;
|
||||
use reqwest::{Client, Url};
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::Display;
|
||||
use std::fs;
|
||||
|
|
@ -19,7 +20,7 @@ use std::os::unix::fs::MetadataExt;
|
|||
use std::str::FromStr;
|
||||
use std::time::Duration;
|
||||
use tokio::fs::{create_dir_all, remove_dir_all, write};
|
||||
use tokio::time::sleep;
|
||||
use tokio::time::{sleep, timeout};
|
||||
|
||||
#[derive(Clone, Default, Debug, Eq, PartialEq)]
|
||||
pub struct CloudOptions {
|
||||
|
|
@ -143,6 +144,7 @@ impl Cloud {
|
|||
"PHP_IDE_CONFIG=serverName=haze".to_string(),
|
||||
format!("UID={}", uid),
|
||||
format!("GID={}", gid),
|
||||
format!("SQL={}", options.db.name()),
|
||||
];
|
||||
let volumes = vec![
|
||||
format!("{}:/var/www/html", config.sources_root),
|
||||
|
|
@ -286,7 +288,7 @@ impl Cloud {
|
|||
Ok(logs)
|
||||
}
|
||||
|
||||
pub async fn exec(&self, docker: &mut Docker, cmd: Vec<String>) -> Result<()> {
|
||||
pub async fn exec<S: Into<String>>(&self, docker: &mut Docker, cmd: Vec<S>) -> Result<()> {
|
||||
exec_tty(docker, &self.id, "haze", cmd, vec![]).await
|
||||
}
|
||||
|
||||
|
|
@ -369,6 +371,34 @@ impl Cloud {
|
|||
.next()
|
||||
.ok_or(Report::msg("No clouds running matching filter"))
|
||||
}
|
||||
|
||||
pub async fn wait_for_start(&self) -> Result<()> {
|
||||
let client = Client::new();
|
||||
let url = Url::parse(&format!(
|
||||
"http://{}/status.php",
|
||||
self.ip.ok_or(Report::msg("Container not running"))?
|
||||
))?;
|
||||
timeout(Duration::from_secs(5), async {
|
||||
while !client.get(url.clone()).send().await.is_ok() {
|
||||
sleep(Duration::from_millis(100)).await
|
||||
}
|
||||
})
|
||||
.await
|
||||
.wrap_err("Timeout after 5 seconds")
|
||||
}
|
||||
|
||||
pub async fn enable_app<S: Into<String>>(&self, docker: &mut Docker, app: S) -> Result<()> {
|
||||
self.exec(
|
||||
docker,
|
||||
vec![
|
||||
"occ".to_string(),
|
||||
"app:enable".to_string(),
|
||||
app.into(),
|
||||
"--force".to_string(),
|
||||
],
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
async fn setup_workdir(base: &Utf8Path, id: &str) -> Result<Utf8PathBuf> {
|
||||
|
|
|
|||
27
src/main.rs
27
src/main.rs
|
|
@ -96,8 +96,31 @@ async fn main() -> Result<()> {
|
|||
None => eprintln!("{} is not running", cloud.id),
|
||||
}
|
||||
}
|
||||
HazeArgs::Test { .. } => {
|
||||
todo!();
|
||||
HazeArgs::Test { options, path } => {
|
||||
let cloud = Cloud::create(&mut docker, options, &config).await?;
|
||||
cloud.wait_for_start().await?;
|
||||
println!("Installing");
|
||||
cloud
|
||||
.exec(&mut docker, vec!["install", "admin", "admin"])
|
||||
.await?;
|
||||
if let Some(app) = path
|
||||
.as_ref()
|
||||
.and_then(|path| path.strip_prefix("apps/"))
|
||||
.map(|path| &path[0..path.find('/').unwrap_or(path.len())])
|
||||
{
|
||||
if app.starts_with("files_") {
|
||||
cloud.enable_app(&mut docker, "files_external").await?;
|
||||
}
|
||||
println!("Enabling {}", app);
|
||||
cloud.enable_app(&mut docker, app).await?;
|
||||
}
|
||||
cloud
|
||||
.exec(
|
||||
&mut docker,
|
||||
vec!["tests".to_string(), path.unwrap_or_default()],
|
||||
)
|
||||
.await?;
|
||||
cloud.destroy(&mut docker).await?;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue