2023-03-13 20:44:56 +01:00
|
|
|
mod issues;
|
|
|
|
|
2023-03-10 23:16:35 +01:00
|
|
|
use dagger_sdk::{connect, ContainerExecOptsBuilder};
|
2023-02-25 02:27:01 +01:00
|
|
|
use pretty_assertions::assert_eq;
|
2023-02-05 23:44:06 +01:00
|
|
|
|
2023-02-19 21:37:54 +01:00
|
|
|
#[tokio::test]
|
|
|
|
async fn test_example_container() {
|
2023-02-20 10:10:42 +01:00
|
|
|
let client = connect().await.unwrap();
|
2023-02-05 23:44:06 +01:00
|
|
|
|
2023-02-19 17:43:12 +01:00
|
|
|
let alpine = client.container().from("alpine:3.16.2");
|
2023-02-05 23:44:06 +01:00
|
|
|
|
|
|
|
let out = alpine
|
2023-02-19 17:49:22 +01:00
|
|
|
.exec_opts(
|
2023-02-19 17:21:40 +01:00
|
|
|
ContainerExecOptsBuilder::default()
|
|
|
|
.args(vec!["cat", "/etc/alpine-release"])
|
|
|
|
.build()
|
|
|
|
.unwrap(),
|
2023-02-19 17:49:22 +01:00
|
|
|
)
|
2023-02-19 15:18:25 +01:00
|
|
|
.stdout()
|
2023-02-19 21:37:54 +01:00
|
|
|
.await
|
2023-02-19 15:18:25 +01:00
|
|
|
.unwrap();
|
2023-02-05 23:44:06 +01:00
|
|
|
|
2023-02-17 12:33:16 +01:00
|
|
|
assert_eq!(out, "3.16.2\n".to_string())
|
2023-02-05 23:44:06 +01:00
|
|
|
}
|
2023-02-25 02:27:01 +01:00
|
|
|
|
|
|
|
#[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();
|
|
|
|
|
|
|
|
let alpine = client.container().from("alpine:3.16.2");
|
|
|
|
|
|
|
|
let contents = alpine
|
|
|
|
.fs()
|
|
|
|
.file("/etc/alpine-release")
|
|
|
|
.contents()
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(contents, "3.16.2\n".to_string());
|
|
|
|
|
|
|
|
let out = alpine
|
|
|
|
.exec_opts(
|
|
|
|
ContainerExecOptsBuilder::default()
|
|
|
|
.args(vec!["cat", "/etc/alpine-release"])
|
|
|
|
.build()
|
|
|
|
.unwrap(),
|
|
|
|
)
|
|
|
|
.stdout()
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(out, "3.16.2\n".to_string());
|
|
|
|
|
|
|
|
let id = alpine.id().await.unwrap();
|
|
|
|
let contents = client
|
|
|
|
.container_opts(dagger_sdk::QueryContainerOpts {
|
|
|
|
id: Some(id),
|
|
|
|
platform: None,
|
|
|
|
})
|
|
|
|
.fs()
|
|
|
|
.file("/etc/alpine-release")
|
|
|
|
.contents()
|
|
|
|
.await
|
|
|
|
.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);
|
|
|
|
}
|