From b6bb5ef675bef6d48a99899ad743826eb61f3157 Mon Sep 17 00:00:00 2001 From: Laurent Querel Date: Tue, 9 Jul 2024 21:09:17 -0700 Subject: [PATCH] chore(forge): Fix a unit test. --- crates/weaver_forge/src/lib.rs | 8 +-- .../weaver_forge/templates/test/weaver.yaml | 49 ++++++++++++++++++- defaults/weaver_config/weaver.yaml | 22 --------- justfile | 1 + src/registry/generate.rs | 7 +++ 5 files changed, 61 insertions(+), 26 deletions(-) delete mode 100644 defaults/weaver_config/weaver.yaml diff --git a/crates/weaver_forge/src/lib.rs b/crates/weaver_forge/src/lib.rs index 8d5df699..c0b53432 100644 --- a/crates/weaver_forge/src/lib.rs +++ b/crates/weaver_forge/src/lib.rs @@ -677,7 +677,7 @@ mod tests { } #[test] - fn test() { + fn test_template_engine() { let logger = TestLogger::default(); let loader = FileSystemFileLoader::try_new("templates/test".into()) .expect("Failed to create file system loader"); @@ -687,11 +687,13 @@ mod tests { // Add a template configuration for converter.md on top // of the default template configuration. This is useful // for test coverage purposes. - engine.target_config.templates = Some(vec![TemplateConfig { + let mut templates = engine.target_config.templates.unwrap_or_default(); + templates.push(TemplateConfig { pattern: Glob::new("converter.md").unwrap(), filter: ".".to_owned(), application_mode: ApplicationMode::Single, - }]); + }); + engine.target_config.templates = Some(templates); let registry_id = "default"; let mut registry = SemConvRegistry::try_from_path_pattern(registry_id, "data/*.yaml") diff --git a/crates/weaver_forge/templates/test/weaver.yaml b/crates/weaver_forge/templates/test/weaver.yaml index 3a7ad593..e100857c 100644 --- a/crates/weaver_forge/templates/test/weaver.yaml +++ b/crates/weaver_forge/templates/test/weaver.yaml @@ -14,4 +14,51 @@ type_mapping: "boolean[]": "[]bool" "string[]": "[]string" -acronyms: ["iOS", "API", "URL"] \ No newline at end of file +acronyms: ["iOS", "API", "URL"] + +templates: + - pattern: "registry.md" + filter: "." + application_mode: single + - pattern: "**/attribute_group.md" + filter: ".groups[] | select(.type == \"attribute_group\")" + application_mode: each + - pattern: "**/attribute_groups.md" + filter: ".groups[] | select(.type == \"attribute_group\")" + application_mode: single + - pattern: "**/event.md" + filter: ".groups[] | select(.type == \"event\")" + application_mode: each + - pattern: "**/events.md" + filter: ".groups[] | select(.type == \"event\")" + application_mode: single + - pattern: "**/group.md" + filter: ".groups" + application_mode: each + - pattern: "**/groups.md" + filter: ".groups" + application_mode: single + - pattern: "**/metric.md" + filter: ".groups[] | select(.type == \"metric\")" + application_mode: each + - pattern: "**/metrics.md" + filter: ".groups[] | select(.type == \"metric\")" + application_mode: single + - pattern: "**/resource.md" + filter: ".groups[] | select(.type == \"resource\")" + application_mode: each + - pattern: "**/resources.md" + filter: ".groups[] | select(.type == \"resource\")" + application_mode: single + - pattern: "**/scope.md" + filter: ".groups[] | select(.type == \"scope\")" + application_mode: each + - pattern: "**/scopes.md" + filter: ".groups[] | select(.type == \"scope\")" + application_mode: single + - pattern: "**/span.md" + filter: ".groups[] | select(.type == \"span\")" + application_mode: each + - pattern: "**/spans.md" + filter: ".groups[] | select(.type == \"span\")" + application_mode: single \ No newline at end of file diff --git a/defaults/weaver_config/weaver.yaml b/defaults/weaver_config/weaver.yaml deleted file mode 100644 index 05fae55e..00000000 --- a/defaults/weaver_config/weaver.yaml +++ /dev/null @@ -1,22 +0,0 @@ -# This file contains the default configuration used by Weaver. -# -# Weaver allows local configuration for a particular target as well as global -# configuration. It looks for configuration files in the target directory, the -# parent directory (i.e., the directory containing all the targets), the -# `$HOME/.weaver/weaver.yaml` directory, and finally in the -# `defaults/weaver_config` directory (embedded in the Weaver binary). A local -# definition overrides the corresponding definition that may be present in the -# parent directory, which itself may redefine the corresponding entry in the -# home directory (i.e., defined per user), and finally in the Weaver application -# binary (i.e., defined by Weaver authors). With this structure, we can specify -# configuration per target, for all targets, and even reuse a configuration -# defined in the binary of the Weaver application. - -# Default template syntax. -template_syntax: - block_start: "{%" - block_end: "%}" - variable_start: "{{" - variable_end: "}}" - comment_start: "{#" - comment_end: "#}" diff --git a/justfile b/justfile index ffdd6cf6..73ef51ed 100644 --- a/justfile +++ b/justfile @@ -19,6 +19,7 @@ pre-push-check: # [ToDo LQ] Re-enable --all-features once the issue is resolved # cargo clippy --workspace --all-features --all-targets -- -D warnings --allow deprecated cargo clippy --workspace --all-targets -- -D warnings --allow deprecated + rm -rf crates/weaver_forge/observed_output/* cargo test --all # [workaround] removed --all-features due to an issue in one of the dependency in Tantity (zstd-safe) # [ToDo LQ] Re-enable --all-features once the issue is resolved diff --git a/src/registry/generate.rs b/src/registry/generate.rs index 1d4ff563..464c333b 100644 --- a/src/registry/generate.rs +++ b/src/registry/generate.rs @@ -36,6 +36,11 @@ pub struct RegistryGenerateArgs { #[arg(short = 't', long, default_value = "templates")] pub templates: PathBuf, + /// List of `weaver.yaml` configuration files to use. When there is a conflict, the last one + /// will override the previous ones for the keys that are defined in both. + #[arg(short = 'c', long)] + pub config: Option>, + /// Parameters key=value, defined in the command line, to pass to the templates. /// The value must be a valid YAML value. #[arg(short= 'D', long, value_parser = parse_key_val)] @@ -184,6 +189,7 @@ mod tests { command: RegistrySubCommand::Generate(RegistryGenerateArgs { output: temp_output.clone(), templates: PathBuf::from("crates/weaver_codegen_test/templates/registry/rust"), + config: None, param: None, params: None, registry: RegistryArgs { @@ -252,6 +258,7 @@ mod tests { command: RegistrySubCommand::Generate(RegistryGenerateArgs { output: temp_output.clone(), templates: PathBuf::from("crates/weaver_codegen_test/templates/registry/rust"), + config: None, param: None, params: None, registry: RegistryArgs {