Skip to content

Commit

Permalink
fix namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Aug 19, 2024
1 parent e0c9b6f commit a0c5dea
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion policies/attribute_name_collisions.rego
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package attribute_name_collisions
package after_resolution

# check that attribute constant names do not collide
deny[attr_registry_collision(description, name)] {
Expand Down
8 changes: 3 additions & 5 deletions policies/attribute_name_collisions_test.rego
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package attribute_name_collisions_test

import data.attribute_name_collisions
package after_resolution
import future.keywords

test_fails_on_const_name_collision if {
Expand All @@ -9,13 +7,13 @@ test_fails_on_const_name_collision if {
{"id": "test2", "attributes": [{"name": "foo.bar_baz"}]}
]}
# each attribute counts as a collision, so there are 2 collisions
count(attribute_name_collisions.deny) == 2 with input as collision
count(deny) == 2 with input as collision
}

test_fails_on_namespace_collision if {
collision := {"groups": [
{"id": "test1", "attributes": [{"name": "foo.bar.baz"}]},
{"id": "test2", "attributes": [{"name": "foo.bar"}]}
]}
count(attribute_name_collisions.deny) == 1 with input as collision
count(deny) == 1 with input as collision
}
2 changes: 1 addition & 1 deletion policies/yaml_schema.rego
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package yaml_schema
package before_resolution

# checks attribute name format
deny[yaml_schema_violation(description, group.id, name)] {
Expand Down
17 changes: 8 additions & 9 deletions policies/yaml_schema_test.rego
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
package yaml_schema_test
package before_resolution

import data.yaml_schema
import future.keywords

test_fails_on_invalid_attribute_name if {
every name in invalid_names {
count(yaml_schema.deny) == 1 with input as {"groups": create_attribute_group(name)}
count(deny) == 1 with input as {"groups": create_attribute_group(name)}
}
}

test_fails_on_invalid_metric_name if {
every name in invalid_names {
count(yaml_schema.deny) == 1 with input as {"groups": create_metric(name)}
count(deny) == 1 with input as {"groups": create_metric(name)}
}
}

test_fails_on_invalid_event_name if {
every name in invalid_names {
count(yaml_schema.deny) == 1 with input as {"groups": create_event(name)}
count(deny) == 1 with input as {"groups": create_event(name)}
}
}

test_passes_on_valid_names if {
every name in valid_names {
count(yaml_schema.deny) == 0 with input as {"groups": create_attribute_group(name)}
count(yaml_schema.deny) == 0 with input as {"groups": create_metric(name)}
count(yaml_schema.deny) == 0 with input as {"groups": create_event(name)}
count(deny) == 0 with input as {"groups": create_attribute_group(name)}
count(deny) == 0 with input as {"groups": create_metric(name)}
count(deny) == 0 with input as {"groups": create_event(name)}
}
}

test_fails_if_prefix_is_present if {
count(yaml_schema.deny) == 1 with input as {"groups": [{"id": "test", "prefix": "foo"}]}
count(deny) == 1 with input as {"groups": [{"id": "test", "prefix": "foo"}]}
}

create_attribute_group(attr) = json {
Expand Down

0 comments on commit a0c5dea

Please sign in to comment.