@@ -776,6 +776,106 @@ func Test_textAnalyze(t *testing.T) {
776
776
"text-collector-1/cfile-2.txt" : []byte ("Yes it all succeeded" ),
777
777
},
778
778
},
779
+ {
780
+ name : "exec collector auto-path matching for stdout" ,
781
+ analyzer : troubleshootv1beta2.TextAnalyze {
782
+ Outcomes : []* troubleshootv1beta2.Outcome {
783
+ {
784
+ Pass : & troubleshootv1beta2.SingleOutcome {
785
+ Message : "Command output found" ,
786
+ },
787
+ },
788
+ {
789
+ Fail : & troubleshootv1beta2.SingleOutcome {
790
+ Message : "Command output not found" ,
791
+ },
792
+ },
793
+ },
794
+ CollectorName : "netbox-branch-check" ,
795
+ FileName : "netbox-branch-check-stdout.txt" , // Simple filename, but file is nested deeper
796
+ RegexPattern : "success" ,
797
+ },
798
+ expectResult : []AnalyzeResult {
799
+ {
800
+ IsPass : true ,
801
+ IsWarn : false ,
802
+ IsFail : false ,
803
+ Title : "netbox-branch-check" ,
804
+ Message : "Command output found" ,
805
+ IconKey : "kubernetes_text_analyze" ,
806
+ IconURI : "https://troubleshoot.sh/images/analyzer-icons/text-analyze.svg" ,
807
+ },
808
+ },
809
+ files : map [string ][]byte {
810
+ // File is stored in exec-style nested path: {collector}/{namespace}/{pod}/{collector}-stdout.txt
811
+ "netbox-branch-check/netbox-enterprise/netbox-enterprise-858bcb8d4-cdgk7/netbox-branch-check-stdout.txt" : []byte ("operation success completed" ),
812
+ },
813
+ },
814
+ {
815
+ name : "exec collector auto-path matching for stderr" ,
816
+ analyzer : troubleshootv1beta2.TextAnalyze {
817
+ Outcomes : []* troubleshootv1beta2.Outcome {
818
+ {
819
+ Pass : & troubleshootv1beta2.SingleOutcome {
820
+ Message : "No errors in stderr" ,
821
+ When : "false" ,
822
+ },
823
+ },
824
+ {
825
+ Fail : & troubleshootv1beta2.SingleOutcome {
826
+ Message : "Error found in stderr" ,
827
+ When : "true" ,
828
+ },
829
+ },
830
+ },
831
+ CollectorName : "my-exec-collector" ,
832
+ FileName : "my-exec-collector-stderr.txt" ,
833
+ RegexPattern : "error" ,
834
+ },
835
+ expectResult : []AnalyzeResult {
836
+ {
837
+ IsPass : false ,
838
+ IsWarn : false ,
839
+ IsFail : true ,
840
+ Title : "my-exec-collector" ,
841
+ Message : "Error found in stderr" ,
842
+ IconKey : "kubernetes_text_analyze" ,
843
+ IconURI : "https://troubleshoot.sh/images/analyzer-icons/text-analyze.svg" ,
844
+ },
845
+ },
846
+ files : map [string ][]byte {
847
+ "my-exec-collector/default/my-pod-12345/my-exec-collector-stderr.txt" : []byte ("connection error occurred" ),
848
+ },
849
+ },
850
+ {
851
+ name : "exec collector no auto-match when wildcards already present" ,
852
+ analyzer : troubleshootv1beta2.TextAnalyze {
853
+ Outcomes : []* troubleshootv1beta2.Outcome {
854
+ {
855
+ Pass : & troubleshootv1beta2.SingleOutcome {
856
+ Message : "Found with existing wildcard" ,
857
+ },
858
+ },
859
+ },
860
+ CollectorName : "test-collector" ,
861
+ FileName : "*/test-collector-stdout.txt" , // Already has wildcard, should not be modified
862
+ RegexPattern : "output" ,
863
+ },
864
+ expectResult : []AnalyzeResult {
865
+ {
866
+ IsPass : true ,
867
+ IsWarn : false ,
868
+ IsFail : false ,
869
+ Title : "test-collector" ,
870
+ Message : "Found with existing wildcard" ,
871
+ IconKey : "kubernetes_text_analyze" ,
872
+ IconURI : "https://troubleshoot.sh/images/analyzer-icons/text-analyze.svg" ,
873
+ },
874
+ },
875
+ files : map [string ][]byte {
876
+ "test-collector/something/test-collector-stdout.txt" : []byte ("some output here" ),
877
+ },
878
+ },
779
879
}
780
880
781
881
for _ , test := range tests {
0 commit comments