mirror of
https://github.com/kjuulh/dagger-rs.git
synced 2024-11-25 16:32:42 +01:00
add tests
This commit is contained in:
parent
c4edd29f50
commit
19b46b6cf0
@ -19,30 +19,24 @@ pub fn render_fields(fields: &Vec<FullTypeFields>) -> eyre::Result<Option<rust::
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut tkns = rust::Tokens::new();
|
let mut tkns = rust::Tokens::new();
|
||||||
if let Some(desc) = &description {
|
|
||||||
tkns.append(desc);
|
|
||||||
tkns.push()
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(args) = args.as_ref() {
|
if let Some(args) = args.as_ref() {
|
||||||
if let Some(desc) = args.description.as_ref() {
|
tkns.append(quote! {
|
||||||
tkns.append("/// # Arguments");
|
$description
|
||||||
tkns.push();
|
pub struct $(&name)Args {
|
||||||
tkns.append("///");
|
$(&args.args)
|
||||||
tkns.push();
|
}
|
||||||
tkns.append(desc);
|
});
|
||||||
tkns.push();
|
tkns.push();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tkns.append(quote! {
|
tkns.append(quote! {
|
||||||
pub fn $name(
|
pub fn $(&name)(
|
||||||
&self,
|
&self,
|
||||||
$(if let Some(args) = args.as_ref() => $(&args.args))
|
$(if let Some(_) = args.as_ref() => args: $(&name)Args)
|
||||||
) -> $(&output) {
|
) -> $(&output) {
|
||||||
let query = self.selection.select("$(field.name.as_ref())");
|
let query = self.selection.select($(field.name.as_ref().map(|n| format!("\"{}\"", n))));
|
||||||
|
$(if let Some(_) = args.as_ref() => query.args(args);)
|
||||||
let query = query.arg("args", args).unwrap();
|
|
||||||
|
|
||||||
$output {
|
$output {
|
||||||
conn: self.conn.clone(),
|
conn: self.conn.clone(),
|
||||||
|
@ -96,15 +96,11 @@ mod tests {
|
|||||||
fields: None,
|
fields: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let expected = r#"use dagger_core::Input;
|
let expected = r#"pub struct BuildArg {
|
||||||
|
pub name: String,
|
||||||
|
|
||||||
pub struct BuildArg {
|
pub value: String,
|
||||||
pub name: Option<String>,
|
|
||||||
|
|
||||||
pub value: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Input for BuildArg {}
|
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let output = input.render(&t).unwrap();
|
let output = input.render(&t).unwrap();
|
||||||
|
@ -19,8 +19,6 @@ impl Handler for Object {
|
|||||||
.ok_or(eyre::anyhow!("could not find name"))?;
|
.ok_or(eyre::anyhow!("could not find name"))?;
|
||||||
let description = render_description(t);
|
let description = render_description(t);
|
||||||
|
|
||||||
let input = rust::import("dagger_core", "Input");
|
|
||||||
|
|
||||||
let fields = match t.fields.as_ref() {
|
let fields = match t.fields.as_ref() {
|
||||||
Some(i) => fields::render_fields(i)?,
|
Some(i) => fields::render_fields(i)?,
|
||||||
None => None,
|
None => None,
|
||||||
@ -40,8 +38,6 @@ impl Handler for Object {
|
|||||||
impl $name {
|
impl $name {
|
||||||
$(if fields.is_some() => $fields)
|
$(if fields.is_some() => $fields)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl $input for $name {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(out)
|
Ok(out)
|
||||||
@ -51,7 +47,8 @@ impl Handler for Object {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use dagger_core::introspection::{
|
use dagger_core::introspection::{
|
||||||
FullType, FullTypeFields, FullTypeFieldsType, TypeRef, __TypeKind,
|
FullType, FullTypeFields, FullTypeFieldsArgs, FullTypeFieldsType, InputValue, TypeRef,
|
||||||
|
__TypeKind,
|
||||||
};
|
};
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
@ -88,21 +85,75 @@ mod tests {
|
|||||||
enum_values: None,
|
enum_values: None,
|
||||||
possible_types: None,
|
possible_types: None,
|
||||||
};
|
};
|
||||||
let expected = r#"use dagger_core::Input;
|
let expected = r#"
|
||||||
|
|
||||||
|
|
||||||
/// A directory whose contents persists across sessions
|
/// A directory whose contents persists across sessions
|
||||||
pub struct CacheVolume {}
|
pub struct CacheVolume {}
|
||||||
|
|
||||||
impl CacheVolume {
|
impl CacheVolume {
|
||||||
pub fn id(
|
pub fn id(
|
||||||
&self,
|
&self,
|
||||||
) -> Option<CacheID> {
|
) -> CacheID {
|
||||||
|
let query = self.selection.select("id");
|
||||||
|
|
||||||
|
CacheID {
|
||||||
|
conn: self.conn.clone(),
|
||||||
|
proc: self.proc.clone(),
|
||||||
|
selection: query,
|
||||||
|
}
|
||||||
|
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"#;
|
||||||
|
let handler = Object {};
|
||||||
|
let obj = handler.render(&t).unwrap();
|
||||||
|
let actual = obj.to_file_string().unwrap();
|
||||||
|
|
||||||
impl Input for CacheVolume {}
|
assert_eq!(actual, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_render_query_container() {
|
||||||
|
let t: FullType = FullType {
|
||||||
|
kind: Some(__TypeKind::OBJECT),
|
||||||
|
name: Some("Query".into()),
|
||||||
|
description: None,
|
||||||
|
fields: Some(vec![FullTypeFields {
|
||||||
|
name: Some("container".into()),
|
||||||
|
description: Some("Loads a container from ID.\nNull ID returns an empty container (scratch).\nOptional platform argument initializes new containers to execute and publish as that platform. Platform defaults to that of the builder's host.".into()),
|
||||||
|
args: Some(vec![
|
||||||
|
Some(
|
||||||
|
FullTypeFieldsArgs
|
||||||
|
{
|
||||||
|
input_value: InputValue { name: "id".into(), description: None, type_: TypeRef { kind: Some(__TypeKind::SCALAR), name: Some("ContainerID".into()), of_type: None }, default_value: None }
|
||||||
|
}),
|
||||||
|
Some(
|
||||||
|
FullTypeFieldsArgs {
|
||||||
|
input_value: InputValue {
|
||||||
|
name: "platform".into(), description: None, type_: TypeRef { kind: Some(__TypeKind::SCALAR), name: Some("Platform".into()), of_type: None },
|
||||||
|
default_value: None }
|
||||||
|
})
|
||||||
|
]),
|
||||||
|
type_: Some(FullTypeFieldsType {
|
||||||
|
type_ref: TypeRef {
|
||||||
|
kind: Some(__TypeKind::NON_NULL),
|
||||||
|
name: None,
|
||||||
|
of_type: Some(Box::new(TypeRef {
|
||||||
|
kind: Some(__TypeKind::SCALAR),
|
||||||
|
name: Some("CacheID".into()),
|
||||||
|
of_type: None,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
is_deprecated: Some(false),
|
||||||
|
deprecation_reason: None,
|
||||||
|
}]),
|
||||||
|
input_fields: None,
|
||||||
|
interfaces: None,
|
||||||
|
enum_values: None,
|
||||||
|
possible_types: None,
|
||||||
|
};
|
||||||
|
let expected = r#"
|
||||||
"#;
|
"#;
|
||||||
let handler = Object {};
|
let handler = Object {};
|
||||||
let obj = handler.render(&t).unwrap();
|
let obj = handler.render(&t).unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user