-
Notifications
You must be signed in to change notification settings - Fork 4
/
main_test.rego
70 lines (60 loc) · 1.38 KB
/
main_test.rego
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main_test
import data.system.main
test_main_with_no_input {
main == {
"apiVersion": "admission.k8s.io/v1beta1",
"kind": "AdmissionReview",
"response": {
"allowed": true
}
}
}
test_main_with_input_requiring_patch {
some encoded_patches
main = {
"apiVersion": "admission.k8s.io/v1beta1",
"kind": "AdmissionReview",
"response": {
"allowed": true,
"patchType": "JSONPatch",
"patch": encoded_patches,
}
} with input.request.object as {
"metadata": {
"labels": {
"test-opa-patch": "true",
}
}
}
patches := json.unmarshal(base64.decode(encoded_patches))
patches == [
{
"op": "add",
"path": "/metadata/annotations",
"value": {}
},
{
"op": "add",
"path": "/metadata/annotations/test-key",
"value": "test-value"
}
]
}
test_main_with_input_failing_validation {
main == {
"apiVersion": "admission.k8s.io/v1beta1",
"kind": "AdmissionReview",
"response": {
"allowed": false,
"status": {
"reason": "missing required label",
},
},
} with input.request.object as {
"metadata": {
"labels": {
"test-opa-validation": "true",
}
}
}
}