generated from kubewarden/go-policy-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
settings_test.go
101 lines (87 loc) · 1.93 KB
/
settings_test.go
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"testing"
)
func TestParsingSettingsWithAllValuesProvidedFromValidationReq(t *testing.T) {
request := `
{
"request": "doesn't matter here",
"settings": {
"allowedTypes": [
"configMap",
"downwardAPI",
"emptyDir",
"persistentVolumeClaim",
"secret",
"projected"
]
}
}
`
rawRequest := []byte(request)
settings, err := NewSettingsFromValidationReq(rawRequest)
if err != nil {
t.Errorf("Unexpected error %+v", err)
}
if !settings.AllowedTypes.Contains("configMap") ||
!settings.AllowedTypes.Contains("downwardAPI") ||
!settings.AllowedTypes.Contains("emptyDir") ||
!settings.AllowedTypes.Contains("persistentVolumeClaim") ||
!settings.AllowedTypes.Contains("secret") ||
!settings.AllowedTypes.Contains("projected") {
t.Errorf("Missing value")
}
}
func TestParsingSettingsWithNoValueProvided(t *testing.T) {
request := `
{
"request": "doesn't matter here",
"settings": {
}
}
`
rawRequest := []byte(request)
settings, err := NewSettingsFromValidationReq(rawRequest)
if err != nil {
t.Errorf("Unexpected error %+v", err)
}
if settings.AllowedTypes.Cardinality() != 0 {
t.Errorf("Expected AllowedTypes to be empty")
}
}
func TestSettingsWithInvalidEntries(t *testing.T) {
request := `
{
"allowedTypes": [
"configMap",
"*"
]
}
`
rawRequest := []byte(request)
settings, err := NewSettingsFromValidateSettingsPayload(rawRequest)
if err != nil {
t.Error("Expected no error, got one")
}
if settings.Valid() {
t.Errorf("Expected Settings reported as not valid")
}
}
func TestEmptySettingsAreValid(t *testing.T) {
request := `
{
"request": "doesn't matter here",
"settings": {
"allowedTypes": []
}
}
`
rawRequest := []byte(request)
settings, err := NewSettingsFromValidateSettingsPayload(rawRequest)
if err != nil {
t.Errorf("Unexpected error %+v", err)
}
if !settings.Valid() {
t.Errorf("Settings are reported as not valid")
}
}