@@ -7,7 +7,108 @@ import (
7
7
)
8
8
9
9
func TestSeverity_Validate (t * testing.T ) {
10
+ testCases := []struct {
11
+ desc string
12
+ severity * Severity
13
+ }{
14
+ {
15
+ desc : "default with rules" ,
16
+ severity : & Severity {
17
+ Default : "high" ,
18
+ Rules : []SeverityRule {
19
+ {
20
+ Severity : "low" ,
21
+ BaseRule : BaseRule {
22
+ Path : "test" ,
23
+ },
24
+ },
25
+ },
26
+ },
27
+ },
28
+ {
29
+ desc : "default without rules" ,
30
+ severity : & Severity {
31
+ Default : "high" ,
32
+ },
33
+ },
34
+ {
35
+ desc : "same severity between default and rule" ,
36
+ severity : & Severity {
37
+ Default : "high" ,
38
+ Rules : []SeverityRule {
39
+ {
40
+ Severity : "high" ,
41
+ BaseRule : BaseRule {
42
+ Path : "test" ,
43
+ },
44
+ },
45
+ },
46
+ },
47
+ },
48
+ }
49
+
50
+ for _ , test := range testCases {
51
+ test := test
52
+ t .Run (test .desc , func (t * testing.T ) {
53
+ t .Parallel ()
54
+
55
+ err := test .severity .Validate ()
56
+ require .NoError (t , err )
57
+ })
58
+ }
59
+ }
60
+
61
+ func TestSeverity_Validate_error (t * testing.T ) {
62
+ testCases := []struct {
63
+ desc string
64
+ severity * Severity
65
+ expected string
66
+ }{
67
+ {
68
+ desc : "missing default severity" ,
69
+ severity : & Severity {
70
+ Default : "" ,
71
+ Rules : []SeverityRule {
72
+ {
73
+ Severity : "low" ,
74
+ BaseRule : BaseRule {
75
+ Path : "test" ,
76
+ },
77
+ },
78
+ },
79
+ },
80
+ expected : "can't set severity rule option: no default severity defined" ,
81
+ },
82
+ {
83
+ desc : "missing rule severity" ,
84
+ severity : & Severity {
85
+ Default : "high" ,
86
+ Rules : []SeverityRule {
87
+ {
88
+ BaseRule : BaseRule {
89
+ Path : "test" ,
90
+ },
91
+ },
92
+ },
93
+ },
94
+ expected : "error in severity rule #0: severity should be set" ,
95
+ },
96
+ }
97
+
98
+ for _ , test := range testCases {
99
+ test := test
100
+ t .Run (test .desc , func (t * testing.T ) {
101
+ t .Parallel ()
102
+
103
+ err := test .severity .Validate ()
104
+ require .EqualError (t , err , test .expected )
105
+ })
106
+ }
107
+ }
108
+
109
+ func TestSeverityRule_Validate (t * testing.T ) {
10
110
rule := & SeverityRule {
111
+ Severity : "low" ,
11
112
BaseRule : BaseRule {
12
113
Path : "test" ,
13
114
},
@@ -17,20 +118,32 @@ func TestSeverity_Validate(t *testing.T) {
17
118
require .NoError (t , err )
18
119
}
19
120
20
- func TestSeverity_Validate_error (t * testing.T ) {
121
+ func TestSeverityRule_Validate_error (t * testing.T ) {
21
122
testCases := []struct {
22
123
desc string
23
124
rule * SeverityRule
24
125
expected string
25
126
}{
26
127
{
27
- desc : "empty rule" ,
28
- rule : & SeverityRule {},
128
+ desc : "missing severity" ,
129
+ rule : & SeverityRule {
130
+ BaseRule : BaseRule {
131
+ Path : "test" ,
132
+ },
133
+ },
134
+ expected : "severity should be set" ,
135
+ },
136
+ {
137
+ desc : "empty rule" ,
138
+ rule : & SeverityRule {
139
+ Severity : "low" ,
140
+ },
29
141
expected : "at least 1 of (text, source, path[-except], linters) should be set" ,
30
142
},
31
143
{
32
144
desc : "invalid path rule" ,
33
145
rule : & SeverityRule {
146
+ Severity : "low" ,
34
147
BaseRule : BaseRule {
35
148
Path : "**test" ,
36
149
},
@@ -40,6 +153,7 @@ func TestSeverity_Validate_error(t *testing.T) {
40
153
{
41
154
desc : "invalid path-except rule" ,
42
155
rule : & SeverityRule {
156
+ Severity : "low" ,
43
157
BaseRule : BaseRule {
44
158
PathExcept : "**test" ,
45
159
},
@@ -49,6 +163,7 @@ func TestSeverity_Validate_error(t *testing.T) {
49
163
{
50
164
desc : "invalid text rule" ,
51
165
rule : & SeverityRule {
166
+ Severity : "low" ,
52
167
BaseRule : BaseRule {
53
168
Text : "**test" ,
54
169
},
@@ -58,6 +173,7 @@ func TestSeverity_Validate_error(t *testing.T) {
58
173
{
59
174
desc : "invalid source rule" ,
60
175
rule : & SeverityRule {
176
+ Severity : "low" ,
61
177
BaseRule : BaseRule {
62
178
Source : "**test" ,
63
179
},
@@ -67,6 +183,7 @@ func TestSeverity_Validate_error(t *testing.T) {
67
183
{
68
184
desc : "path and path-expect" ,
69
185
rule : & SeverityRule {
186
+ Severity : "low" ,
70
187
BaseRule : BaseRule {
71
188
Path : "test" ,
72
189
PathExcept : "test" ,
0 commit comments