Skip to content

Commit 6861660

Browse files
committed
simplify the text analyze code by combining with compareRegex code
1 parent 39350b5 commit 6861660

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

pkg/analyze/text_analyze.go

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,6 @@ func analyzeRegexGroups(pattern string, collected []byte, outcomes []*troublesho
137137
// allow fallthrough
138138
for _, outcome := range outcomes {
139139
if outcome.Fail != nil {
140-
if outcome.Fail.When == "" {
141-
result.IsFail = true
142-
result.Message = outcome.Fail.Message
143-
result.URI = outcome.Fail.URI
144-
145-
return result, nil
146-
}
147-
148140
isMatch, err := compareRegex(outcome.Fail.When, foundMatches)
149141
if err != nil {
150142
return result, errors.Wrap(err, "failed to compare regex fail conditional")
@@ -158,14 +150,6 @@ func analyzeRegexGroups(pattern string, collected []byte, outcomes []*troublesho
158150
return result, nil
159151
}
160152
} else if outcome.Warn != nil {
161-
if outcome.Warn.When == "" {
162-
result.IsWarn = true
163-
result.Message = outcome.Warn.Message
164-
result.URI = outcome.Warn.URI
165-
166-
return result, nil
167-
}
168-
169153
isMatch, err := compareRegex(outcome.Warn.When, foundMatches)
170154
if err != nil {
171155
return result, errors.Wrap(err, "failed to compare regex warn conditional")
@@ -179,14 +163,6 @@ func analyzeRegexGroups(pattern string, collected []byte, outcomes []*troublesho
179163
return result, nil
180164
}
181165
} else if outcome.Pass != nil {
182-
if outcome.Pass.When == "" {
183-
result.IsPass = true
184-
result.Message = outcome.Pass.Message
185-
result.URI = outcome.Pass.URI
186-
187-
return result, nil
188-
}
189-
190166
isMatch, err := compareRegex(outcome.Pass.When, foundMatches)
191167
if err != nil {
192168
return result, errors.Wrap(err, "failed to compare regex pass conditional")
@@ -206,6 +182,9 @@ func analyzeRegexGroups(pattern string, collected []byte, outcomes []*troublesho
206182
}
207183

208184
func compareRegex(conditional string, foundMatches map[string]string) (bool, error) {
185+
if conditional == "" {
186+
return true, nil
187+
}
209188
parts := strings.Split(strings.TrimSpace(conditional), " ")
210189

211190
if len(parts) != 3 {

pkg/analyze/text_analyze_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,12 @@ func Test_compareRegex(t *testing.T) {
444444
},
445445
expected: true,
446446
},
447+
{
448+
name: "empty conditional",
449+
conditional: "",
450+
foundMatches: map[string]string{},
451+
expected: true,
452+
},
447453
}
448454
for _, test := range tests {
449455
t.Run(test.name, func(t *testing.T) {

0 commit comments

Comments
 (0)