Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use stretchr/testify instead of gotest #110

Merged
merged 2 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions adapters/mockcve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
8 changes: 4 additions & 4 deletions adapters/mockplatform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ 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) {
m := NewMockPlatform()
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)
}
10 changes: 5 additions & 5 deletions adapters/mocksbom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
17 changes: 4 additions & 13 deletions adapters/v1/armo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})
}
}
Expand Down Expand Up @@ -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)
})
}
}
Expand Down Expand Up @@ -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)
},
}
Expand Down
12 changes: 3 additions & 9 deletions adapters/v1/armo_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
})
}
}
Expand Down Expand Up @@ -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)
})
}
}
12 changes: 3 additions & 9 deletions adapters/v1/domain_to_armo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})
}
}
Expand Down Expand Up @@ -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)
})
}
}
7 changes: 2 additions & 5 deletions adapters/v1/domain_to_syft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})
}
}
6 changes: 3 additions & 3 deletions adapters/v1/grype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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, "")
}
7 changes: 2 additions & 5 deletions adapters/v1/grype_to_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})
}
}
10 changes: 3 additions & 7 deletions adapters/v1/syft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
}
7 changes: 2 additions & 5 deletions adapters/v1/syft_to_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})
}
}
6 changes: 3 additions & 3 deletions cmd/http/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
})
Expand Down
6 changes: 3 additions & 3 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Loading
Loading