generated from kubewarden/go-policy-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsettings_test.go
57 lines (47 loc) · 1.39 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
package main
import (
"encoding/json"
"testing"
)
func TestParsingSettingsWithNoValueProvided(t *testing.T) {
rawSettings := []byte(`{}`)
settings := &Settings{}
if err := json.Unmarshal(rawSettings, settings); err != nil {
t.Errorf("Unexpected error %+v", err)
}
if len(settings.PropagatedLabels) != 0 {
t.Errorf("PropagatedLabels should contains zero labels after unmarshal")
}
valid, _ := settings.Valid()
if valid {
t.Errorf("Empty settings should not be valid")
}
}
func TestParsingSettingsWithEmptyStringLabel(t *testing.T) {
rawSettings := []byte(`{"propagatedLabels": ["label", ""]}`)
settings := &Settings{}
if err := json.Unmarshal(rawSettings, settings); err != nil {
t.Errorf("Unexpected error %+v", err)
}
if len(settings.PropagatedLabels) != 2 {
t.Errorf("PropagatedLabels should contains two labels after unmarshal")
}
valid, _ := settings.Valid()
if valid {
t.Errorf("Empty label string should not be valid")
}
}
func TestParsingSettingsWithNoLabels(t *testing.T) {
rawSettings := []byte(`{"propagatedLabels": []}`)
settings := &Settings{}
if err := json.Unmarshal(rawSettings, settings); err != nil {
t.Errorf("Unexpected error %+v", err)
}
if len(settings.PropagatedLabels) != 0 {
t.Errorf("PropagatedLabels should contains zero labels after unmarshal")
}
valid, _ := settings.Valid()
if valid {
t.Errorf("At least one label must be provided")
}
}