generated from jimschubert/go-cli-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_test.go
94 lines (90 loc) · 2.71 KB
/
config_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
package docked
import (
"testing"
"github.com/jimschubert/docked/model"
"github.com/jimschubert/docked/model/docker/commands"
"github.com/jimschubert/docked/model/validations"
"github.com/stretchr/testify/assert"
)
func TestConfig_Load(t *testing.T) {
type args struct {
path string
}
tests := []struct {
name string
args args
want Config
wantErr bool
}{
{
name: "contains ignore only",
args: args{"testdata/config/ignore_only.yml"},
want: Config{Ignore: []string{"D5:secret-aws-access-key"}},
wantErr: false,
},
{
name: "contains rule overrides only (as array of objects)",
args: args{"testdata/config/rules_only.yml"},
want: Config{RuleOverrides: &RuleOverrides{
{"D5:secret-aws-access-key", model.LowPriority.Ptr()},
{"D5:secret-aws-secret-access-key", model.CriticalPriority.Ptr()},
}},
wantErr: false,
},
{
name: "contains rule overrides only (as map)",
args: args{"testdata/config/rules_kvp.yml"},
want: Config{RuleOverrides: &RuleOverrides{
{"D5:secret-aws-access-key", model.LowPriority.Ptr()},
{"D5:secret-aws-secret-access-key", model.CriticalPriority.Ptr()},
}},
wantErr: false,
},
{
name: "contains ignores and rule overrides",
args: args{"testdata/config/ignores_and_rules.yml"},
want: Config{
Ignore: []string{"D5:secret-aws-access-key", "D5:secret-aws-secret-access-key"},
RuleOverrides: &RuleOverrides{
{"D7:tagged-latest", model.CriticalPriority.Ptr()},
{"D7:tagged-latest-builder", model.HighPriority.Ptr()},
{"DC:consider-multistage", model.CriticalPriority.Ptr()},
}},
wantErr: false,
},
{
name: "contains ignores and rule overrides",
args: args{"testdata/config/full_with_custom_rules.yml"},
want: Config{
Ignore: []string{"D5:secret-aws-access-key", "D5:secret-aws-secret-access-key"},
RuleOverrides: &RuleOverrides{
{"D7:tagged-latest", model.CriticalPriority.Ptr()},
{"D7:tagged-latest-builder", model.HighPriority.Ptr()},
{"DC:consider-multistage", model.CriticalPriority.Ptr()},
},
CustomRules: []validations.SimpleRegexRule{
{
Name: "no funny business",
Summary: "Prevent common typo on our team",
Details: "Jim keeps mistyping rm -rf",
Pattern: `rm -rf /\b`,
Priority: model.CriticalPriority,
Command: commands.Run,
},
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := Config{}
err := c.Load(tt.args.path)
if (err != nil) != tt.wantErr {
t.Errorf("yaml.Unmarshal to Config{} error = %v, wantErr %v", err, tt.wantErr)
return
}
assert.Equal(t, tt.want, c, "yaml.Unmarshal to got = %v, want %v", c, tt.want)
})
}
}