Skip to content

Commit

Permalink
assert: Replace checker by assert package
Browse files Browse the repository at this point in the history
Signed-off-by: Tam Mach <tam.mach@cilium.io>
  • Loading branch information
sayboras committed May 14, 2024
1 parent 9322bc8 commit c43b47c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
15 changes: 4 additions & 11 deletions pkg/api/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"testing"

"github.com/go-openapi/spec"

"github.com/cilium/cilium/pkg/checker"
"github.com/stretchr/testify/require"
)

func TestParseSpecPaths(t *testing.T) {
Expand Down Expand Up @@ -110,9 +109,7 @@ func TestParseSpecPaths(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := parseSpecPaths(tc.paths)
if ok, msg := checker.DeepEqual(got, tc.expected); !ok {
t.Errorf("case %q failed:\n%s", tc.name, msg)
}
require.Equalf(t, tc.expected, got, "case %q failed", tc.name)
})
}
}
Expand Down Expand Up @@ -179,12 +176,8 @@ func TestAllowedFlagsToDeniedPaths(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got, err := generateDeniedAPIEndpoints(sampleFlags, tc.allowed)
if ok, msg := checker.DeepEqual(got, tc.expected); !ok {
t.Errorf("case %q failed:\n%s", tc.name, msg)
}
if ok, msg := checker.DeepEqual(errors.Unwrap(err), tc.expectedErr); !ok {
t.Errorf("case %q error mismatch:\n%s", tc.name, msg)
}
require.Equalf(t, tc.expected, got, "case %q failed", tc.name)
require.Equalf(t, tc.expectedErr, errors.Unwrap(err), "case %q failed", tc.name)
})
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/hubble/parser/sock/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (

"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

flowpb "github.com/cilium/cilium/api/v1/flow"
"github.com/cilium/cilium/pkg/byteorder"
cgroupManager "github.com/cilium/cilium/pkg/cgroups/manager"
"github.com/cilium/cilium/pkg/checker"
parserErrors "github.com/cilium/cilium/pkg/hubble/parser/errors"
"github.com/cilium/cilium/pkg/hubble/parser/getters"
"github.com/cilium/cilium/pkg/hubble/testutils"
Expand Down Expand Up @@ -418,8 +418,7 @@ func TestDecodeSockEvent(t *testing.T) {
assert.ErrorContains(t, err, tc.errMsg)
} else {
assert.Nil(t, err)
ok, msg := checker.DeepEqual(flow, tc.flow)
assert.True(t, ok, msg)
require.EqualValues(t, tc.flow, flow)
}
})
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/policy/mapstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/cilium/cilium/pkg/checker"
"github.com/cilium/cilium/pkg/identity"
"github.com/cilium/cilium/pkg/identity/cache"
"github.com/cilium/cilium/pkg/labels"
Expand Down Expand Up @@ -2013,7 +2012,7 @@ func TestMapState_AddVisibilityKeys(t *testing.T) {
}
tt.ms.ForEach(func(k Key, v MapStateEntry) bool {
if v2, ok := old.Old[k]; ok {
if equals, _ := checker.DeepEqual(v2, v); !equals {
if !assert.ObjectsAreEqual(v2, v) {
if !v.DatapathEqual(&v2) {
wantAdds[k] = struct{}{}
}
Expand Down
11 changes: 6 additions & 5 deletions test/runtime/fqdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"time"

. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"

"github.com/cilium/cilium/api/v1/models"
"github.com/cilium/cilium/pkg/checker"
. "github.com/cilium/cilium/test/ginkgo-ext"
"github.com/cilium/cilium/test/helpers"
"github.com/cilium/cilium/test/helpers/constants"
Expand Down Expand Up @@ -1125,8 +1125,8 @@ var _ = Describe("RuntimeAgentFQDNPolicies", func() {
ipcacheAfter, err := vm.BpfIPCacheList(true)
Expect(err).To(BeNil(), "ipcache can not be dumped")
GinkgoPrint(fmt.Sprintf("Local scope identities in IP cache after Cilium restart: %v", ipcacheAfter))
equal, diff := checker.DeepEqual(ipcacheBefore, ipcacheAfter)
Expect(equal).To(BeTrue(), "CIDR identities were not restored correctly: %s", diff)
equal := assert.ObjectsAreEqualValues(ipcacheBefore, ipcacheAfter)
Expect(equal).To(BeTrue(), "CIDR identities were not restored correctly")

// Reapply FQDN policy and check that selectors still have same ids
_, err = vm.PolicyRenderAndImport(policy)
Expand All @@ -1141,8 +1141,9 @@ var _ = Describe("RuntimeAgentFQDNPolicies", func() {
By("Dumping IP cache after the DNS policy is imported after restart")
ipcacheAfterDNSPolicy, err := vm.BpfIPCacheList(true)
Expect(err).To(BeNil(), "ipcache can not be dumped")
equal, diff = checker.DeepEqual(ipcacheBefore, ipcacheAfterDNSPolicy)
Expect(equal).To(BeTrue(), "CIDR identities changed after policy import: %s", diff)
equal = assert.ObjectsAreEqualValues(ipcacheBefore, ipcacheAfterDNSPolicy)
Expect(equal).To(BeTrue(), "CIDR identities changed after policy import")

GinkgoPrint(fmt.Sprintf("Local scope identities in IP cache after re-import of DNS policy: %v", ipcacheAfterDNSPolicy))

})
Expand Down

0 comments on commit c43b47c

Please sign in to comment.