Skip to content

Commit

Permalink
Support resources without parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejressel committed Dec 1, 2024
1 parent 8804649 commit 54b1fdc
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 55 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions providers/pulumi_wasm_provider_docker_rust/src/resource/network.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions providers/pulumi_wasm_provider_docker_rust/src/resource/volume.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion pulumi_wasm_generator_lib/src/code_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn generate_expression(expr: Expression) -> String {
#[cfg(test)]
mod tests {
use crate::code_generation::generate_code;
use crate::yaml::tests::{access_rule, example_array};
use crate::yaml::tests::{access_rule, example_array, example_empty_properties};

#[test]
fn test_example_array() {
Expand All @@ -152,4 +152,11 @@ mod tests {
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)
}
}
67 changes: 67 additions & 0 deletions pulumi_wasm_generator_lib/src/yaml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,73 @@ 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(),
);
}
"#,
)
}
}

fn reformat_code(code: &str) -> String {
let syntax_tree = syn::parse_file(code).unwrap();
prettyplease::unparse(&syntax_tree)
Expand Down
44 changes: 24 additions & 20 deletions pulumi_wasm_generator_lib/src/yaml/yaml_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub(crate) struct YamlResource {
#[serde(rename = "type")]
pub(crate) type_: String,
pub(crate) name: Option<String>,
#[serde(default)]
pub(crate) properties: BTreeMap<String, YamlExpression>,
}

Expand All @@ -36,46 +37,49 @@ mod tests {

#[test]
fn test_array_yaml_deserialization() {
use super::super::tests::example_array;
let yaml = example_array::YAML;
let yaml_file = YamlFile::from_yaml(yaml).unwrap();
let expected_yaml_file = example_array::get_yaml_file();
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 = complex_yaml::YAML;
let yaml_file = YamlFile::from_yaml(yaml).unwrap();
let expected_yaml_file = complex_yaml::get_yaml_file();
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 = access_rule::YAML;
let yaml_file = YamlFile::from_yaml(yaml).unwrap();
let expected_yaml_file = access_rule::get_yaml_file();
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 = example_access_organization::YAML;
let yaml_file = YamlFile::from_yaml(yaml).unwrap();
let expected_yaml_file = example_access_organization::get_yaml_file();
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 = example_variable::YAML;
let yaml_file = YamlFile::from_yaml(yaml).unwrap();
let expected_yaml_file = example_variable::get_yaml_file();
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);
}
}

0 comments on commit 54b1fdc

Please sign in to comment.