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\n other: 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\n other: 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}
@@ -444,6 +514,12 @@ func Test_compareRegex(t *testing.T) {
444514 },
445515 expected : true ,
446516 },
517+ {
518+ name : "empty conditional" ,
519+ conditional : "" ,
520+ foundMatches : map [string ]string {},
521+ expected : true ,
522+ },
447523 }
448524 for _ , test := range tests {
449525 t .Run (test .name , func (t * testing.T ) {
@@ -452,7 +528,7 @@ func Test_compareRegex(t *testing.T) {
452528 actual , err := compareRegex (test .conditional , test .foundMatches )
453529 req .NoError (err )
454530
455- assert .Equal (t , test .expected , actual )
531+ req .Equal (test .expected , actual )
456532 })
457533 }
458534}
0 commit comments