From 55c9787ef11d08094c4cd9b1ca8170d353ea7c21 Mon Sep 17 00:00:00 2001 From: itowlson Date: Wed, 3 Jan 2024 12:11:43 +1300 Subject: [PATCH] Test that variables and components can be added in the same template Signed-off-by: itowlson --- crates/templates/src/manager.rs | 7 ++++++- .../add-variables/metadata/snippets/component.txt | 6 ++++++ .../templates/add-variables/metadata/spin-template.toml | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 crates/templates/tests/templates/add-variables/metadata/snippets/component.txt diff --git a/crates/templates/src/manager.rs b/crates/templates/src/manager.rs index e12d3efb3..d0768987f 100644 --- a/crates/templates/src/manager.rs +++ b/crates/templates/src/manager.rs @@ -1018,8 +1018,13 @@ mod tests { } let spin_toml = tokio::fs::read_to_string(&spin_toml_path).await.unwrap(); + assert!(spin_toml.contains("[variables]\nsecret")); assert!(spin_toml.contains("url = { default = \"https://service.example.com\" }")); + + assert!(spin_toml.contains("[component.insertvars]")); + assert!(spin_toml.contains("[component.insertvars.variables]")); + assert!(spin_toml.contains("kv_credentials = \"{{ secret }}\"")); } #[tokio::test] @@ -1106,7 +1111,7 @@ mod tests { manifest_path: spin_toml_path.clone(), }, output_path: PathBuf::from(output_dir), - name: "insertvars".to_owned(), + name: "insertvarsagain".to_owned(), values, accept_defaults: false, }; diff --git a/crates/templates/tests/templates/add-variables/metadata/snippets/component.txt b/crates/templates/tests/templates/add-variables/metadata/snippets/component.txt new file mode 100644 index 000000000..f98c450c7 --- /dev/null +++ b/crates/templates/tests/templates/add-variables/metadata/snippets/component.txt @@ -0,0 +1,6 @@ +[component.{{project-name | kebab_case}}] +source = { url = "https://example.com/spin-kv-explorer.wasm", digest = "sha256:12345" } +id = "{{ project-name | kebab_case }}" +key_value_stores = ["default"] +[component.{{project-name | kebab_case}}.variables] +{% raw %}kv_credentials = "{{ secret }}"{% endraw %} diff --git a/crates/templates/tests/templates/add-variables/metadata/spin-template.toml b/crates/templates/tests/templates/add-variables/metadata/spin-template.toml index e5508d987..8be4a1175 100644 --- a/crates/templates/tests/templates/add-variables/metadata/spin-template.toml +++ b/crates/templates/tests/templates/add-variables/metadata/spin-template.toml @@ -8,6 +8,7 @@ supported = false [add_component] [add_component.snippets] +component = "component.txt" variables = "variables.txt" [parameters]