Skip to content

Commit 1f01d66

Browse files
committed
chore: fix opa validator testdata packages according to regal
1 parent 0f3b405 commit 1f01d66

File tree

9 files changed

+22
-22
lines changed

9 files changed

+22
-22
lines changed

admissionctrl/validator/opa_validator_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestOpaValidator(t *testing.T) {
1717
// create a context with a timeout
1818

1919
// create a new OPA object
20-
opaValidator, err := NewOpaValidator("testopavalidator", testutil.Filepath(t, "opa/validators/prefixed_policies.rego"),
20+
opaValidator, err := NewOpaValidator("testopavalidator", testutil.Filepath(t, "opa/validators/prefixed_policies/prefixed_policies.rego"),
2121
"errors = data.prefixed_policies.errors", slog.New(slog.DiscardHandler), nil)
2222

2323
require.NoError(t, err)
@@ -186,7 +186,7 @@ func TestOpaValidatorContext(t *testing.T) {
186186
t.Run(tt.name, func(t *testing.T) {
187187
validator, err := NewOpaValidator(
188188
"test_context_validator",
189-
testutil.Filepath(t, "opa/validators/context.rego"),
189+
testutil.Filepath(t, "opa/validators/context/context.rego"),
190190
tt.query,
191191
slog.New(slog.DiscardHandler),
192192
nil,

config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestLoadConfig(t *testing.T) {
8181
OpaRule: &OpaRule{
8282

8383
Query: "errors = data.costcenter_meta.errors",
84-
Filename: "testdata/opa/validators/costcenter_meta.rego",
84+
Filename: "testdata/opa/validators/costcenter_meta/costcenter_meta.rego",
8585
},
8686
},
8787
{

config/testdata/with_admission.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ validator "opa" "some_opa_validator" {
33

44
opa_rule {
55
query = "errors = data.costcenter_meta.errors"
6-
filename = "testdata/opa/validators/costcenter_meta.rego"
6+
filename = "testdata/opa/validators/costcenter_meta/costcenter_meta.rego"
77
}
88
}
99
validator "notation" "some_notation_validator" {
File renamed without changes.
File renamed without changes.
File renamed without changes.

testdata/opa/validators/costcenter_meta_test.rego renamed to testdata/opa/validators/costcenter_meta/costcenter_meta_test.rego

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ import data.costcenter_meta.errors
55
import future.keywords
66

77
test_missing_costcenter if {
8-
count(errors) == 1 with input as {
8+
count(errors) == 1 with input as {"job": {
99
"ID": "my-job",
1010
"Meta": {},
11-
}
11+
}}
1212
}
1313

1414
test_costcenter_prefix_wrong if {
15-
count(errors) == 1 with input as {
15+
count(errors) == 1 with input as {"job": {
1616
"ID": "my-job",
1717
"Meta": {"costcenter": "my-costcenter"},
18-
}
18+
}}
1919
}
2020

2121
test_costcenter_correct if {
22-
count(errors) == 0 with input as {
22+
count(errors) == 0 with input as {"job": {
2323
"ID": "my-job",
2424
"Meta": {"costcenter": "cccode-my-costcenter"},
25-
}
25+
}}
2626
}

testdata/opa/validators/prefixed_policies.rego renamed to testdata/opa/validators/prefixed_policies/prefixed_policies.rego

File renamed without changes.

testdata/opa/validators/prefixed_policies_test.rego renamed to testdata/opa/validators/prefixed_policies/prefixed_policies_test.rego

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@ import data.prefixed_policies.errors
55
import future.keywords
66

77
test_no_errors if {
8-
count(errors) == 0 with input as {
8+
count(errors) == 0 with input as {"job": {
99
"ID": "example",
1010
"Name": "example",
1111
"TaskGroups": [{
1212
"Name": "cache",
1313
"Tasks": [],
1414
}],
1515
"Type": "service",
16-
}
16+
}}
1717
}
1818

1919
test_no_errors_for_valid_policy if {
20-
count(errors) == 0 with input as {
20+
count(errors) == 0 with input as {"job": {
2121
"ID": "example",
2222
"Name": "example",
2323
"TaskGroups": [{
2424
"Name": "cache",
2525
"Tasks": [{"Vault": {"Policies": ["example-redis"]}}],
2626
}],
2727
"Type": "service",
28-
}
28+
}}
2929
}
3030

3131
test_no_errors_for_multi_valid_policy if {
32-
count(errors) == 0 with input as {
32+
count(errors) == 0 with input as {"job": {
3333
"ID": "example",
3434
"Name": "example",
3535
"TaskGroups": [{
@@ -40,35 +40,35 @@ test_no_errors_for_multi_valid_policy if {
4040
]}}],
4141
}],
4242
"Type": "service",
43-
}
43+
}}
4444
}
4545

4646
test_errors_for_wrong_task_policy if {
47-
count(errors) == 1 with input as {
47+
count(errors) == 1 with input as {"job": {
4848
"ID": "example",
4949
"Name": "example",
5050
"TaskGroups": [{
5151
"Name": "cache",
5252
"Tasks": [{"Vault": {"Policies": ["some-randome-policy"]}}],
5353
}],
5454
"Type": "service",
55-
}
55+
}}
5656
}
5757

5858
test_errors_for_multi_wrong_policy if {
59-
count(errors) == 2 with input as {
59+
count(errors) == 2 with input as {"job": {
6060
"ID": "example",
6161
"Name": "example",
6262
"TaskGroups": [{
6363
"Name": "cache",
6464
"Tasks": [{"Vault": {"Policies": ["some-randome-policy", "also-not-valid"]}}],
6565
}],
6666
"Type": "service",
67-
}
67+
}}
6868
}
6969

7070
test_errors_for_wrong_task_group_policy if {
71-
count(errors) == 1 with input as {
71+
count(errors) == 1 with input as {"job": {
7272
"ID": "example",
7373
"Name": "example",
7474
"TaskGroups": [{
@@ -77,5 +77,5 @@ test_errors_for_wrong_task_group_policy if {
7777
"Tasks": [],
7878
}],
7979
"Type": "service",
80-
}
80+
}}
8181
}

0 commit comments

Comments
 (0)