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