Skip to content

Commit 9d2ef05

Browse files
committed
updated unit test
1 parent 725d6ca commit 9d2ef05

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

cns/middlewares/k8sSwiftV2_windows_test.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import (
55
"reflect"
66
"testing"
77

8-
"github.com/Azure/azure-container-networking/cni"
98
"github.com/Azure/azure-container-networking/cns"
109
"github.com/Azure/azure-container-networking/cns/middlewares/mock"
11-
acn "github.com/Azure/azure-container-networking/common"
1210
"github.com/Azure/azure-container-networking/crd/multitenancy/api/v1alpha1"
11+
"github.com/Azure/azure-container-networking/network/policy"
1312
"github.com/stretchr/testify/require"
1413
"gotest.tools/v3/assert"
1514
)
@@ -120,14 +119,14 @@ func TestAddDefaultDenyACL(t *testing.T) {
120119
"Priority": 10000
121120
}`)
122121

123-
expectedDefaultDenyACL := []cni.KVPair{
122+
expectedDefaultDenyACL := []policy.Policy{
124123
{
125-
Name: "EndpointPolicy",
126-
Value: valueOut,
124+
Type: policy.ACLPolicy,
125+
Data: valueOut,
127126
},
128127
{
129-
Name: "EndpointPolicy",
130-
Value: valueIn,
128+
Type: policy.ACLPolicy,
129+
Data: valueIn,
131130
},
132131
}
133132

@@ -145,30 +144,30 @@ func TestAddDefaultDenyACL(t *testing.T) {
145144

146145
// Normalize both slices so there is no extra spacing, new lines, etc
147146
normalizedExpected := normalizeKVPairs(t, expectedDefaultDenyACL)
148-
normalizedActual := normalizeKVPairs(t, podIPInfo.DefaultDenyACL)
147+
normalizedActual := normalizeKVPairs(t, podIPInfo.EndpointPolicies)
149148
if !reflect.DeepEqual(normalizedExpected, normalizedActual) {
150-
t.Errorf("got '%+v', expected '%+v'", podIPInfo.DefaultDenyACL, expectedDefaultDenyACL)
149+
t.Errorf("got '%+v', expected '%+v'", podIPInfo.EndpointPolicies, expectedDefaultDenyACL)
151150
}
152151
}
153152

154153
// normalizeKVPairs normalizes the JSON values in the KV pairs by unmarshaling them into a map, then marshaling them back to compact JSON to remove any extra space, new lines, etc
155-
func normalizeKVPairs(t *testing.T, kvPairs []acn.KVPair) []cni.KVPair {
156-
normalized := make([]cni.KVPair, len(kvPairs))
154+
func normalizeKVPairs(t *testing.T, kvPairs []policy.Policy) []policy.Policy {
155+
normalized := make([]policy.Policy, len(kvPairs))
157156

158157
for i, kv := range kvPairs {
159158
var unmarshaledValue map[string]interface{}
160159
// Unmarshal the Value into a map
161-
err := json.Unmarshal(kv.Value, &unmarshaledValue)
160+
err := json.Unmarshal(kv.Data, &unmarshaledValue)
162161
require.NoError(t, err, "Failed to unmarshal JSON value")
163162

164163
// Marshal it back to compact JSON
165164
normalizedValue, err := json.Marshal(unmarshaledValue)
166165
require.NoError(t, err, "Failed to re-marshal JSON value")
167166

168167
// Replace Value with the normalized compact JSON
169-
normalized[i] = acn.KVPair{
170-
Name: kv.Name,
171-
Value: normalizedValue,
168+
normalized[i] = policy.Policy{
169+
Type: policy.ACLPolicy,
170+
Data: normalizedValue,
172171
}
173172
}
174173

0 commit comments

Comments
 (0)