Skip to content

Commit d40206a

Browse files
committed
Add test
Renamed policy to project_scm_branch_validation
1 parent 0142435 commit d40206a

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

aap_policy_examples/project_scm_branch.rego renamed to aap_policy_examples/project_scm_branch_validation.rego

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ project_scm_branch_validation := result if {
2626
}
2727

2828
# Check if a given branch value is allowed
29+
allowed_branch(branch) if {
30+
branch == ""
31+
}
32+
2933
allowed_branch(branch) if {
3034
some allowed_value in valid_project_scm_branch_values
3135
branch == allowed_value
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package test_aap_policy_examples
2+
3+
import data.aap_policy_examples
4+
5+
test_valid_main_branch_allowed if {
6+
test_input := {
7+
"project": {
8+
"scm_branch": "main"
9+
}
10+
}
11+
aap_policy_examples.project_scm_branch_validation.allowed == true with input as test_input
12+
}
13+
14+
test_valid_v1_branch_allowed if {
15+
test_input := {
16+
"project": {
17+
"scm_branch": "v1"
18+
}
19+
}
20+
aap_policy_examples.project_scm_branch_validation.allowed == true with input as test_input
21+
}
22+
23+
test_invalid_branch_blocked if {
24+
test_input := {
25+
"project": {
26+
"scm_branch": "develop"
27+
}
28+
}
29+
aap_policy_examples.project_scm_branch_validation.allowed == false with input as test_input
30+
}
31+
32+
test_invalid_branch_violation_message if {
33+
test_input := {
34+
"project": {
35+
"scm_branch": "develop"
36+
}
37+
}
38+
aap_policy_examples.project_scm_branch_validation.violations[0] == "Invalid branch: develop. Only named 'main' or 'v1' branches are allowed." with input as test_input
39+
}

0 commit comments

Comments
 (0)