Skip to content

Commit

Permalink
Expand tests in semconv crate
Browse files Browse the repository at this point in the history
Update readme to denote the JSON schema for semconv and also expand tests to make sure that while no error messages exist, data is also loaded correctly.
  • Loading branch information
jsuereth committed Feb 11, 2024
1 parent 42f6979 commit af05dd0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/weaver_semconv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ methods to resolve references between different semconv catalogs.
See [semantic convention YAML language](https://github.com/open-telemetry/build-tools/blob/main/semantic-conventions/syntax.md)
for more details on the syntax.

See [build-tools JSON schema](https://github.com/open-telemetry/build-tools/blob/main/semantic-conventions/semconv.schema.json) for
formal definition of the allowed syntax.

18 changes: 18 additions & 0 deletions crates/weaver_semconv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ mod tests {

/// Load multiple semantic convention files in the semantic convention registry.
/// No error should be emitted.
/// Spot check one or two pieces of loaded data.
#[test]
fn test_load_catalog() {
let yaml_files = vec![
Expand Down Expand Up @@ -813,6 +814,23 @@ mod tests {
let result = catalog.load_from_file(yaml);
assert!(result.is_ok(), "{:#?}", result.err().unwrap());
}

// Now let's resolve attributes and check provenance and structure is what we expect.
let _ = catalog.resolve(ResolverConfig::with_keep_specs()).unwrap();
assert_eq!(catalog.attribute_with_provenance("server.address").unwrap().provenance, "data/server.yaml");
let server_address = catalog.attribute("server.address").unwrap();
assert_eq!(server_address.brief(), "Server address - domain name if available without reverse DNS lookup, otherwise IP address or Unix domain socket name.");
assert_eq!(server_address.is_required(), false);

Check failure

Code scanning / clippy

used assert_eq! with a literal bool Error

used assert\_eq! with a literal bool
assert_eq!(server_address.tag(), None);
if let AttributeSpec::Id {
r#type, ..
} = server_address {
assert_eq!(format!("{}", r#type), "string");
} else {
panic!("Expected real AttributeSpec, not reference");
}
// Assert that we read things correctly and keep provenance.
assert_eq!(catalog.metric_with_provenance("http.client.request.duration").unwrap().provenance, "data/http-metrics.yaml");
}

/// Test the resolver with a semantic convention semantic convention registry that contains
Expand Down

0 comments on commit af05dd0

Please sign in to comment.