diff --git a/Cargo.lock b/Cargo.lock index 3c40f0bcb..313937dee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2334,6 +2334,7 @@ dependencies = [ "handlebars", "prettyplease", "proc-macro2", + "quote", "regex", "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 629dddfdc..ac91d84af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,4 +86,5 @@ directories = "5.0" reqwest = "0.12.5" wit-component = "0.221.0" wit-parser = "0.221.0" -bon = "3.0.0" \ No newline at end of file +bon = "3.0.0" +proc-macro2 = "1.0.92" \ No newline at end of file diff --git a/pulumi_wasm_generator_lib/Cargo.toml b/pulumi_wasm_generator_lib/Cargo.toml index 2bf63f7e8..1529fee3b 100644 --- a/pulumi_wasm_generator_lib/Cargo.toml +++ b/pulumi_wasm_generator_lib/Cargo.toml @@ -13,9 +13,10 @@ handlebars.workspace = true regex.workspace = true convert_case.workspace = true serde_yaml.workspace = true -prettyplease = "0.2.25" -syn = "2.0.90" -proc-macro2 = "1.0.92" +prettyplease.workspace = true +syn.workspace = true +quote.workspace = true +proc-macro2.workspace = true [dev-dependencies] assert_cmd.workspace = true diff --git a/pulumi_wasm_generator_lib/src/code_generation/mod.rs b/pulumi_wasm_generator_lib/src/code_generation/mod.rs new file mode 100644 index 000000000..74bacb50c --- /dev/null +++ b/pulumi_wasm_generator_lib/src/code_generation/mod.rs @@ -0,0 +1,21 @@ +use crate::code_generation::rust_generation::generate_code; +use crate::code_generation::yaml::model::yaml_to_model; +use crate::code_generation::yaml::yaml_model::YamlFile; +use anyhow::anyhow; +use anyhow::Context; +use std::panic; +pub(crate) mod rust_generation; +mod tests; +pub(crate) mod yaml; + +pub fn generate_code_from_string( + yaml: String, + package: &crate::model::Package, +) -> anyhow::Result { + let yaml_file = + YamlFile::from_yaml(yaml.as_str()).context(format!("Failed to parse YAML: {}", yaml))?; + let example = panic::catch_unwind(|| yaml_to_model(yaml_file, package.name.clone(), package)) + .map_err(|_| anyhow!("Failed to convert YAML to model")) + .context(format!("Failed to convert YAML {} to model", yaml))?; + generate_code(example) +} diff --git a/pulumi_wasm_generator_lib/src/code_generation.rs b/pulumi_wasm_generator_lib/src/code_generation/rust_generation.rs similarity index 63% rename from pulumi_wasm_generator_lib/src/code_generation.rs rename to pulumi_wasm_generator_lib/src/code_generation/rust_generation.rs index 933c4f4c0..dcd587275 100644 --- a/pulumi_wasm_generator_lib/src/code_generation.rs +++ b/pulumi_wasm_generator_lib/src/code_generation/rust_generation.rs @@ -1,23 +1,15 @@ +use crate::code_generation::yaml::model::Example; +use crate::code_generation::yaml::model::Expression; +use crate::code_generation::yaml::model::Resource; use crate::model::ElementId; use crate::utils::escape_rust_name; -use crate::yaml::model::{yaml_to_model, Example, Expression, Resource}; -use crate::yaml::yaml_model::YamlFile; -use anyhow::{anyhow, Context, Result}; +use anyhow::Context; +use anyhow::Result; use convert_case::Case; use convert_case::Casing; +use quote::ToTokens; use std::collections::BTreeMap; -use std::panic; use syn::LitStr; -use syn::__private::ToTokens; - -pub fn generate_code_from_string(yaml: String, package: &crate::model::Package) -> Result { - let yaml_file = - YamlFile::from_yaml(yaml.as_str()).context(format!("Failed to parse YAML: {}", yaml))?; - let example = panic::catch_unwind(|| yaml_to_model(yaml_file, package.name.clone(), package)) - .map_err(|_| anyhow!("Failed to convert YAML to model")) - .context(format!("Failed to convert YAML {} to model", yaml))?; - generate_code(example) -} pub fn generate_code(example: Example) -> Result { let mut result = r" @@ -139,47 +131,3 @@ fn generate_expression(expr: Expression) -> String { } } } - -#[cfg(test)] -mod tests { - use crate::code_generation::generate_code; - use crate::yaml::tests::{ - access_rule, example_array, example_empty_properties, example_escape_string, - example_numbers, - }; - - #[test] - fn test_example_array() { - let model = example_array::get_model(); - let code = generate_code(model).unwrap(); - assert_eq!(example_array::get_rust_code(), code) - } - - #[test] - fn test_access_rule() { - let model = access_rule::get_model(); - let code = generate_code(model).unwrap(); - assert_eq!(access_rule::get_rust_code(), code) - } - - #[test] - fn test_without_parameters() { - let model = example_empty_properties::get_model(); - let code = generate_code(model).unwrap(); - assert_eq!(example_empty_properties::get_rust_code(), code) - } - - #[test] - fn test_numbers() { - let model = example_numbers::get_model(); - let code = generate_code(model).unwrap(); - assert_eq!(example_numbers::get_rust_code(), code) - } - - #[test] - fn test_string_escape() { - let model = example_escape_string::get_model(); - let code = generate_code(model).unwrap(); - assert_eq!(example_escape_string::get_rust_code(), code) - } -} diff --git a/pulumi_wasm_generator_lib/src/code_generation/tests.rs b/pulumi_wasm_generator_lib/src/code_generation/tests.rs new file mode 100644 index 000000000..bdd34e51a --- /dev/null +++ b/pulumi_wasm_generator_lib/src/code_generation/tests.rs @@ -0,0 +1,67 @@ +#[cfg(test)] +mod tests { + use crate::code_generation::yaml::model::yaml_to_model; + use crate::code_generation::yaml::tests::*; + use crate::code_generation::YamlFile; + use crate::{extract_schema_from_file, schema}; + + use crate::code_generation::rust_generation::generate_code; + use crate::code_generation::yaml::tests::{ + example_array, example_empty_properties, example_escape_string, example_numbers, + }; + + macro_rules! yaml_deserialization_test { + ($test_name:ident, $test_module:ident) => { + #[test] + fn $test_name() { + let yaml_file = YamlFile::from_yaml($test_module::YAML).unwrap(); + let expected_yaml_file = $test_module::get_yaml_file(); + assert_eq!(yaml_file, expected_yaml_file); + } + }; + } + + yaml_deserialization_test!(generate_yaml_complex_yaml, complex_yaml); + + macro_rules! full_pipeline_test { + ($test_name:ident, $package_name:expr, $test_module:ident) => { + #[test] + fn $test_name() { + let yaml_file = YamlFile::from_yaml($test_module::YAML).unwrap(); + let expected_yaml_file = $test_module::get_yaml_file(); + assert_eq!(yaml_file, expected_yaml_file); + + let schema_package: schema::Package = extract_schema_from_file( + concat!("test_cases/", $package_name, ".json").as_ref(), + ) + .unwrap(); + let package = schema::to_model(&schema_package).unwrap(); + let yaml_file = $test_module::get_yaml_file(); + let result = yaml_to_model(yaml_file, $package_name.to_string(), &package); + assert_eq!(result, $test_module::get_model()); + + let model = $test_module::get_model(); + let code = generate_code(model).unwrap(); + assert_eq!($test_module::get_rust_code(), code); + } + }; + } + + full_pipeline_test!(full_pipeline_example_array, "cloudflare", example_array); + full_pipeline_test!( + full_pipeline_example_empty_properties, + "cloudflare", + example_empty_properties + ); + full_pipeline_test!( + full_pipeline_example_escape_string, + "cloudflare", + example_escape_string + ); + full_pipeline_test!(full_pipeline_example_numbers, "cloudflare", example_numbers); + full_pipeline_test!( + full_pipeline_example_variable, + "cloudflare", + example_variable + ); +} diff --git a/pulumi_wasm_generator_lib/src/code_generation/yaml/mod.rs b/pulumi_wasm_generator_lib/src/code_generation/yaml/mod.rs new file mode 100644 index 000000000..7962fdedd --- /dev/null +++ b/pulumi_wasm_generator_lib/src/code_generation/yaml/mod.rs @@ -0,0 +1,4 @@ +pub(crate) mod model; +#[cfg(test)] +pub(crate) mod tests; +pub(crate) mod yaml_model; diff --git a/pulumi_wasm_generator_lib/src/yaml/model.rs b/pulumi_wasm_generator_lib/src/code_generation/yaml/model.rs similarity index 76% rename from pulumi_wasm_generator_lib/src/yaml/model.rs rename to pulumi_wasm_generator_lib/src/code_generation/yaml/model.rs index 597a9b07b..0fba38ec9 100644 --- a/pulumi_wasm_generator_lib/src/yaml/model.rs +++ b/pulumi_wasm_generator_lib/src/code_generation/yaml/model.rs @@ -1,5 +1,5 @@ +use crate::code_generation::yaml::yaml_model::{YamlExpression, YamlFile, YamlResource}; use crate::model::{ElementId, GlobalType, Package, Ref, Type}; -use crate::yaml::yaml_model::{YamlExpression, YamlFile, YamlResource}; use std::collections::{BTreeMap, HashMap}; struct PackageContext<'a> { @@ -207,58 +207,3 @@ fn map_type( Expression::Object(element_id.clone(), new_properties) } - -#[cfg(test)] -mod tests { - use super::*; - use crate::yaml::tests::{ - access_rule, example_access_organization, example_array, example_numbers, - }; - use crate::{extract_schema_from_file, schema}; - - #[test] - fn test_map_expression() { - let schema_package: schema::Package = - extract_schema_from_file("test_cases/cloudflare.json".as_ref()).unwrap(); - let package = schema::to_model(&schema_package).unwrap(); - let yaml_file = example_access_organization::get_yaml_file(); - - yaml_to_model(yaml_file, "cloudflare".to_string(), &package); - } - - #[test] - fn test_access_rule() { - let schema_package: schema::Package = - extract_schema_from_file("test_cases/cloudflare.json".as_ref()).unwrap(); - let package = schema::to_model(&schema_package).unwrap(); - let yaml_file = access_rule::get_yaml_file(); - - let result = yaml_to_model(yaml_file, "cloudflare".to_string(), &package); - - assert_eq!(result, access_rule::get_model()); - } - - #[test] - fn test_example_array() { - let schema_package: schema::Package = - extract_schema_from_file("test_cases/cloudflare.json".as_ref()).unwrap(); - let package = schema::to_model(&schema_package).unwrap(); - let yaml_file = example_array::get_yaml_file(); - - let result = yaml_to_model(yaml_file, "cloudflare".to_string(), &package); - - assert_eq!(result, example_array::get_model()); - } - - #[test] - fn test_example_numbers() { - let schema_package: schema::Package = - extract_schema_from_file("test_cases/cloudflare.json".as_ref()).unwrap(); - let package = schema::to_model(&schema_package).unwrap(); - let yaml_file = example_numbers::get_yaml_file(); - - let result = yaml_to_model(yaml_file, "cloudflare".to_string(), &package); - - assert_eq!(result, example_numbers::get_model()); - } -} diff --git a/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/complex_yaml.rs b/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/complex_yaml.rs new file mode 100644 index 000000000..10434aa96 --- /dev/null +++ b/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/complex_yaml.rs @@ -0,0 +1,94 @@ +use crate::code_generation::YamlFile; + +//language=YAML +pub const YAML: &str = r#" + resources: + petstoreSchema: + type: cloudflare:ApiShieldSchema + name: petstore_schema + properties: + zoneId: 0da42c8d2132a9ddaf714f9e7c920711 + name: myschema + kind: openapi_v3 + validationEnabled: true + source: + fn::invoke: + Function: std:file + Arguments: + input: ./schemas/petstore.json + Return: result +"#; + +pub fn get_yaml_file() -> YamlFile { + use crate::code_generation::yaml::yaml_model::{YamlExpression, YamlFile, YamlResource}; + use std::collections::BTreeMap; + + YamlFile { + resources: { + let mut resources = BTreeMap::new(); + resources.insert( + "petstoreSchema".to_string(), + YamlResource { + type_: "cloudflare:ApiShieldSchema".to_string(), + name: Some("petstore_schema".to_string()), + properties: { + let mut properties = BTreeMap::new(); + properties.insert( + "zoneId".to_string(), + YamlExpression::String("0da42c8d2132a9ddaf714f9e7c920711".to_string()), + ); + properties.insert( + "name".to_string(), + YamlExpression::String("myschema".to_string()), + ); + properties.insert( + "kind".to_string(), + YamlExpression::String("openapi_v3".to_string()), + ); + properties.insert( + "validationEnabled".to_string(), + YamlExpression::Boolean(true), + ); + properties.insert( + "source".to_string(), + YamlExpression::Object({ + let mut source = BTreeMap::new(); + source.insert( + "fn::invoke".to_string(), + YamlExpression::Object({ + let mut fn_invoke = BTreeMap::new(); + fn_invoke.insert( + "Function".to_string(), + YamlExpression::String("std:file".to_string()), + ); + fn_invoke.insert( + "Arguments".to_string(), + YamlExpression::Object({ + let mut arguments = BTreeMap::new(); + arguments.insert( + "input".to_string(), + YamlExpression::String( + "./schemas/petstore.json".to_string(), + ), + ); + arguments + }), + ); + fn_invoke.insert( + "Return".to_string(), + YamlExpression::String("result".to_string()), + ); + fn_invoke + }), + ); + source + }), + ); + properties + }, + }, + ); + resources + }, + } +} diff --git a/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/example_array.rs b/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/example_array.rs new file mode 100644 index 000000000..a34aba53e --- /dev/null +++ b/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/example_array.rs @@ -0,0 +1,93 @@ +use crate::code_generation::yaml::model::{Example, Expression, Resource}; +use crate::code_generation::yaml::tests::reformat_code; +use crate::code_generation::YamlFile; +use crate::model::ElementId; +use std::collections::BTreeMap; + +//language=YAML +pub const YAML: &str = r#" + resources: + myCert: + type: cloudflare:AccessMutualTlsCertificate + name: my_cert + properties: + associatedHostnames: + - staging.example.com +"#; + +pub fn get_yaml_file() -> YamlFile { + use crate::code_generation::yaml::yaml_model::{YamlExpression, YamlFile, YamlResource}; + + YamlFile { + resources: { + let mut resources = BTreeMap::new(); + resources.insert( + "myCert".to_string(), + YamlResource { + type_: "cloudflare:AccessMutualTlsCertificate".to_string(), + name: Some("my_cert".to_string()), + properties: { + let mut properties = BTreeMap::new(); + properties.insert( + "associatedHostnames".to_string(), + YamlExpression::Array(vec![YamlExpression::String( + "staging.example.com".to_string(), + )]), + ); + properties + }, + }, + ); + resources + }, + } +} + +pub fn get_model() -> Example { + Example { + resources: { + let mut map = BTreeMap::new(); + map.insert( + "myCert".to_string(), + Resource { + type_: ElementId::new( + "cloudflare:index/accessMutualTlsCertificate:AccessMutualTlsCertificate", + ) + .unwrap(), + // type_: "cloudflare:AccessMutualTlsCertificate".to_string(), + name: Some("my_cert".to_string()), + properties: { + let mut props = BTreeMap::new(); + props.insert( + "associatedHostnames".to_string(), + Expression::Array(vec![Expression::String( + "staging.example.com".to_string(), + )]), + ); + props + }, + }, + ); + map + }, + } +} + +// language=Rust +pub fn get_rust_code() -> String { + reformat_code( + r#" + use pulumi_wasm_rust::Output; + use pulumi_wasm_rust::{add_export, pulumi_main}; + #[pulumi_main] + fn test_main() -> Result<(), Error> { + let myCert = access_mutual_tls_certificate::create( + "myCert", + AccessMutualTlsCertificateArgs::builder() + .associated_hostnames(vec!["staging.example.com",]) + .build_struct(), + ); + } + "#, + ) +} diff --git a/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/example_empty_properties.rs b/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/example_empty_properties.rs new file mode 100644 index 000000000..dc8f63868 --- /dev/null +++ b/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/example_empty_properties.rs @@ -0,0 +1,71 @@ +use crate::code_generation::yaml::model::{Example, Resource}; +use crate::code_generation::yaml::tests::reformat_code; +use crate::code_generation::YamlFile; +use crate::model::ElementId; +use std::collections::BTreeMap; + +//language=YAML +pub const YAML: &str = r#" + resources: + myCert: + type: cloudflare:AccessMutualTlsCertificate + name: my_cert +"#; + +pub fn get_yaml_file() -> YamlFile { + use crate::code_generation::yaml::yaml_model::{YamlFile, YamlResource}; + + YamlFile { + resources: { + let mut resources = BTreeMap::new(); + resources.insert( + "myCert".to_string(), + YamlResource { + type_: "cloudflare:AccessMutualTlsCertificate".to_string(), + name: Some("my_cert".to_string()), + properties: BTreeMap::new(), + }, + ); + resources + }, + } +} + +pub fn get_model() -> Example { + Example { + resources: { + let mut map = BTreeMap::new(); + map.insert( + "myCert".to_string(), + Resource { + type_: ElementId::new( + "cloudflare:index/accessMutualTlsCertificate:AccessMutualTlsCertificate", + ) + .unwrap(), + // type_: "cloudflare:AccessMutualTlsCertificate".to_string(), + name: Some("my_cert".to_string()), + properties: BTreeMap::new(), + }, + ); + map + }, + } +} + +// language=Rust +pub fn get_rust_code() -> String { + reformat_code( + r#" + use pulumi_wasm_rust::Output; + use pulumi_wasm_rust::{add_export, pulumi_main}; + #[pulumi_main] + fn test_main() -> Result<(), Error> { + let myCert = access_mutual_tls_certificate::create( + "myCert", + AccessMutualTlsCertificateArgs::builder() + .build_struct(), + ); + } + "#, + ) +} diff --git a/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/example_escape_string.rs b/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/example_escape_string.rs new file mode 100644 index 000000000..558591b46 --- /dev/null +++ b/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/example_escape_string.rs @@ -0,0 +1,86 @@ +use crate::code_generation::yaml::model::Expression; +use crate::code_generation::yaml::model::{Example, Resource}; +use crate::code_generation::yaml::tests::reformat_code; +use crate::code_generation::YamlFile; +use crate::model::ElementId; +use std::collections::BTreeMap; + +//language=YAML +pub(crate) const YAML: &str = r#" + resources: + example: + type: cloudflare:AccessOrganization + properties: + name: my "name" +"#; + +pub(crate) fn get_yaml_file() -> YamlFile { + use crate::code_generation::yaml::yaml_model::{YamlExpression, YamlFile, YamlResource}; + + YamlFile { + resources: { + let mut resources = BTreeMap::new(); + resources.insert( + "example".to_string(), + YamlResource { + type_: "cloudflare:AccessOrganization".to_string(), + name: None, + properties: { + let mut properties = BTreeMap::new(); + properties.insert( + "name".to_string(), + YamlExpression::String("my \"name\"".to_string()), + ); + properties + }, + }, + ); + resources + }, + } +} + +pub fn get_model() -> Example { + Example { + resources: { + let mut map = BTreeMap::new(); + map.insert( + "example".to_string(), + Resource { + type_: ElementId::new("cloudflare:index/accessOrganization:AccessOrganization") + .unwrap(), + // type_: "cloudflare:AccessMutualTlsCertificate".to_string(), + name: None, + properties: { + let mut props = BTreeMap::new(); + props.insert( + "name".to_string(), + Expression::String("my \"name\"".to_string()), + ); + props + }, + }, + ); + map + }, + } +} + +// language=Rust +pub fn get_rust_code() -> String { + reformat_code( + r#" + use pulumi_wasm_rust::Output; + use pulumi_wasm_rust::{add_export, pulumi_main}; + #[pulumi_main] + fn test_main() -> Result<(), Error> { + let example = access_organization::create( + "example", + AccessOrganizationArgs::builder() + .name("my \"name\"") + .build_struct(), + ); + } + "#, + ) +} diff --git a/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/example_numbers.rs b/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/example_numbers.rs new file mode 100644 index 000000000..868b37f42 --- /dev/null +++ b/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/example_numbers.rs @@ -0,0 +1,81 @@ +use crate::code_generation::yaml::model::Expression; +use crate::code_generation::yaml::model::{Example, Resource}; +use crate::code_generation::yaml::tests::reformat_code; +use crate::code_generation::yaml::yaml_model::YamlExpression; +use crate::code_generation::YamlFile; +use crate::model::ElementId; +use std::collections::BTreeMap; + +//language=YAML +pub const YAML: &str = r#" + resources: + example: + type: cloudflare:KeylessCertificate + properties: + port: 24008 +"#; + +pub fn get_yaml_file() -> YamlFile { + use crate::code_generation::yaml::yaml_model::{YamlFile, YamlResource}; + + YamlFile { + resources: { + let mut resources = BTreeMap::new(); + resources.insert( + "example".to_string(), + YamlResource { + type_: "cloudflare:KeylessCertificate".to_string(), + name: None, + properties: { + let mut properties = BTreeMap::new(); + properties.insert("port".to_string(), YamlExpression::Number(24008f64)); + properties + }, + }, + ); + resources + }, + } +} + +pub fn get_model() -> Example { + Example { + resources: { + let mut map = BTreeMap::new(); + map.insert( + "example".to_string(), + Resource { + type_: ElementId::new("cloudflare:index/keylessCertificate:KeylessCertificate") + .unwrap(), + // type_: "cloudflare:AccessMutualTlsCertificate".to_string(), + name: None, + properties: { + let mut props = BTreeMap::new(); + props.insert("port".to_string(), Expression::Integer(24008)); + props + }, + }, + ); + map + }, + } +} + +// language=Rust +pub fn get_rust_code() -> String { + reformat_code( + r#" + use pulumi_wasm_rust::Output; + use pulumi_wasm_rust::{add_export, pulumi_main}; + #[pulumi_main] + fn test_main() -> Result<(), Error> { + let example = keyless_certificate::create( + "example", + KeylessCertificateArgs::builder() + .port(24008) + .build_struct(), + ); + } + "#, + ) +} diff --git a/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/example_variable.rs b/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/example_variable.rs new file mode 100644 index 000000000..9e83b1326 --- /dev/null +++ b/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/example_variable.rs @@ -0,0 +1,87 @@ +use crate::code_generation::yaml::model::{Example, Expression, Resource}; +use crate::code_generation::yaml::tests::reformat_code; +use crate::code_generation::YamlFile; +use crate::model::ElementId; +use std::collections::BTreeMap; + +//language=YAML +pub const YAML: &str = r#" + resources: + myCert: + type: cloudflare:AccessMutualTlsCertificate + name: my_cert + properties: + certificate: ${caPem} +"#; + +pub fn get_yaml_file() -> YamlFile { + use crate::code_generation::yaml::yaml_model::{YamlExpression, YamlFile, YamlResource}; + + YamlFile { + resources: { + let mut resources = BTreeMap::new(); + resources.insert( + "myCert".to_string(), + YamlResource { + type_: "cloudflare:AccessMutualTlsCertificate".to_string(), + name: Some("my_cert".to_string()), + properties: { + let mut properties = BTreeMap::new(); + properties.insert( + "certificate".to_string(), + YamlExpression::String("${caPem}".to_string()), + ); + properties + }, + }, + ); + resources + }, + } +} + +pub fn get_model() -> Example { + Example { + resources: { + let mut map = BTreeMap::new(); + map.insert( + "myCert".to_string(), + Resource { + type_: ElementId::new( + "cloudflare:index/accessMutualTlsCertificate:AccessMutualTlsCertificate", + ) + .unwrap(), + name: Some("my_cert".to_string()), + properties: { + let mut props = BTreeMap::new(); + props.insert( + "certificate".to_string(), + Expression::String("${caPem}".to_string()), + ); + props + }, + }, + ); + map + }, + } +} + +// language=Rust +pub fn get_rust_code() -> String { + reformat_code( + r#" + use pulumi_wasm_rust::Output; + use pulumi_wasm_rust::{add_export, pulumi_main}; + #[pulumi_main] + fn test_main() -> Result<(), Error> { + let myCert = access_mutual_tls_certificate::create( + "myCert", + AccessMutualTlsCertificateArgs::builder() + .certificate("${caPem}") + .build_struct(), + ); + } + "#, + ) +} diff --git a/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/mod.rs b/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/mod.rs new file mode 100644 index 000000000..d155a0ce3 --- /dev/null +++ b/pulumi_wasm_generator_lib/src/code_generation/yaml/tests/mod.rs @@ -0,0 +1,11 @@ +pub(crate) mod complex_yaml; +pub(crate) mod example_array; +pub(crate) mod example_empty_properties; +pub(crate) mod example_escape_string; +pub(crate) mod example_numbers; +pub(crate) mod example_variable; + +fn reformat_code(code: &str) -> String { + let syntax_tree = syn::parse_file(code).unwrap(); + prettyplease::unparse(&syntax_tree) +} diff --git a/pulumi_wasm_generator_lib/src/code_generation/yaml/yaml_model.rs b/pulumi_wasm_generator_lib/src/code_generation/yaml/yaml_model.rs new file mode 100644 index 000000000..38f7ae46f --- /dev/null +++ b/pulumi_wasm_generator_lib/src/code_generation/yaml/yaml_model.rs @@ -0,0 +1,32 @@ +use serde::{Deserialize, Serialize}; +use std::collections::BTreeMap; + +#[derive(Debug, Serialize, Deserialize, PartialEq)] +pub(crate) struct YamlFile { + pub(crate) resources: BTreeMap, +} + +#[derive(Debug, Serialize, Deserialize, PartialEq)] +pub(crate) struct YamlResource { + #[serde(rename = "type")] + pub(crate) type_: String, + pub(crate) name: Option, + #[serde(default)] + pub(crate) properties: BTreeMap, +} + +#[derive(Debug, Serialize, Deserialize, PartialEq)] +#[serde(untagged)] +pub(crate) enum YamlExpression { + String(String), + Number(f64), + Boolean(bool), + Object(BTreeMap), + Array(Vec), +} + +impl YamlFile { + pub fn from_yaml(yaml: &str) -> Result { + serde_yaml::from_str(yaml) + } +} diff --git a/pulumi_wasm_generator_lib/src/lib.rs b/pulumi_wasm_generator_lib/src/lib.rs index f6a65d4cc..e0574e20a 100644 --- a/pulumi_wasm_generator_lib/src/lib.rs +++ b/pulumi_wasm_generator_lib/src/lib.rs @@ -5,13 +5,11 @@ use std::path::Path; use crate::schema::Package; use anyhow::{Context, Result}; - -pub(crate) mod code_generation; +mod code_generation; mod model; mod output; mod schema; mod utils; -pub(crate) mod yaml; pub fn generate_rust_library(schema_json: &Path, result_path: &Path) -> Result<()> { let schema_package: schema::Package = extract_schema_from_file(schema_json)?; diff --git a/pulumi_wasm_generator_lib/src/yaml/mod.rs b/pulumi_wasm_generator_lib/src/yaml/mod.rs deleted file mode 100644 index 7027c874f..000000000 --- a/pulumi_wasm_generator_lib/src/yaml/mod.rs +++ /dev/null @@ -1,796 +0,0 @@ -pub(crate) mod model; -pub(crate) mod yaml_model; - -#[cfg(test)] -pub(crate) mod tests { - use crate::yaml::yaml_model::YamlFile; - use std::collections::BTreeMap; - pub(crate) mod example_access_organization { - - use super::*; - - pub(crate) const YAML: &str = r#" -resources: - example: - type: cloudflare:AccessOrganization - properties: - accountId: f037e56e89293a057740de681ac9abbe - name: example.cloudflareaccess.com - authDomain: example.cloudflareaccess.com - isUiReadOnly: false - userSeatExpirationInactiveTime: 720h - autoRedirectToIdentity: false - loginDesigns: - - backgroundColor: '#ffffff' - textColor: '#000000' - logoPath: https://example.com/logo.png - headerText: My header text - footerText: My footer text - "#; - - pub(crate) fn get_yaml_file() -> YamlFile { - use crate::yaml::yaml_model::{YamlExpression, YamlFile, YamlResource}; - - YamlFile { - resources: { - let mut resources = BTreeMap::new(); - resources.insert( - "example".to_string(), - YamlResource { - type_: "cloudflare:AccessOrganization".to_string(), - name: None, - properties: { - let mut properties = BTreeMap::new(); - properties.insert( - "accountId".to_string(), - YamlExpression::String( - "f037e56e89293a057740de681ac9abbe".to_string(), - ), - ); - properties.insert( - "name".to_string(), - YamlExpression::String( - "example.cloudflareaccess.com".to_string(), - ), - ); - properties.insert( - "authDomain".to_string(), - YamlExpression::String( - "example.cloudflareaccess.com".to_string(), - ), - ); - properties.insert( - "isUiReadOnly".to_string(), - YamlExpression::Boolean(false), - ); - properties.insert( - "userSeatExpirationInactiveTime".to_string(), - YamlExpression::String("720h".to_string()), - ); - properties.insert( - "autoRedirectToIdentity".to_string(), - YamlExpression::Boolean(false), - ); - properties.insert( - "loginDesigns".to_string(), - YamlExpression::Array(vec![YamlExpression::Object({ - let mut design = BTreeMap::new(); - design.insert( - "backgroundColor".to_string(), - YamlExpression::String("#ffffff".to_string()), - ); - design.insert( - "textColor".to_string(), - YamlExpression::String("#000000".to_string()), - ); - design.insert( - "logoPath".to_string(), - YamlExpression::String( - "https://example.com/logo.png".to_string(), - ), - ); - design.insert( - "headerText".to_string(), - YamlExpression::String("My header text".to_string()), - ); - design.insert( - "footerText".to_string(), - YamlExpression::String("My footer text".to_string()), - ); - design - })]), - ); - properties - }, - }, - ); - resources - }, - } - } - } - - pub(crate) mod complex_yaml { - - use super::*; - - pub const YAML: &str = r#" -resources: - petstoreSchema: - type: cloudflare:ApiShieldSchema - name: petstore_schema - properties: - zoneId: 0da42c8d2132a9ddaf714f9e7c920711 - name: myschema - kind: openapi_v3 - validationEnabled: true - source: - fn::invoke: - Function: std:file - Arguments: - input: ./schemas/petstore.json - Return: result -"#; - - pub fn get_yaml_file() -> YamlFile { - use crate::yaml::yaml_model::{YamlExpression, YamlFile, YamlResource}; - use std::collections::BTreeMap; - - YamlFile { - resources: { - let mut resources = BTreeMap::new(); - resources.insert( - "petstoreSchema".to_string(), - YamlResource { - type_: "cloudflare:ApiShieldSchema".to_string(), - name: Some("petstore_schema".to_string()), - properties: { - let mut properties = BTreeMap::new(); - properties.insert( - "zoneId".to_string(), - YamlExpression::String( - "0da42c8d2132a9ddaf714f9e7c920711".to_string(), - ), - ); - properties.insert( - "name".to_string(), - YamlExpression::String("myschema".to_string()), - ); - properties.insert( - "kind".to_string(), - YamlExpression::String("openapi_v3".to_string()), - ); - properties.insert( - "validationEnabled".to_string(), - YamlExpression::Boolean(true), - ); - properties.insert( - "source".to_string(), - YamlExpression::Object({ - let mut source = BTreeMap::new(); - source.insert( - "fn::invoke".to_string(), - YamlExpression::Object({ - let mut fn_invoke = BTreeMap::new(); - fn_invoke.insert( - "Function".to_string(), - YamlExpression::String("std:file".to_string()), - ); - fn_invoke.insert( - "Arguments".to_string(), - YamlExpression::Object({ - let mut arguments = BTreeMap::new(); - arguments.insert( - "input".to_string(), - YamlExpression::String( - "./schemas/petstore.json" - .to_string(), - ), - ); - arguments - }), - ); - fn_invoke.insert( - "Return".to_string(), - YamlExpression::String("result".to_string()), - ); - fn_invoke - }), - ); - source - }), - ); - properties - }, - }, - ); - resources - }, - } - } - } - - pub(crate) mod access_rule { - use crate::model::ElementId; - use crate::yaml::model::{Example, Expression}; - use crate::yaml::tests::reformat_code; - use std::collections::BTreeMap; - - pub const YAML: &str = r#" -resources: - # Challenge requests coming from known Tor exit nodes. - torExitNodes: - type: cloudflare:AccessRule - name: tor_exit_nodes - properties: - zoneId: 0da42c8d2132a9ddaf714f9e7c920711 - notes: Requests coming from known Tor exit nodes - mode: challenge - configuration: - target: country - value: T1 -"#; - - pub fn get_yaml_file() -> super::YamlFile { - use crate::yaml::yaml_model::{YamlExpression, YamlFile, YamlResource}; - - YamlFile { - resources: { - let mut resources = BTreeMap::new(); - resources.insert( - "torExitNodes".to_string(), - YamlResource { - type_: "cloudflare:AccessRule".to_string(), - name: Some("tor_exit_nodes".to_string()), - properties: { - let mut properties = BTreeMap::new(); - properties.insert( - "zoneId".to_string(), - YamlExpression::String( - "0da42c8d2132a9ddaf714f9e7c920711".to_string(), - ), - ); - properties.insert( - "notes".to_string(), - YamlExpression::String( - "Requests coming from known Tor exit nodes".to_string(), - ), - ); - properties.insert( - "mode".to_string(), - YamlExpression::String("challenge".to_string()), - ); - properties.insert( - "configuration".to_string(), - YamlExpression::Object({ - let mut configuration = BTreeMap::new(); - configuration.insert( - "target".to_string(), - YamlExpression::String("country".to_string()), - ); - configuration.insert( - "value".to_string(), - YamlExpression::String("T1".to_string()), - ); - configuration - }), - ); - properties - }, - }, - ); - resources - }, - } - } - - pub fn get_model() -> Example { - Example { - resources: { - let mut map = BTreeMap::new(); - map.insert( - "torExitNodes".to_string(), - crate::yaml::model::Resource { - type_: ElementId::new("cloudflare:index/accessRule:AccessRule") - .unwrap(), - name: Some("tor_exit_nodes".to_string()), - properties: { - let mut props = BTreeMap::new(); - props.insert( - "zoneId".to_string(), - Expression::String( - "0da42c8d2132a9ddaf714f9e7c920711".to_string(), - ), - ); - props.insert( - "notes".to_string(), - Expression::String( - "Requests coming from known Tor exit nodes".to_string(), - ), - ); - props.insert( - "mode".to_string(), - Expression::String("challenge".to_string()), - ); - props.insert( - "configuration" - .to_string(), - Expression::Object( - ElementId::new("cloudflare:index/AccessRuleConfiguration:AccessRuleConfiguration").unwrap(), // You might need to adjust this ElementId - { - let mut config = BTreeMap::new(); - config.insert( - "target".to_string(), - Expression::String("country".to_string()), - ); - config.insert( - "value".to_string(), - Expression::String("T1".to_string()), - ); - config - }, - ), - ); - props - }, - }, - ); - map - }, - } - } - - pub fn get_rust_code() -> String { - reformat_code( - r#" - use pulumi_wasm_rust::Output; - use pulumi_wasm_rust::{add_export, pulumi_main}; - #[pulumi_main] - fn test_main() -> Result<(), Error> { - let torExitNodes = access_rule::create( - "torExitNodes", - AccessRuleArgs::builder() - .configuration( - AccessRuleConfiguration::builder() - .target("country") - .value("T1") - .build_struct(), - ) - .mode("challenge") - .notes("Requests coming from known Tor exit nodes") - .zone_id("0da42c8d2132a9ddaf714f9e7c920711") - .build_struct(), - ); - } - "#, - ) - } - } - - pub(crate) mod example_array { - use super::*; - use crate::model::ElementId; - use crate::yaml::model::{Example, Expression, Resource}; - - pub const YAML: &str = r#" -resources: - myCert: - type: cloudflare:AccessMutualTlsCertificate - name: my_cert - properties: - zoneId: 0da42c8d2132a9ddaf714f9e7c920711 - name: My Root Cert - certificate: ${caPem} - associatedHostnames: - - staging.example.com -"#; - - pub fn get_yaml_file() -> super::YamlFile { - use crate::yaml::yaml_model::{YamlExpression, YamlFile, YamlResource}; - - YamlFile { - resources: { - let mut resources = BTreeMap::new(); - resources.insert( - "myCert".to_string(), - YamlResource { - type_: "cloudflare:AccessMutualTlsCertificate".to_string(), - name: Some("my_cert".to_string()), - properties: { - let mut properties = BTreeMap::new(); - properties.insert( - "zoneId".to_string(), - YamlExpression::String( - "0da42c8d2132a9ddaf714f9e7c920711".to_string(), - ), - ); - properties.insert( - "name".to_string(), - YamlExpression::String("My Root Cert".to_string()), - ); - properties.insert( - "certificate".to_string(), - YamlExpression::String("${caPem}".to_string()), - ); - properties.insert( - "associatedHostnames".to_string(), - YamlExpression::Array(vec![YamlExpression::String( - "staging.example.com".to_string(), - )]), - ); - properties - }, - }, - ); - resources - }, - } - } - - pub fn get_model() -> Example { - Example { - resources: { - let mut map = BTreeMap::new(); - map.insert( - "myCert".to_string(), - Resource { - type_: ElementId::new("cloudflare:index/accessMutualTlsCertificate:AccessMutualTlsCertificate").unwrap(), - // type_: "cloudflare:AccessMutualTlsCertificate".to_string(), - name: Some("my_cert".to_string()), - properties: { - let mut props = BTreeMap::new(); - props.insert( - "zoneId".to_string(), - Expression::String( - "0da42c8d2132a9ddaf714f9e7c920711".to_string(), - ), - ); - props.insert( - "name".to_string(), - Expression::String("My Root Cert".to_string()), - ); - props.insert( - "certificate".to_string(), - Expression::String("${caPem}".to_string()), - ); - props.insert( - "associatedHostnames".to_string(), - Expression::Array(vec![Expression::String( - "staging.example.com".to_string(), - )]), - ); - props - }, - }, - ); - map - }, - } - } - - pub fn get_rust_code() -> String { - reformat_code( - r#" - use pulumi_wasm_rust::Output; - use pulumi_wasm_rust::{add_export, pulumi_main}; - #[pulumi_main] - fn test_main() -> Result<(), Error> { - let myCert = access_mutual_tls_certificate::create( - "myCert", - AccessMutualTlsCertificateArgs::builder() - .associated_hostnames(vec!["staging.example.com",]) - .certificate("${caPem}") - .name("My Root Cert") - .zone_id("0da42c8d2132a9ddaf714f9e7c920711") - .build_struct(), - ); - } - "#, - ) - } - } - - pub(crate) mod example_variable { - use super::*; - - pub const YAML: &str = r#" -resources: - myCert: - type: cloudflare:AccessMutualTlsCertificate - name: my_cert - properties: - zoneId: 0da42c8d2132a9ddaf714f9e7c920711 - name: My Root Cert - certificate: ${caPem} - associatedHostnames: - - staging.example.com - "#; - - pub fn get_yaml_file() -> super::YamlFile { - use crate::yaml::yaml_model::{YamlExpression, YamlFile, YamlResource}; - - YamlFile { - resources: { - let mut resources = BTreeMap::new(); - resources.insert( - "myCert".to_string(), - YamlResource { - type_: "cloudflare:AccessMutualTlsCertificate".to_string(), - name: Some("my_cert".to_string()), - properties: { - let mut properties = BTreeMap::new(); - properties.insert( - "zoneId".to_string(), - YamlExpression::String( - "0da42c8d2132a9ddaf714f9e7c920711".to_string(), - ), - ); - properties.insert( - "name".to_string(), - YamlExpression::String("My Root Cert".to_string()), - ); - properties.insert( - "certificate".to_string(), - YamlExpression::String("${caPem}".to_string()), - ); - properties.insert( - "associatedHostnames".to_string(), - YamlExpression::Array(vec![YamlExpression::String( - "staging.example.com".to_string(), - )]), - ); - properties - }, - }, - ); - resources - }, - } - } - } - - pub(crate) mod example_empty_properties { - use super::*; - use crate::model::ElementId; - use crate::yaml::model::{Example, Resource}; - - pub const YAML: &str = r#" -resources: - myCert: - type: cloudflare:AccessMutualTlsCertificate - name: my_cert -"#; - - pub fn get_yaml_file() -> super::YamlFile { - use crate::yaml::yaml_model::{YamlFile, YamlResource}; - - YamlFile { - resources: { - let mut resources = BTreeMap::new(); - resources.insert( - "myCert".to_string(), - YamlResource { - type_: "cloudflare:AccessMutualTlsCertificate".to_string(), - name: Some("my_cert".to_string()), - properties: BTreeMap::new(), - }, - ); - resources - }, - } - } - - pub fn get_model() -> Example { - Example { - resources: { - let mut map = BTreeMap::new(); - map.insert( - "myCert".to_string(), - Resource { - type_: ElementId::new("cloudflare:index/accessMutualTlsCertificate:AccessMutualTlsCertificate").unwrap(), - // type_: "cloudflare:AccessMutualTlsCertificate".to_string(), - name: Some("my_cert".to_string()), - properties: BTreeMap::new() - }, - ); - map - }, - } - } - - pub fn get_rust_code() -> String { - reformat_code( - r#" - use pulumi_wasm_rust::Output; - use pulumi_wasm_rust::{add_export, pulumi_main}; - #[pulumi_main] - fn test_main() -> Result<(), Error> { - let myCert = access_mutual_tls_certificate::create( - "myCert", - AccessMutualTlsCertificateArgs::builder() - .build_struct(), - ); - } - "#, - ) - } - } - - pub(crate) mod example_numbers { - use super::*; - use crate::model::ElementId; - use crate::yaml::model::{Example, Expression, Resource}; - use crate::yaml::yaml_model::YamlExpression; - - pub const YAML: &str = r#" - resources: - example: - type: cloudflare:KeylessCertificate - properties: - port: 24008 -"#; - - pub fn get_yaml_file() -> super::YamlFile { - use crate::yaml::yaml_model::{YamlFile, YamlResource}; - - YamlFile { - resources: { - let mut resources = BTreeMap::new(); - resources.insert( - "example".to_string(), - YamlResource { - type_: "cloudflare:KeylessCertificate".to_string(), - name: None, - properties: { - let mut properties = BTreeMap::new(); - properties - .insert("port".to_string(), YamlExpression::Number(24008f64)); - properties - }, - }, - ); - resources - }, - } - } - - pub fn get_model() -> Example { - Example { - resources: { - let mut map = BTreeMap::new(); - map.insert( - "example".to_string(), - Resource { - type_: ElementId::new( - "cloudflare:index/keylessCertificate:KeylessCertificate", - ) - .unwrap(), - // type_: "cloudflare:AccessMutualTlsCertificate".to_string(), - name: None, - properties: { - let mut props = BTreeMap::new(); - props.insert("port".to_string(), Expression::Integer(24008)); - props - }, - }, - ); - map - }, - } - } - - pub fn get_rust_code() -> String { - reformat_code( - r#" - use pulumi_wasm_rust::Output; - use pulumi_wasm_rust::{add_export, pulumi_main}; - #[pulumi_main] - fn test_main() -> Result<(), Error> { - let example = keyless_certificate::create( - "example", - KeylessCertificateArgs::builder() - .port(24008) - .build_struct(), - ); - } - "#, - ) - } - } - - pub(crate) mod example_escape_string { - use super::*; - use crate::model::ElementId; - use crate::yaml::model::{Example, Expression, Resource}; - use crate::yaml::yaml_model::YamlExpression; - - use super::*; - - pub(crate) const YAML: &str = r#" -resources: - example: - type: cloudflare:AccessOrganization - properties: - name: my "name" - "#; - - pub(crate) fn get_yaml_file() -> YamlFile { - use crate::yaml::yaml_model::{YamlExpression, YamlFile, YamlResource}; - - YamlFile { - resources: { - let mut resources = BTreeMap::new(); - resources.insert( - "example".to_string(), - YamlResource { - type_: "cloudflare:AccessOrganization".to_string(), - name: None, - properties: { - let mut properties = BTreeMap::new(); - properties.insert( - "name".to_string(), - YamlExpression::String("my \"name\"".to_string()), - ); - properties - }, - }, - ); - resources - }, - } - } - - pub fn get_model() -> Example { - use crate::yaml::yaml_model::{YamlExpression, YamlFile, YamlResource}; - - Example { - resources: { - let mut map = BTreeMap::new(); - map.insert( - "example".to_string(), - Resource { - type_: ElementId::new( - "cloudflare:index/accessOrganization:AccessOrganization", - ) - .unwrap(), - // type_: "cloudflare:AccessMutualTlsCertificate".to_string(), - name: None, - properties: { - let mut props = BTreeMap::new(); - props.insert( - "name".to_string(), - Expression::String("my \"name\"".to_string()), - ); - props - }, - }, - ); - map - }, - } - } - - pub fn get_rust_code() -> String { - reformat_code( - r#" - use pulumi_wasm_rust::Output; - use pulumi_wasm_rust::{add_export, pulumi_main}; - #[pulumi_main] - fn test_main() -> Result<(), Error> { - let example = access_organization::create( - "example", - AccessOrganizationArgs::builder() - .name("my \"name\"") - .build_struct(), - ); - } - "#, - ) - } - } - - fn reformat_code(code: &str) -> String { - let syntax_tree = syn::parse_file(code).unwrap(); - prettyplease::unparse(&syntax_tree) - } -} diff --git a/pulumi_wasm_generator_lib/src/yaml/yaml_model.rs b/pulumi_wasm_generator_lib/src/yaml/yaml_model.rs deleted file mode 100644 index 8d2f0b5b5..000000000 --- a/pulumi_wasm_generator_lib/src/yaml/yaml_model.rs +++ /dev/null @@ -1,101 +0,0 @@ -use serde::{Deserialize, Serialize}; -use std::collections::BTreeMap; - -#[derive(Debug, Serialize, Deserialize, PartialEq)] -pub(crate) struct YamlFile { - pub(crate) resources: BTreeMap, -} - -#[derive(Debug, Serialize, Deserialize, PartialEq)] -pub(crate) struct YamlResource { - #[serde(rename = "type")] - pub(crate) type_: String, - pub(crate) name: Option, - #[serde(default)] - pub(crate) properties: BTreeMap, -} - -#[derive(Debug, Serialize, Deserialize, PartialEq)] -#[serde(untagged)] -pub(crate) enum YamlExpression { - String(String), - Number(f64), - Boolean(bool), - Object(BTreeMap), - Array(Vec), -} - -impl YamlFile { - pub fn from_yaml(yaml: &str) -> Result { - serde_yaml::from_str(yaml) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_array_yaml_deserialization() { - use super::super::tests::example_array::*; - let yaml_file = YamlFile::from_yaml(YAML).unwrap(); - let expected_yaml_file = get_yaml_file(); - assert_eq!(yaml_file, expected_yaml_file); - } - - #[test] - fn test_complex_yaml_deserialization() { - use super::super::tests::complex_yaml::*; - let yaml_file = YamlFile::from_yaml(YAML).unwrap(); - let expected_yaml_file = get_yaml_file(); - assert_eq!(yaml_file, expected_yaml_file); - } - - #[test] - fn test_access_rule_yaml_deserialization() { - use super::super::tests::access_rule::*; - let yaml_file = YamlFile::from_yaml(YAML).unwrap(); - let expected_yaml_file = get_yaml_file(); - assert_eq!(yaml_file, expected_yaml_file); - } - - #[test] - fn test_access_organization_yaml_deserialization() { - use super::super::tests::example_access_organization::*; - let yaml_file = YamlFile::from_yaml(YAML).unwrap(); - let expected_yaml_file = get_yaml_file(); - assert_eq!(yaml_file, expected_yaml_file); - } - - #[test] - fn test_example_variable() { - use super::super::tests::example_variable::*; - let yaml_file = YamlFile::from_yaml(YAML).unwrap(); - let expected_yaml_file = get_yaml_file(); - assert_eq!(yaml_file, expected_yaml_file); - } - - #[test] - fn test_without_parameters() { - use super::super::tests::example_empty_properties::*; - let yaml_file = YamlFile::from_yaml(YAML).unwrap(); - let expected_yaml_file = get_yaml_file(); - assert_eq!(yaml_file, expected_yaml_file); - } - - #[test] - fn test_without_numbers() { - use super::super::tests::example_numbers::*; - let yaml_file = YamlFile::from_yaml(YAML).unwrap(); - let expected_yaml_file = get_yaml_file(); - assert_eq!(yaml_file, expected_yaml_file); - } - - #[test] - fn test_string_escape() { - use super::super::tests::example_escape_string::*; - let yaml_file = YamlFile::from_yaml(YAML).unwrap(); - let expected_yaml_file = get_yaml_file(); - assert_eq!(yaml_file, expected_yaml_file); - } -}