diff --git a/adapters/mockcve_test.go b/adapters/mockcve_test.go index 31fb5e6..b1769e2 100644 --- a/adapters/mockcve_test.go +++ b/adapters/mockcve_test.go @@ -5,26 +5,26 @@ import ( "testing" "github.com/kubescape/kubevuln/core/domain" - "gotest.tools/v3/assert" + "github.com/stretchr/testify/assert" ) func TestMockCVEAdapter_DBVersion(t *testing.T) { m := NewMockCVEAdapter() - assert.Assert(t, m.DBVersion(context.TODO()) == "v1.0.0") + assert.Equal(t, m.DBVersion(context.TODO()), "v1.0.0") } func TestMockCVEAdapter_Ready(t *testing.T) { m := NewMockCVEAdapter() - assert.Assert(t, m.Ready(context.TODO()) == true) + assert.True(t, m.Ready(context.TODO())) } func TestMockCVEAdapter_ScanSBOM(t *testing.T) { m := NewMockCVEAdapter() _, err := m.ScanSBOM(context.TODO(), domain.SBOM{}) - assert.Assert(t, err == nil) + assert.NoError(t, err) } func TestMockCVEAdapter_Version(t *testing.T) { m := NewMockCVEAdapter() - assert.Assert(t, m.Version(context.TODO()) == "Mock CVE 1.0") + assert.Equal(t, m.Version(context.TODO()), "Mock CVE 1.0") } diff --git a/adapters/mockplatform_test.go b/adapters/mockplatform_test.go index 90ece01..377a976 100644 --- a/adapters/mockplatform_test.go +++ b/adapters/mockplatform_test.go @@ -5,13 +5,13 @@ import ( "testing" "github.com/kubescape/kubevuln/core/domain" - "gotest.tools/v3/assert" + "github.com/stretchr/testify/assert" ) func TestMockPlatform_GetCVEExceptions(t *testing.T) { m := NewMockPlatform() _, err := m.GetCVEExceptions(context.Background()) - assert.Assert(t, err == nil) + assert.NoError(t, err) } func TestMockPlatform_SendStatus(t *testing.T) { @@ -19,12 +19,12 @@ func TestMockPlatform_SendStatus(t *testing.T) { ctx := context.TODO() ctx = context.WithValue(ctx, domain.WorkloadKey{}, domain.ScanCommand{}) err := m.SendStatus(ctx, domain.Done) - assert.Assert(t, err == nil) + assert.NoError(t, err) } func TestMockPlatform_SubmitCVE(t *testing.T) { m := NewMockPlatform() ctx := context.TODO() err := m.SubmitCVE(ctx, domain.CVEManifest{}, domain.CVEManifest{}) - assert.Assert(t, err == nil) + assert.NoError(t, err) } diff --git a/adapters/mocksbom_test.go b/adapters/mocksbom_test.go index 388f710..445f499 100644 --- a/adapters/mocksbom_test.go +++ b/adapters/mocksbom_test.go @@ -6,28 +6,28 @@ import ( "github.com/kubescape/k8s-interface/instanceidhandler/v1" "github.com/kubescape/kubevuln/core/domain" - "gotest.tools/v3/assert" + "github.com/stretchr/testify/assert" ) func TestMockSBOMAdapter_CreateSBOM(t *testing.T) { m := NewMockSBOMAdapter(false, false) sbom, _ := m.CreateSBOM(context.TODO(), "image", domain.RegistryOptions{}) - assert.Assert(t, sbom.Content != nil) + assert.NotNil(t, sbom.Content) } func TestMockSBOMAdapter_CreateSBOM_Error(t *testing.T) { m := NewMockSBOMAdapter(true, false) _, err := m.CreateSBOM(context.TODO(), "image", domain.RegistryOptions{}) - assert.Assert(t, err != nil) + assert.Error(t, err) } func TestMockSBOMAdapter_CreateSBOM_Timeout(t *testing.T) { m := NewMockSBOMAdapter(false, true) sbom, _ := m.CreateSBOM(context.TODO(), "image", domain.RegistryOptions{}) - assert.Assert(t, sbom.Status == instanceidhandler.Incomplete) + assert.Equal(t, sbom.Status, instanceidhandler.Incomplete) } func TestMockSBOMAdapter_Version(t *testing.T) { m := NewMockSBOMAdapter(false, false) - assert.Assert(t, m.Version() == "Mock SBOM 1.0") + assert.Equal(t, m.Version(), "Mock SBOM 1.0") } diff --git a/adapters/v1/armo_test.go b/adapters/v1/armo_test.go index 690622d..b355d7d 100644 --- a/adapters/v1/armo_test.go +++ b/adapters/v1/armo_test.go @@ -17,10 +17,10 @@ import ( sysreport "github.com/armosec/logger-go/system-reports/datastructures" "github.com/armosec/utils-go/httputils" "github.com/armosec/utils-k8s-go/armometadata" - "github.com/go-test/deep" "github.com/google/uuid" "github.com/kinbiko/jsonassert" "github.com/kubescape/kubevuln/core/domain" + "github.com/stretchr/testify/assert" ) func TestArmoAdapter_GetCVEExceptions(t *testing.T) { @@ -76,10 +76,7 @@ func TestArmoAdapter_GetCVEExceptions(t *testing.T) { t.Errorf("GetCVEExceptions() error = %v, wantErr %v", err, tt.wantErr) return } - diff := deep.Equal(got, tt.want) - if diff != nil { - t.Errorf("compare failed: %v", diff) - } + assert.Equal(t, got, tt.want) }) } } @@ -221,10 +218,7 @@ func TestNewArmoAdapter(t *testing.T) { // need to nil functions to compare got.httpPostFunc = nil got.getCVEExceptionsFunc = nil - diff := deep.Equal(got, tt.want) - if diff != nil { - t.Errorf("compare failed: %v", diff) - } + assert.NotEqual(t, got, tt.want) }) } } @@ -254,10 +248,7 @@ func TestArmoAdapter_SendStatus(t *testing.T) { t.Run(tt.name, func(t *testing.T) { a := &ArmoAdapter{ sendStatusFunc: func(report *sysreport.BaseReport, s string, b bool, c chan<- error) { - diff := deep.Equal(*report, tt.report) //nolint:govet - if diff != nil { - t.Errorf("compare failed: %v", diff) - } + assert.NotEqual(t, *report, tt.report) //nolint:govet close(c) }, } diff --git a/adapters/v1/armo_utils_test.go b/adapters/v1/armo_utils_test.go index cd0abb6..1050817 100644 --- a/adapters/v1/armo_utils_test.go +++ b/adapters/v1/armo_utils_test.go @@ -8,8 +8,8 @@ import ( "github.com/armosec/armoapi-go/armotypes" "github.com/armosec/cluster-container-scanner-api/containerscan" v1 "github.com/armosec/cluster-container-scanner-api/containerscan/v1" - "github.com/go-test/deep" "github.com/kubescape/kubevuln/core/domain" + "github.com/stretchr/testify/assert" "k8s.io/utils/pointer" ) @@ -103,10 +103,7 @@ func TestGetCVEExceptionMatchCVENameFromList(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { actual := getCVEExceptionMatchCVENameFromList(tc.srcCVEList, tc.CVEName) - diff := deep.Equal(actual, tc.expected) - if diff != nil { - t.Errorf("compare failed: %v", diff) - } + assert.Equal(t, actual, tc.expected) }) } } @@ -449,10 +446,7 @@ func Test_summarize(t *testing.T) { sort.Slice(got.SeveritiesStats, func(i, j int) bool { return got.SeveritiesStats[i].Severity < got.SeveritiesStats[j].Severity }) - diff := deep.Equal(got, tt.want) - if diff != nil { - t.Errorf("compare failed: %v", diff) - } + assert.Equal(t, got, tt.want) }) } } diff --git a/adapters/v1/domain_to_armo_test.go b/adapters/v1/domain_to_armo_test.go index 30cb6f9..c9de3b5 100644 --- a/adapters/v1/domain_to_armo_test.go +++ b/adapters/v1/domain_to_armo_test.go @@ -10,11 +10,11 @@ import ( "github.com/anchore/syft/syft/source" "github.com/armosec/armoapi-go/armotypes" "github.com/armosec/cluster-container-scanner-api/containerscan" - "github.com/go-test/deep" v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/uuid" "github.com/kubescape/kubevuln/core/domain" "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1" + "github.com/stretchr/testify/assert" ) func Test_domainToArmo(t *testing.T) { @@ -73,10 +73,7 @@ func Test_domainToArmo(t *testing.T) { } got[0].ContainerScanID = "" got[0].Timestamp = 0 - diff := deep.Equal(got, tt.want) - if diff != nil { - t.Errorf("compare failed: %v", diff) - } + assert.Equal(t, got, tt.want) }) } } @@ -133,10 +130,7 @@ func Test_parseLayersPayload(t *testing.T) { t.Errorf("parseLayersPayload() error = %v, wantErr %v", err, tt.wantErr) return } - diff := deep.Equal(got, tt.want) - if diff != nil { - t.Errorf("compare failed: %v", diff) - } + assert.Equal(t, got, tt.want) }) } } diff --git a/adapters/v1/domain_to_syft_test.go b/adapters/v1/domain_to_syft_test.go index 82c0052..453c5dc 100644 --- a/adapters/v1/domain_to_syft_test.go +++ b/adapters/v1/domain_to_syft_test.go @@ -3,10 +3,10 @@ package v1 import ( "testing" - "github.com/go-test/deep" "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1" "github.com/spdx/tools-golang/spdx/v2/common" "github.com/spdx/tools-golang/spdx/v2/v2_3" + "github.com/stretchr/testify/assert" ) func Test_domainToSpdx(t *testing.T) { @@ -77,10 +77,7 @@ func Test_domainToSpdx(t *testing.T) { t.Errorf("domainToSpdx() error = %v, wantErr %v", err, tt.wantErr) return } - diff := deep.Equal(got, tt.want) - if diff != nil { - t.Errorf("compare failed: %v", diff) - } + assert.Equal(t, got, tt.want) }) } } diff --git a/adapters/v1/grype_test.go b/adapters/v1/grype_test.go index 80429f0..dae1676 100644 --- a/adapters/v1/grype_test.go +++ b/adapters/v1/grype_test.go @@ -12,7 +12,7 @@ import ( "github.com/kubescape/kubevuln/core/domain" "github.com/kubescape/kubevuln/internal/tools" "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1" - "gotest.tools/v3/assert" + "github.com/stretchr/testify/assert" ) func Test_grypeAdapter_DBVersion(t *testing.T) { @@ -23,7 +23,7 @@ func Test_grypeAdapter_DBVersion(t *testing.T) { g := NewGrypeAdapterFixedDB() g.Ready(ctx) // need to call ready to load the DB version := g.DBVersion(ctx) - assert.Assert(t, version == "sha256:9be2df3d7d657bfb40ddcc68c9d00520ee7f5a34c7a26333f90cf89cefd5668a") + assert.Equal(t, version, "sha256:9be2df3d7d657bfb40ddcc68c9d00520ee7f5a34c7a26333f90cf89cefd5668a") } func fileToSBOM(path string) *v1beta1.Document { @@ -86,5 +86,5 @@ func Test_grypeAdapter_Version(t *testing.T) { ctx := context.TODO() g := NewGrypeAdapter() version := g.Version(ctx) - assert.Assert(t, version != "") + assert.NotEqual(t, version, "") } diff --git a/adapters/v1/grype_to_domain_test.go b/adapters/v1/grype_to_domain_test.go index 0d9afa7..c19c061 100644 --- a/adapters/v1/grype_to_domain_test.go +++ b/adapters/v1/grype_to_domain_test.go @@ -5,8 +5,8 @@ import ( "github.com/anchore/grype/grype/presenter/models" "github.com/anchore/syft/syft/source" - "github.com/go-test/deep" "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1" + "github.com/stretchr/testify/assert" ) func Test_grypeToDomain(t *testing.T) { @@ -65,10 +65,7 @@ func Test_grypeToDomain(t *testing.T) { t.Errorf("grypeToDomain() error = %v, wantErr %v", err, tt.wantErr) return } - diff := deep.Equal(got, tt.want) - if diff != nil { - t.Errorf("compare failed: %v", diff) - } + assert.Equal(t, got, tt.want) }) } } diff --git a/adapters/v1/syft_test.go b/adapters/v1/syft_test.go index 7e8bbbb..040ad79 100644 --- a/adapters/v1/syft_test.go +++ b/adapters/v1/syft_test.go @@ -7,12 +7,11 @@ import ( "testing" "time" - "github.com/go-test/deep" "github.com/kinbiko/jsonassert" "github.com/kubescape/k8s-interface/instanceidhandler/v1" "github.com/kubescape/kubevuln/core/domain" "github.com/kubescape/kubevuln/internal/tools" - "gotest.tools/v3/assert" + "github.com/stretchr/testify/assert" ) func fileContent(path string) []byte { @@ -96,7 +95,7 @@ func Test_syftAdapter_CreateSBOM(t *testing.T) { func Test_syftAdapter_Version(t *testing.T) { s := NewSyftAdapter(5*time.Minute, 512*1024*1024) version := s.Version() - assert.Assert(t, version != "") + assert.NotEqual(t, version, "") } func Test_syftAdapter_transformations(t *testing.T) { @@ -108,8 +107,5 @@ func Test_syftAdapter_transformations(t *testing.T) { s := NewSyftAdapter(5*time.Minute, 512*1024*1024) domainSBOM, err := s.spdxToDomain(spdxSBOM) tools.EnsureSetup(t, err == nil) - diff := deep.Equal(sbom.Content, domainSBOM) - if diff != nil { - t.Errorf("compare failed: %v", diff) - } + assert.Equal(t, sbom.Content, domainSBOM) } diff --git a/adapters/v1/syft_to_domain_test.go b/adapters/v1/syft_to_domain_test.go index b1b284c..85ebcc1 100644 --- a/adapters/v1/syft_to_domain_test.go +++ b/adapters/v1/syft_to_domain_test.go @@ -4,10 +4,10 @@ import ( "testing" "time" - "github.com/go-test/deep" "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1" "github.com/spdx/tools-golang/spdx/v2/common" "github.com/spdx/tools-golang/spdx/v2/v2_3" + "github.com/stretchr/testify/assert" ) func TestSyftAdapter_spdxToDomain(t *testing.T) { @@ -91,10 +91,7 @@ func TestSyftAdapter_spdxToDomain(t *testing.T) { t.Errorf("spdxToDomain() error = %v, wantErr %v", err, tt.wantErr) return } - diff := deep.Equal(got, tt.want) - if diff != nil { - t.Errorf("compare failed: %v", diff) - } + assert.Equal(t, got, tt.want) }) } } diff --git a/cmd/http/main_test.go b/cmd/http/main_test.go index bbf42f7..6aee08e 100644 --- a/cmd/http/main_test.go +++ b/cmd/http/main_test.go @@ -13,7 +13,7 @@ import ( "github.com/kubescape/kubevuln/core/services" "github.com/kubescape/kubevuln/internal/tools" "github.com/kubescape/kubevuln/repositories" - "gotest.tools/v3/assert" + "github.com/stretchr/testify/assert" ) func TestScan(t *testing.T) { @@ -117,8 +117,8 @@ func TestScan(t *testing.T) { w = httptest.NewRecorder() router.ServeHTTP(w, req) - assert.Assert(t, test.expectedCode == w.Code) - assert.Assert(t, test.expectedBody == w.Body.String(), w.Body.String()) + assert.Equal(t, test.expectedCode, w.Code, w.Code) + assert.Equal(t, test.expectedBody, w.Body.String(), w.Body.String()) controller.Shutdown() }) diff --git a/config/config_test.go b/config/config_test.go index f3c2d70..ff827be 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -4,17 +4,17 @@ import ( "testing" "github.com/spf13/viper" - "gotest.tools/v3/assert" + "github.com/stretchr/testify/assert" ) func TestLoadConfig(t *testing.T) { viper.Reset() _, err := LoadConfig("testdata") - assert.Assert(t, err == nil) + assert.NoError(t, err) } func TestLoadConfigNotFound(t *testing.T) { viper.Reset() _, err := LoadConfig("testdataInvalid") - assert.Assert(t, err != nil) + assert.Error(t, err) } diff --git a/controllers/http_test.go b/controllers/http_test.go index c738dbf..18f9a23 100644 --- a/controllers/http_test.go +++ b/controllers/http_test.go @@ -11,7 +11,7 @@ import ( "github.com/kubescape/kubevuln/core/ports" "github.com/kubescape/kubevuln/core/services" "github.com/kubescape/kubevuln/internal/tools" - "gotest.tools/v3/assert" + "github.com/stretchr/testify/assert" ) func TestHTTPController_Alive(t *testing.T) { @@ -22,8 +22,8 @@ func TestHTTPController_Alive(t *testing.T) { req, _ := http.NewRequest("GET", path, nil) w := httptest.NewRecorder() router.ServeHTTP(w, req) - assert.Assert(t, http.StatusOK == w.Code, w.Code) - assert.Assert(t, w.Body.String() == "{\"status\":200,\"title\":\"OK\"}", w.Body.String()) + assert.Equal(t, http.StatusOK, w.Code, w.Code) + assert.Equal(t, w.Body.String(), "{\"status\":200,\"title\":\"OK\"}", w.Body.String()) } func TestHTTPController_GenerateSBOM(t *testing.T) { @@ -70,8 +70,8 @@ func TestHTTPController_GenerateSBOM(t *testing.T) { req, _ := http.NewRequest("POST", path, file) w := httptest.NewRecorder() router.ServeHTTP(w, req) - assert.Assert(t, tt.expectedCode == w.Code, w.Code) - assert.Assert(t, tt.expectedBody == w.Body.String(), w.Body.String()) + assert.Equal(t, tt.expectedCode, w.Code, w.Code) + assert.Equal(t, tt.expectedBody, w.Body.String(), w.Body.String()) }) } } @@ -105,8 +105,8 @@ func TestHTTPController_Ready(t *testing.T) { req, _ := http.NewRequest("GET", path, nil) w := httptest.NewRecorder() router.ServeHTTP(w, req) - assert.Assert(t, tt.expectedCode == w.Code, w.Code) - assert.Assert(t, tt.expectedBody == w.Body.String(), w.Body.String()) + assert.Equal(t, tt.expectedCode, w.Code, w.Code) + assert.Equal(t, tt.expectedBody, w.Body.String(), w.Body.String()) }) } } @@ -155,8 +155,8 @@ func TestHTTPController_ScanCVE(t *testing.T) { req, _ := http.NewRequest("POST", path, file) w := httptest.NewRecorder() router.ServeHTTP(w, req) - assert.Assert(t, tt.expectedCode == w.Code, w.Code) - assert.Assert(t, tt.expectedBody == w.Body.String(), w.Body.String()) + assert.Equal(t, tt.expectedCode, w.Code, w.Code) + assert.Equal(t, tt.expectedBody, w.Body.String(), w.Body.String()) }) } } @@ -205,8 +205,8 @@ func TestHTTPController_ScanRegistry(t *testing.T) { req, _ := http.NewRequest("POST", path, file) w := httptest.NewRecorder() router.ServeHTTP(w, req) - assert.Assert(t, tt.expectedCode == w.Code, w.Code) - assert.Assert(t, tt.expectedBody == w.Body.String(), w.Body.String()) + assert.Equal(t, tt.expectedCode, w.Code, w.Code) + assert.Equal(t, tt.expectedBody, w.Body.String(), w.Body.String()) }) } } diff --git a/core/services/mockscan_test.go b/core/services/mockscan_test.go index 188e6d7..070ef03 100644 --- a/core/services/mockscan_test.go +++ b/core/services/mockscan_test.go @@ -4,8 +4,8 @@ import ( "context" "testing" - "github.com/go-test/deep" "github.com/kubescape/kubevuln/core/domain" + "github.com/stretchr/testify/assert" ) func TestMockScanService_GenerateSBOM(t *testing.T) { @@ -144,10 +144,7 @@ func TestMockScanService_ValidateGenerateSBOM(t *testing.T) { t.Errorf("ValidateGenerateSBOM() error = %v, wantErr %v", err, tt.wantErr) return } - diff := deep.Equal(got, tt.want) - if diff != nil { - t.Errorf("compare failed: %v", diff) - } + assert.Equal(t, got, tt.want) }) } } @@ -186,10 +183,7 @@ func TestMockScanService_ValidateScanCVE(t *testing.T) { t.Errorf("ValidateScanCVE() error = %v, wantErr %v", err, tt.wantErr) return } - diff := deep.Equal(got, tt.want) - if diff != nil { - t.Errorf("compare failed: %v", diff) - } + assert.Equal(t, got, tt.want) }) } } diff --git a/core/services/scan_test.go b/core/services/scan_test.go index 16dca5c..1ae9f05 100644 --- a/core/services/scan_test.go +++ b/core/services/scan_test.go @@ -14,7 +14,7 @@ import ( "github.com/kubescape/kubevuln/internal/tools" "github.com/kubescape/kubevuln/repositories" "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1" - "gotest.tools/v3/assert" + "github.com/stretchr/testify/assert" ) func TestScanService_GenerateSBOM(t *testing.T) { @@ -256,7 +256,7 @@ func TestScanService_ScanCVE(t *testing.T) { if tt.wantCvep { cvep, err := storageCVE.GetCVE(ctx, sbomp.ID, sbomAdapter.Version(), cveAdapter.Version(ctx), cveAdapter.DBVersion(ctx)) tools.EnsureSetup(t, err == nil) - assert.Assert(t, cvep.Labels != nil) + assert.NotNil(t, cvep.Labels) } }) } @@ -313,7 +313,7 @@ func TestScanService_NginxTest(t *testing.T) { tools.EnsureSetup(t, err == nil) cvep, err := storageCVE.GetCVE(ctx, sbomp.ID, sbomAdapter.Version(), cveAdapter.Version(ctx), cveAdapter.DBVersion(ctx)) tools.EnsureSetup(t, err == nil) - assert.Assert(t, cvep.Content != nil) + assert.NotNil(t, cvep.Content) } func TestScanService_ValidateGenerateSBOM(t *testing.T) { @@ -459,7 +459,7 @@ func TestScanService_ScanRegistry(t *testing.T) { tools.EnsureSetup(t, err == nil) } if err := s.ScanRegistry(ctx); (err != nil) != tt.wantErr { - t.Errorf("GenerateSBOM() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ScanRegistry() error = %v, wantErr %v", err, tt.wantErr) } }) } @@ -494,7 +494,7 @@ func TestScanService_ValidateScanRegistry(t *testing.T) { false) _, err := s.ValidateScanRegistry(context.TODO(), tt.workload) if (err != nil) != tt.wantErr { - t.Errorf("ValidateScanCVE() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ValidateScanRegistry() error = %v, wantErr %v", err, tt.wantErr) return } }) diff --git a/go.mod b/go.mod index 5353199..070ad73 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,6 @@ require ( github.com/eapache/go-resiliency v1.3.0 github.com/gammazero/workerpool v1.1.3 github.com/gin-gonic/gin v1.9.0 - github.com/go-test/deep v1.1.0 github.com/google/go-containerregistry v0.14.0 github.com/google/uuid v1.3.0 github.com/hashicorp/go-multierror v1.1.1 @@ -28,10 +27,10 @@ require ( github.com/kubescape/storage v0.2.0 github.com/spdx/tools-golang v0.5.0-rc1 github.com/spf13/viper v1.15.0 + github.com/stretchr/testify v1.8.2 go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.40.0 go.opentelemetry.io/otel v1.14.0 go.opentelemetry.io/otel/trace v1.14.0 - gotest.tools/v3 v3.4.0 k8s.io/apimachinery v0.26.3 k8s.io/client-go v0.26.3 k8s.io/utils v0.0.0-20230202215443-34013725500c @@ -95,6 +94,7 @@ require ( github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.11.2 // indirect github.com/go-restruct/restruct v1.2.0-alpha // indirect + github.com/go-test/deep v1.1.0 // indirect github.com/goccy/go-json v0.10.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/glog v1.0.0 // indirect @@ -156,6 +156,7 @@ require ( github.com/pelletier/go-toml/v2 v2.0.6 // indirect github.com/pierrec/lz4/v4 v4.1.15 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pquerna/cachecontrol v0.1.0 // indirect github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect github.com/rivo/uniseg v0.2.0 // indirect diff --git a/go.sum b/go.sum index 5300168..265d94e 100644 --- a/go.sum +++ b/go.sum @@ -898,6 +898,7 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stripe/stripe-go/v74 v74.8.0 h1:0+3EfQSBhMg8SQ1+w+AP6Gxyko2crWbUG2uXbzYs8SU= github.com/stripe/stripe-go/v74 v74.8.0/go.mod h1:5PoXNp30AJ3tGq57ZcFuaMylzNi8KpwlrYAFmO1fHZw= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= @@ -1639,7 +1640,6 @@ gorm.io/gorm v1.23.10 h1:4Ne9ZbzID9GUxRkllxN4WjJKpsHx8YbKvekVdgyWh24= gorm.io/gorm v1.23.10/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA= gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= -gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g= grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/internal/tools/tools.go b/internal/tools/tools.go index bcadd2a..f117d5b 100644 --- a/internal/tools/tools.go +++ b/internal/tools/tools.go @@ -8,12 +8,12 @@ import ( "github.com/aquilax/truncate" "github.com/distribution/distribution/reference" "github.com/kubescape/k8s-interface/instanceidhandler/v1" - "gotest.tools/v3/assert" + "github.com/stretchr/testify/assert" "k8s.io/apimachinery/pkg/util/validation" ) func EnsureSetup(t *testing.T, errored bool) { - assert.Assert(t, errored, "Error during test setup") + assert.True(t, errored, "Error during test setup") } func PackageVersion(name string) string { diff --git a/internal/tools/tools_test.go b/internal/tools/tools_test.go index 2b0f302..47cad2f 100644 --- a/internal/tools/tools_test.go +++ b/internal/tools/tools_test.go @@ -3,9 +3,8 @@ package tools import ( "testing" - "github.com/go-test/deep" "github.com/kubescape/k8s-interface/instanceidhandler/v1" - "gotest.tools/v3/assert" + "github.com/stretchr/testify/assert" ) func TestEnsureSetup(t *testing.T) { @@ -13,7 +12,7 @@ func TestEnsureSetup(t *testing.T) { } func TestPackageVersion(t *testing.T) { - assert.Assert(t, PackageVersion("github.com/anchore/syft") == "unknown") // only works on compiled binaries + assert.True(t, PackageVersion("github.com/anchore/syft") == "unknown") // only works on compiled binaries } func TestLabelsFromImageID(t *testing.T) { @@ -45,10 +44,7 @@ func TestLabelsFromImageID(t *testing.T) { for _, tt := range tests { t.Run(tt.imageID, func(t *testing.T) { got := LabelsFromImageID(tt.imageID) - diff := deep.Equal(got, tt.want) - if diff != nil { - t.Errorf("compare failed: %v", diff) - } + assert.Equal(t, got, tt.want) }) } } diff --git a/repositories/apiserver_test.go b/repositories/apiserver_test.go index 7cccf56..8783817 100644 --- a/repositories/apiserver_test.go +++ b/repositories/apiserver_test.go @@ -9,7 +9,7 @@ import ( "github.com/kubescape/kubevuln/core/domain" "github.com/kubescape/kubevuln/internal/tools" "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1" - "gotest.tools/v3/assert" + "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -136,10 +136,10 @@ func TestAPIServerStore_UpdateCVE(t *testing.T) { tools.EnsureSetup(t, err == nil) cvep.Content.Descriptor.Version = "v1.1.0" err = a.StoreCVE(ctx, cvep, true) - assert.Assert(t, err == nil) + assert.NoError(t, err) got, err := a.GetCVE(ctx, instanceID, "", "", "") tools.EnsureSetup(t, err == nil) - assert.Assert(t, got.Content.Descriptor.Version == "v1.1.0") + assert.Equal(t, got.Content.Descriptor.Version, "v1.1.0") } func TestAPIServerStore_GetSBOM(t *testing.T) { diff --git a/repositories/broken_test.go b/repositories/broken_test.go index 33ba865..35bfd93 100644 --- a/repositories/broken_test.go +++ b/repositories/broken_test.go @@ -5,35 +5,35 @@ import ( "testing" "github.com/kubescape/kubevuln/core/domain" - "gotest.tools/v3/assert" + "github.com/stretchr/testify/assert" ) func TestBrokenStore_GetCVE(t *testing.T) { b := NewBrokenStorage() _, err := b.GetCVE(context.TODO(), "", "", "", "") - assert.Assert(t, err != nil) + assert.Error(t, err) } func TestBrokenStore_GetSBOM(t *testing.T) { b := NewBrokenStorage() _, err := b.GetSBOM(context.TODO(), "", "") - assert.Assert(t, err != nil) + assert.Error(t, err) } func TestBrokenStore_GetSBOMp(t *testing.T) { b := NewBrokenStorage() _, err := b.GetSBOMp(context.TODO(), "", "") - assert.Assert(t, err != nil) + assert.Error(t, err) } func TestBrokenStore_StoreCVE(t *testing.T) { b := NewBrokenStorage() err := b.StoreCVE(context.TODO(), domain.CVEManifest{}, false) - assert.Assert(t, err != nil) + assert.Error(t, err) } func TestBrokenStore_StoreSBOM(t *testing.T) { b := NewBrokenStorage() err := b.StoreSBOM(context.TODO(), domain.SBOM{}) - assert.Assert(t, err != nil) + assert.Error(t, err) } diff --git a/repositories/memory_test.go b/repositories/memory_test.go index 301ecde..bee1b2d 100644 --- a/repositories/memory_test.go +++ b/repositories/memory_test.go @@ -6,14 +6,14 @@ import ( "github.com/kubescape/kubevuln/core/domain" "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1" - "gotest.tools/v3/assert" + "github.com/stretchr/testify/assert" ) func TestMemoryStore_GetCVE(t *testing.T) { m := NewMemoryStorage(false, false) ctx := context.TODO() got, _ := m.GetCVE(ctx, "imageID", "", "", "") - assert.Assert(t, got.Content == nil) + assert.Nil(t, got.Content) cve := domain.CVEManifest{ ID: "imageID", SBOMCreatorVersion: "", @@ -23,16 +23,16 @@ func TestMemoryStore_GetCVE(t *testing.T) { } _ = m.StoreCVE(ctx, cve, false) got, _ = m.GetCVE(ctx, "imageID", "", "", "") - assert.Assert(t, got.Content != nil) + assert.NotNil(t, got.Content) } func TestMemoryStore_GetSBOM(t *testing.T) { m := NewMemoryStorage(false, false) ctx := context.TODO() got, _ := m.GetSBOM(ctx, "imageID", "") - assert.Assert(t, got.Content == nil) + assert.Nil(t, got.Content) got, _ = m.GetSBOMp(ctx, "imageID", "") - assert.Assert(t, got.Content == nil) + assert.Nil(t, got.Content) sbom := domain.SBOM{ ID: "imageID", SBOMCreatorVersion: "", @@ -41,7 +41,7 @@ func TestMemoryStore_GetSBOM(t *testing.T) { } _ = m.StoreSBOM(ctx, sbom) got, _ = m.GetSBOM(ctx, "imageID", "") - assert.Assert(t, got.Content != nil) + assert.NotNil(t, got.Content) got, _ = m.GetSBOMp(ctx, "imageID", "") - assert.Assert(t, got.Content != nil) + assert.NotNil(t, got.Content) }