From 5e78ad402e7f98817b18a93e4e5807ada53bad4d Mon Sep 17 00:00:00 2001 From: Miccah Date: Fri, 5 Jan 2024 12:06:59 -0800 Subject: [PATCH] [chore] Add test to check all versioned detectors are non-zero (#2272) --- pkg/engine/defaults_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/engine/defaults_test.go b/pkg/engine/defaults_test.go index 67e41bc8..6131b211 100644 --- a/pkg/engine/defaults_test.go +++ b/pkg/engine/defaults_test.go @@ -48,3 +48,20 @@ func TestDefaultDetectorTypesImplementing(t *testing.T) { ) } } + +func TestDefaultVersionerDetectorsHaveNonZeroVersions(t *testing.T) { + // Loop through all our default detectors and find the ones that + // implement Versioner. Of those, check each version is not zero. + // This is required due to an implementation detail of filtering detectors. + // See: https://github.com/trufflesecurity/trufflehog/blob/v3.63.7/main.go#L624-L638 + for _, detector := range DefaultDetectors() { + v, ok := detector.(detectors.Versioner) + if !ok || v.Version() != 0 { + continue + } + t.Errorf( + "detector %q implements Versioner that returns a zero version", + detectorspb.DetectorType_name[int32(detector.Type())], + ) + } +}