Skip to content

Commit

Permalink
Avoid using require.Contains, since it fails when capacities are not …
Browse files Browse the repository at this point in the history
…equal.
  • Loading branch information
tanyaveksler committed Oct 29, 2024
1 parent 50fefb5 commit a19be86
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions pkg/netpol/connlist/exposure_analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,41 @@ func checkExpectedVsActualData(t *testing.T, testName string, actualExp ExposedP
"test: %q, mismatch in is egress protected for peer %q", testName, actualExp.ExposedPeer().String())
require.Equal(t, expectedData.isIngressProtected, actualExp.IsProtectedByIngressNetpols(),
"test: %q, mismatch in is ingress protected for peer %q", testName, actualExp.ExposedPeer().String())
require.Equal(t, expectedData.lenIngressExposedConns, len(actualExp.IngressExposure()),
ingressExposure := actualExp.IngressExposure()
require.Equal(t, expectedData.lenIngressExposedConns, len(ingressExposure),
"test: %q, mismatch in length of ingress exposure slice for peer %q", testName, actualExp.ExposedPeer().String())
for i := range expectedData.ingressExp {
require.Contains(t, actualExp.IngressExposure(), expectedData.ingressExp[i],
require.True(t, checkXgressExposureContainment(ingressExposure, expectedData.ingressExp[i]),
"test: %q, expected ingress data %v is not contained in actual results", testName, expectedData.ingressExp[i])
}
require.Equal(t, expectedData.lenEgressExposedConns, len(actualExp.EgressExposure()),
egressExposure := actualExp.EgressExposure()
require.Equal(t, expectedData.lenEgressExposedConns, len(egressExposure),
"test: %q, mismatch in length of egress exposure slice for peer %q", testName, actualExp.ExposedPeer().String())
for i := range expectedData.egressExp {
require.Contains(t, actualExp.EgressExposure(), expectedData.egressExp[i],
require.True(t, checkXgressExposureContainment(egressExposure, expectedData.egressExp[i]),
"test: %q, expected egress data %v is not contained in actual results", testName, expectedData.egressExp[i])
}
}

func checkXgressExposureContainment(actualArray []XgressExposureData, expectedItem *xgressExposure) bool {
for i := range actualArray {
currItem := actualArray[i].(*xgressExposure)
if currItem.IsExposedToEntireCluster() != expectedItem.IsExposedToEntireCluster() {
continue
}
if !currItem.IsExposedToEntireCluster() {
if currItem.namespaceLabels.String() != expectedItem.namespaceLabels.String() {
continue
}
if currItem.podLabels.String() != expectedItem.podLabels.String() {
continue
}
}
v1 := expectedItem.PotentialConnectivity().(*common.ConnectionSet)

Check failure on line 370 in pkg/netpol/connlist/exposure_analysis_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

importShadow: shadow of imported from 'k8s.io/api/core/v1' package 'v1' (gocritic)
v2 := currItem.PotentialConnectivity().(*common.ConnectionSet)
if v1.Equal(v2) {
return true
}
}
return false
}

0 comments on commit a19be86

Please sign in to comment.