Skip to content

Commit 6a0fb2e

Browse files
committed
greatly improve coverage by adding regex group tests
1 parent 6861660 commit 6a0fb2e

File tree

1 file changed

+73
-3
lines changed

1 file changed

+73
-3
lines changed

pkg/analyze/text_analyze_test.go

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"testing"
88

99
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
10-
"github.com/stretchr/testify/assert"
1110
"github.com/stretchr/testify/require"
1211
)
1312

@@ -371,6 +370,77 @@ func Test_textAnalyze(t *testing.T) {
371370
"text-collector-1/cfile-1.txt": []byte("Yes it all SUCCEEDED"),
372371
},
373372
},
373+
374+
{
375+
name: "compare group with integer",
376+
analyzer: troubleshootv1beta2.TextAnalyze{
377+
Outcomes: []*troubleshootv1beta2.Outcome{
378+
{
379+
Pass: &troubleshootv1beta2.SingleOutcome{
380+
When: "val > 10",
381+
Message: "val is greater than 10",
382+
},
383+
},
384+
{
385+
Fail: &troubleshootv1beta2.SingleOutcome{
386+
Message: "val is not greater than 10",
387+
},
388+
},
389+
},
390+
CollectorName: "text-collector-1",
391+
FileName: "cfile-1.txt",
392+
RegexGroups: `value: (?P<val>\d+)`,
393+
},
394+
expectResult: []AnalyzeResult{
395+
{
396+
IsPass: true,
397+
IsWarn: false,
398+
IsFail: false,
399+
Title: "text-collector-1",
400+
Message: "val is greater than 10",
401+
IconKey: "kubernetes_text_analyze",
402+
IconURI: "https://troubleshoot.sh/images/analyzer-icons/text-analyze.svg?w=13&h=16",
403+
},
404+
},
405+
files: map[string][]byte{
406+
"text-collector-1/cfile-1.txt": []byte("value: 15\nother: 10"),
407+
},
408+
},
409+
{
410+
name: "compare group with integer (failure)",
411+
analyzer: troubleshootv1beta2.TextAnalyze{
412+
Outcomes: []*troubleshootv1beta2.Outcome{
413+
{
414+
Pass: &troubleshootv1beta2.SingleOutcome{
415+
When: "val > 10",
416+
Message: "val is greater than 10",
417+
},
418+
},
419+
{
420+
Fail: &troubleshootv1beta2.SingleOutcome{
421+
Message: "val is not greater than 10",
422+
},
423+
},
424+
},
425+
CollectorName: "text-collector-1",
426+
FileName: "cfile-1.txt",
427+
RegexGroups: `value: (?P<val>\d+)`,
428+
},
429+
expectResult: []AnalyzeResult{
430+
{
431+
IsPass: false,
432+
IsWarn: false,
433+
IsFail: true,
434+
Title: "text-collector-1",
435+
Message: "val is not greater than 10",
436+
IconKey: "kubernetes_text_analyze",
437+
IconURI: "https://troubleshoot.sh/images/analyzer-icons/text-analyze.svg?w=13&h=16",
438+
},
439+
},
440+
files: map[string][]byte{
441+
"text-collector-1/cfile-1.txt": []byte("value: 2\nother: 10"),
442+
},
443+
},
374444
}
375445

376446
for _, test := range tests {
@@ -404,7 +474,7 @@ func Test_textAnalyze(t *testing.T) {
404474
for _, v := range actual {
405475
unPointered = append(unPointered, *v)
406476
}
407-
assert.ElementsMatch(t, test.expectResult, unPointered)
477+
req.ElementsMatch(test.expectResult, unPointered)
408478
})
409479
}
410480
}
@@ -458,7 +528,7 @@ func Test_compareRegex(t *testing.T) {
458528
actual, err := compareRegex(test.conditional, test.foundMatches)
459529
req.NoError(err)
460530

461-
assert.Equal(t, test.expected, actual)
531+
req.Equal(test.expected, actual)
462532
})
463533
}
464534
}

0 commit comments

Comments
 (0)