From 9c38c1a0900e644b9abeb6f98d22d26516ca5ba9 Mon Sep 17 00:00:00 2001 From: Mehdi Moussaif Date: Fri, 24 Nov 2023 12:22:31 +0100 Subject: [PATCH] Add tests for cmd/shared Signed-off-by: Mehdi Moussaif --- cmd/shared/image_scan_test.go | 61 +++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 cmd/shared/image_scan_test.go diff --git a/cmd/shared/image_scan_test.go b/cmd/shared/image_scan_test.go new file mode 100644 index 00000000..2842e626 --- /dev/null +++ b/cmd/shared/image_scan_test.go @@ -0,0 +1,61 @@ +package shared + +import ( + "testing" + + "github.com/kubescape/kubescape/v3/core/cautils" + "github.com/stretchr/testify/assert" +) + +// Validate a scanInfo struct with a valid fail threshold severity +func TestValidateImageScanInfo(t *testing.T) { + testCases := []struct { + Description string + ScanInfo *cautils.ScanInfo + Want error + }{ + { + "Empty scanInfo is valid", + &cautils.ScanInfo{}, + nil, + }, + { + "Empty severity is valid", + &cautils.ScanInfo{FailThresholdSeverity: ""}, + nil, + }, + { + "High severity is valid", + &cautils.ScanInfo{FailThresholdSeverity: "High"}, + nil, + }, + { + "HIGH severity is valid", + &cautils.ScanInfo{FailThresholdSeverity: "HIGH"}, + nil, + }, + { + "high severity is valid", + &cautils.ScanInfo{FailThresholdSeverity: "high"}, + nil, + }, + { + "Unknown severity is invalid", + &cautils.ScanInfo{FailThresholdSeverity: "unknown"}, + ErrUnknownSeverity, + }, + } + + for _, tc := range testCases { + t.Run( + tc.Description, + func(t *testing.T) { + var want error = tc.Want + + got := ValidateImageScanInfo(tc.ScanInfo) + + assert.Equal(t, want, got) + }, + ) + } +}