Skip to content

Commit

Permalink
chore(forge): Fix a unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
lquerel committed Jul 10, 2024
1 parent da7b6c7 commit b6bb5ef
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 26 deletions.
8 changes: 5 additions & 3 deletions crates/weaver_forge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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")
Expand Down
49 changes: 48 additions & 1 deletion crates/weaver_forge/templates/test/weaver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,51 @@ type_mapping:
"boolean[]": "[]bool"
"string[]": "[]string"

acronyms: ["iOS", "API", "URL"]
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
22 changes: 0 additions & 22 deletions defaults/weaver_config/weaver.yaml

This file was deleted.

1 change: 1 addition & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/registry/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<PathBuf>>,

/// 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)]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b6bb5ef

Please sign in to comment.