From 0ad360ba1a5a0fffbd3e3859bc0da8f040d8501c Mon Sep 17 00:00:00 2001 From: Florian Fromm Date: Mon, 20 Mar 2023 18:29:14 +0100 Subject: [PATCH] chore: restructure organisation of tests folder --- crates/dagger-sdk/tests/integration_tests.rs | 2 + .../{mod.rs => standard_apis/container.rs} | 58 ------------------- .../tests/standard_apis/directory.rs | 17 ++++++ crates/dagger-sdk/tests/standard_apis/git.rs | 27 +++++++++ crates/dagger-sdk/tests/standard_apis/mod.rs | 22 +++++++ 5 files changed, 68 insertions(+), 58 deletions(-) create mode 100644 crates/dagger-sdk/tests/integration_tests.rs rename crates/dagger-sdk/tests/{mod.rs => standard_apis/container.rs} (51%) create mode 100644 crates/dagger-sdk/tests/standard_apis/directory.rs create mode 100644 crates/dagger-sdk/tests/standard_apis/git.rs create mode 100644 crates/dagger-sdk/tests/standard_apis/mod.rs diff --git a/crates/dagger-sdk/tests/integration_tests.rs b/crates/dagger-sdk/tests/integration_tests.rs new file mode 100644 index 0000000..5c96629 --- /dev/null +++ b/crates/dagger-sdk/tests/integration_tests.rs @@ -0,0 +1,2 @@ +mod issues; +mod standard_apis; diff --git a/crates/dagger-sdk/tests/mod.rs b/crates/dagger-sdk/tests/standard_apis/container.rs similarity index 51% rename from crates/dagger-sdk/tests/mod.rs rename to crates/dagger-sdk/tests/standard_apis/container.rs index 9611f64..3635961 100644 --- a/crates/dagger-sdk/tests/mod.rs +++ b/crates/dagger-sdk/tests/standard_apis/container.rs @@ -1,5 +1,3 @@ -mod issues; - use dagger_sdk::{connect, ContainerExecOptsBuilder}; use pretty_assertions::assert_eq; @@ -23,46 +21,6 @@ async fn test_example_container() { assert_eq!(out, "3.16.2\n".to_string()) } -#[tokio::test] -async fn test_directory() { - let c = connect().await.unwrap(); - - let contents = c - .directory() - .with_new_file("/hello.txt", "world") - .file("/hello.txt") - .contents() - .await - .unwrap(); - - assert_eq!("world", contents) -} - -#[tokio::test] -async fn test_git() { - let c = connect().await.unwrap(); - - let tree = c.git("github.com/dagger/dagger").branch("main").tree(); - - let _ = tree - .entries() - .await - .unwrap() - .iter() - .find(|f| f.as_str() == "README.md") - .unwrap(); - - let readme_file = tree.file("README.md"); - - let readme = readme_file.contents().await.unwrap(); - assert_eq!(true, readme.find("Dagger").is_some()); - - let readme_id = readme_file.id().await.unwrap(); - let other_readme = c.file(readme_id).contents().await.unwrap(); - - assert_eq!(readme, other_readme); -} - #[tokio::test] async fn test_container() { let client = connect().await.unwrap(); @@ -102,19 +60,3 @@ async fn test_container() { .unwrap(); assert_eq!(contents, "3.16.2\n".to_string()); } - -#[tokio::test] -async fn test_err_message() { - let client = connect().await.unwrap(); - - let alpine = client.container().from("fake.invalid:latest").id().await; - assert_eq!(alpine.is_err(), true); - let err = alpine.expect_err("Tests expect err"); - - let error_msg = r#" -GQLClient Error: Look at json field for more details -Message: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed -"#; - - assert_eq!(err.to_string().as_str(), error_msg); -} diff --git a/crates/dagger-sdk/tests/standard_apis/directory.rs b/crates/dagger-sdk/tests/standard_apis/directory.rs new file mode 100644 index 0000000..f54c091 --- /dev/null +++ b/crates/dagger-sdk/tests/standard_apis/directory.rs @@ -0,0 +1,17 @@ +use dagger_sdk::{connect, ContainerExecOptsBuilder}; +use pretty_assertions::assert_eq; + +#[tokio::test] +async fn test_directory() { + let c = connect().await.unwrap(); + + let contents = c + .directory() + .with_new_file("/hello.txt", "world") + .file("/hello.txt") + .contents() + .await + .unwrap(); + + assert_eq!("world", contents) +} diff --git a/crates/dagger-sdk/tests/standard_apis/git.rs b/crates/dagger-sdk/tests/standard_apis/git.rs new file mode 100644 index 0000000..590499d --- /dev/null +++ b/crates/dagger-sdk/tests/standard_apis/git.rs @@ -0,0 +1,27 @@ +use dagger_sdk::{connect, ContainerExecOptsBuilder}; +use pretty_assertions::assert_eq; + +#[tokio::test] +async fn test_git() { + let c = connect().await.unwrap(); + + let tree = c.git("github.com/dagger/dagger").branch("main").tree(); + + let _ = tree + .entries() + .await + .unwrap() + .iter() + .find(|f| f.as_str() == "README.md") + .unwrap(); + + let readme_file = tree.file("README.md"); + + let readme = readme_file.contents().await.unwrap(); + assert_eq!(true, readme.find("Dagger").is_some()); + + let readme_id = readme_file.id().await.unwrap(); + let other_readme = c.file(readme_id).contents().await.unwrap(); + + assert_eq!(readme, other_readme); +} diff --git a/crates/dagger-sdk/tests/standard_apis/mod.rs b/crates/dagger-sdk/tests/standard_apis/mod.rs new file mode 100644 index 0000000..3f69e0a --- /dev/null +++ b/crates/dagger-sdk/tests/standard_apis/mod.rs @@ -0,0 +1,22 @@ +mod container; +mod directory; +mod git; + +use dagger_sdk::connect; +use pretty_assertions::assert_eq; + +#[tokio::test] +async fn test_err_message() { + let client = connect().await.unwrap(); + + let alpine = client.container().from("fake.invalid:latest").id().await; + assert_eq!(alpine.is_err(), true); + let err = alpine.expect_err("Tests expect err"); + + let error_msg = r#" +GQLClient Error: Look at json field for more details +Message: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed +"#; + + assert_eq!(err.to_string().as_str(), error_msg); +}