diff --git a/pkg/analyze/text_analyze_test.go b/pkg/analyze/text_analyze_test.go index 07843e6e..05bb75dd 100644 --- a/pkg/analyze/text_analyze_test.go +++ b/pkg/analyze/text_analyze_test.go @@ -477,6 +477,41 @@ func Test_textAnalyze(t *testing.T) { "text-collector-1/cfile-1.txt": []byte("value: 2\nother: 10"), }, }, + { + name: "Warn message is templated with regex groups", + analyzer: troubleshootv1beta2.TextAnalyze{ + Outcomes: []*troubleshootv1beta2.Outcome{ + { + Pass: &troubleshootv1beta2.SingleOutcome{ + When: `Warning == ""`, + Message: "No warning found", + }, + }, + { + Warn: &troubleshootv1beta2.SingleOutcome{ + Message: "Warning for CRD with name in {{ .CRDName }} in namespace {{ .Namespace }}", + }, + }, + }, + CollectorName: "text-collector-templated-regex-message", + FileName: "cfile-1.txt", + RegexGroups: `"name":\s*"(?P.*?)".*namespace":\s*"(?P.*?)".*warning":\s*.*"(?Pmywarning.*?)"`, + }, + expectResult: []AnalyzeResult{ + { + IsPass: false, + IsWarn: true, + IsFail: false, + Title: "text-collector-templated-regex-message", + Message: "Warning for CRD with name in insert-crd-name-here in namespace default", + IconKey: "kubernetes_text_analyze", + IconURI: "https://troubleshoot.sh/images/analyzer-icons/text-analyze.svg?w=13&h=16", + }, + }, + files: map[string][]byte{ + "text-collector-templated-regex-message/cfile-1.txt": []byte(`{"level":"ERROR","timestamp":"2022-05-17T20:37:41Z","caller":"controller/controller.go:317","message":"Reconciler error","context":{"name":"insert-crd-name-here","namespace":"default","warning":"mywarning"}}`), + }, + }, { name: "Outcome message is templated with regex groups", analyzer: troubleshootv1beta2.TextAnalyze{