-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd79fd5
commit cf7904e
Showing
11 changed files
with
296 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use std::ffi; | ||
|
||
use assert_cmd::{assert::Assert, Command}; | ||
|
||
pub(crate) fn run<I, S>(args: I) -> Assert | ||
where | ||
I: IntoIterator<Item = S>, | ||
S: AsRef<ffi::OsStr>, | ||
{ | ||
Command::cargo_bin("daikoku").unwrap().args(args).run() | ||
} | ||
|
||
pub(crate) trait AssertCommand { | ||
fn run(&mut self) -> Assert; | ||
} | ||
|
||
impl AssertCommand for Command { | ||
fn run(&mut self) -> Assert { | ||
self.assert().success() | ||
} | ||
} | ||
|
||
pub struct Environment {} | ||
|
||
impl Environment { | ||
pub(crate) fn info(name: &str) -> Assert { | ||
run(["environments", "info", format!("--name={}", name).as_str()]) | ||
} | ||
|
||
pub(crate) fn clear(force: bool) -> Assert { | ||
run([ | ||
"environments", | ||
"clear", | ||
format!("--force={}", force.to_string()).as_str(), | ||
]) | ||
} | ||
|
||
pub(crate) fn add(name: &str, daikoku_ip: &str /* apikey: String*/) -> Assert { | ||
run([ | ||
"environments", | ||
"add", | ||
format!("--name={}", name).as_str(), | ||
format!("--server=http://{}:8080", daikoku_ip).as_str(), | ||
"--apikey=amJ1UWtEYWpZZThWVTU0a2RjVW1oWjhWM0I1Q0NmV1I6eTJXNmtYV21yRzBxdm8xU2psSjdYU1M0ZEE5cGc5dDlZZ25wMTlIOXR5cUJaZE5NSkZDQmRJUXVKQ3haMXk4VQ==" | ||
]) | ||
} | ||
|
||
pub(crate) fn switch(name: &str) -> Assert { | ||
run([ | ||
"environments", | ||
"switch", | ||
format!("--name={}", name).as_str(), | ||
]) | ||
} | ||
|
||
pub(crate) fn login() -> Assert { | ||
run(["login"]) | ||
} | ||
} | ||
|
||
pub struct Cms {} | ||
|
||
impl Cms { | ||
pub(crate) fn clear(force: bool) -> Assert { | ||
run([ | ||
"cms", | ||
"clear", | ||
format!("--force={}", force.to_string()).as_str(), | ||
]) | ||
} | ||
|
||
pub(crate) fn init(name: &str, path: String) -> Assert { | ||
run([ | ||
"cms", | ||
"init", | ||
format!("--name={}", name).as_str(), | ||
format!("--path={}", path).as_str(), | ||
]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod cli; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,52 @@ | ||
// use assert_cmd::prelude::*; | ||
// use serial_test::serial; | ||
// use std::fs; | ||
use testcontainers::{ | ||
core::{IntoContainerPort, WaitFor}, | ||
runners::AsyncRunner, | ||
GenericImage, ImageExt, | ||
}; | ||
|
||
// const WASMO_TEST_FOLDER: &str = "/tmp/daikoku"; | ||
// struct Setup { | ||
// temporary_path: String, | ||
// } | ||
|
||
// impl Setup { | ||
// fn new() -> Self { | ||
// let temporary_path = WASMO_TEST_FOLDER.to_string(); | ||
|
||
// let _ = fs::remove_dir_all(&temporary_path); | ||
|
||
// match fs::create_dir(&temporary_path) { | ||
// Err(err) => println!("{:?}", err), | ||
// Ok(v) => println!("{:?}", v), | ||
// } | ||
// Setup { | ||
// temporary_path: temporary_path, | ||
// } | ||
// } | ||
|
||
// fn clean(&self) { | ||
// fs::remove_dir_all(&self.temporary_path).expect("Failed to remove folder") | ||
// } | ||
// } | ||
mod commands; | ||
mod setup; | ||
|
||
use std::fs; | ||
|
||
use commands::cli::{Cms, Environment}; | ||
use setup::start_containers; | ||
|
||
async fn create_cms() -> Result<(), Box<dyn std::error::Error + 'static>> { | ||
let temporary_path = std::env::temp_dir() | ||
.join("daikoku") | ||
.into_os_string() | ||
.into_string() | ||
.unwrap(); | ||
|
||
let _ = fs::remove_dir_all(&temporary_path); | ||
|
||
Cms::clear(true); | ||
|
||
let _ = fs::create_dir(&temporary_path); | ||
|
||
Cms::init("cms", temporary_path); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn test_check_info_of_environment() { | ||
let result = Environment::info("dev"); | ||
let output = String::from_utf8(result.get_output().stdout.clone()).unwrap(); | ||
|
||
assert!(output.contains("http://localhost:8080")); | ||
assert!(output.contains("dev")); | ||
} | ||
|
||
#[tokio::test] | ||
async fn login() -> Result<(), Box<dyn std::error::Error + 'static>> { | ||
let postgres = GenericImage::new("postgres", "13") | ||
.with_exposed_port(5432.tcp()) | ||
.with_wait_for(WaitFor::seconds(1)) | ||
.with_env_var("POSTGRES_USER", "postgres") | ||
.with_env_var("POSTGRES_PASSWORD", "postgres") | ||
.with_env_var("POSTGRES_DB", "daikoku"); | ||
let (_postgres_container, _daikoku_container) = start_containers().await?; | ||
|
||
let daikoku_ip = "localhost"; //daikoku_container.get_host().await?.to_string(); | ||
|
||
create_cms().await?; | ||
|
||
let daikoku = GenericImage::new("maif/daikoku", "17.5.0") | ||
.with_wait_for(WaitFor::seconds(1)) | ||
.with_env_var("daikoku.mode", "dev") | ||
.with_env_var("Ddaikoku.postgres.database", "daikoku") | ||
.with_env_var("daikoku.exposedOn", "9000"); | ||
Environment::add("dev", &daikoku_ip); | ||
|
||
let postgres_container = postgres.start().await?; | ||
let daikoku_container = daikoku.start().await?; | ||
test_check_info_of_environment(); | ||
|
||
println!("{:#?}", postgres_container); | ||
Environment::switch("dev"); | ||
|
||
|
||
Environment::login(); | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.