mirror of
https://github.com/kjuulh/dagger-rs.git
synced 2025-08-18 13:03:28 +02:00
Compare commits
3 Commits
feat/warni
...
fix/readme
Author | SHA1 | Date | |
---|---|---|---|
0b07e3bbe9
|
|||
4381af0295 | |||
5f9b3a19c0 |
@@ -153,6 +153,7 @@ impl From<&TypeRef> for Scalar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn get_type_from_name<'t>(types: &'t [FullType], name: &'t str) -> Option<&'t FullType> {
|
pub fn get_type_from_name<'t>(types: &'t [FullType], name: &'t str) -> Option<&'t FullType> {
|
||||||
types
|
types
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -258,6 +259,7 @@ pub fn input_values_has_optionals(input_values: &[&InputValue]) -> bool {
|
|||||||
> 0
|
> 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn input_values_is_empty(input_values: &[InputValue]) -> bool {
|
pub fn input_values_is_empty(input_values: &[InputValue]) -> bool {
|
||||||
input_values.len() > 0
|
input_values.len() > 0
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
#![deny(warnings)]
|
||||||
|
|
||||||
mod functions;
|
mod functions;
|
||||||
mod generator;
|
mod generator;
|
||||||
pub mod rust;
|
pub mod rust;
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{copy, Read, Write},
|
io::{copy, Write},
|
||||||
os::unix::prelude::PermissionsExt,
|
os::unix::prelude::PermissionsExt,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
@@ -241,6 +241,7 @@ pub struct SchemaTypes {
|
|||||||
pub full_type: FullType,
|
pub full_type: FullType,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct SchemaDirectivesArgs {
|
pub struct SchemaDirectivesArgs {
|
||||||
@@ -257,6 +258,7 @@ pub struct SchemaDirectives {
|
|||||||
pub args: Option<Vec<Option<SchemaDirectivesArgs>>>,
|
pub args: Option<Vec<Option<SchemaDirectivesArgs>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Schema {
|
pub struct Schema {
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
#![deny(warnings)]
|
||||||
|
|
||||||
pub mod cli_session;
|
pub mod cli_session;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod connect_params;
|
pub mod connect_params;
|
||||||
|
@@ -27,7 +27,7 @@ cargo add dagger-sdk
|
|||||||
```rust
|
```rust
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> eyre::Result<()> {
|
async fn main() -> eyre::Result<()> {
|
||||||
let client = dagger_sdk::connect()?;
|
let client = dagger_sdk::connect().await?;
|
||||||
|
|
||||||
let version = client
|
let version = client
|
||||||
.container()
|
.container()
|
||||||
@@ -46,9 +46,3 @@ And run it like a normal application:
|
|||||||
```bash
|
```bash
|
||||||
cargo run
|
cargo run
|
||||||
```
|
```
|
||||||
|
|
||||||
### Disclaimer
|
|
||||||
|
|
||||||
You are free to use something else than `tokio`, I haven't tested it with
|
|
||||||
anything else, but it should work with any other runtime. We don't rely on it
|
|
||||||
specifically. That might change in the future though.
|
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
#![deny(warnings)]
|
||||||
|
|
||||||
mod client;
|
mod client;
|
||||||
mod gen;
|
mod gen;
|
||||||
mod querybuilder;
|
mod querybuilder;
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
use dagger_sdk::{connect, ContainerExecOptsBuilder};
|
use dagger_sdk::{connect, ContainerExecOpts, ContainerExecOptsBuilder};
|
||||||
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_example_container() {
|
async fn test_example_container() {
|
||||||
@@ -19,3 +20,99 @@ async fn test_example_container() {
|
|||||||
|
|
||||||
assert_eq!(out, "3.16.2\n".to_string())
|
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();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user