Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit d9eec88

Browse files
committed
test: move aws cni unit tests to its own package
1 parent a268b65 commit d9eec88

File tree

2 files changed

+41
-38
lines changed

2 files changed

+41
-38
lines changed

pkg/handlers/aws/mutation/cni/calico/tests/generate_patches.go renamed to pkg/handlers/aws/mutation/cni/calico/inject_test.go

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
// Copyright 2023 D2iQ, Inc. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package tests
4+
package calico
55

66
import (
77
"testing"
88

9+
capav1 "github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
10+
. "github.com/onsi/ginkgo/v2"
911
"github.com/onsi/gomega"
10-
"github.com/onsi/gomega/format"
12+
1113
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
1214

13-
capav1 "github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
1415
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
1516
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
1617
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
1718
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
19+
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig"
1820
)
1921

20-
func TestGeneratePatches(
21-
t *testing.T,
22-
generatorFunc func() mutation.GeneratePatches,
23-
variableName string,
24-
variablePath ...string,
25-
) {
26-
t.Helper()
22+
func TestCalicoPatch(t *testing.T) {
23+
gomega.RegisterFailHandler(Fail)
24+
RunSpecs(t, "AWS Calico CNI ingress mutator suite")
25+
}
2726

28-
format.MaxLength = 0
29-
format.TruncatedDiff = false
27+
var _ = Describe("Generate AWS Calico CNI ingress patches", func() {
28+
patchGenerator := func() mutation.GeneratePatches {
29+
return mutation.NewMetaGeneratePatchesHandler("", NewPatch()).(mutation.GeneratePatches)
30+
}
3031

31-
capitest.ValidateGeneratePatches(
32-
t,
33-
generatorFunc,
34-
capitest.PatchTestDef{
32+
testDefs := []capitest.PatchTestDef{
33+
{
3534
Name: "unset variable",
3635
},
37-
capitest.PatchTestDef{
36+
{
3837
Name: "provider set with AWSClusterTemplate",
3938
Vars: []runtimehooksv1.Variable{
4039
capitest.VariableWithValue(
41-
variableName,
40+
clusterconfig.MetaVariableName,
4241
v1alpha1.CNI{
4342
Provider: v1alpha1.CNIProviderCalico,
4443
},
45-
variablePath...,
44+
"addons",
45+
v1alpha1.CNIVariableName,
4646
),
4747
},
4848
RequestItem: request.NewAWSClusterTemplateRequestItem("1234"),
@@ -101,15 +101,16 @@ func TestGeneratePatches(
101101
),
102102
}},
103103
},
104-
capitest.PatchTestDef{
104+
{
105105
Name: "provider set with AWSClusterTemplate pre-existing rules",
106106
Vars: []runtimehooksv1.Variable{
107107
capitest.VariableWithValue(
108-
variableName,
108+
clusterconfig.MetaVariableName,
109109
v1alpha1.CNI{
110110
Provider: v1alpha1.CNIProviderCalico,
111111
},
112-
variablePath...,
112+
"addons",
113+
v1alpha1.CNIVariableName,
113114
),
114115
},
115116
RequestItem: request.NewAWSClusterTemplateRequestItem(
@@ -193,15 +194,16 @@ func TestGeneratePatches(
193194
),
194195
}},
195196
},
196-
capitest.PatchTestDef{
197+
{
197198
Name: "provider set with AWSClusterTemplate conflicting pre-existing rules",
198199
Vars: []runtimehooksv1.Variable{
199200
capitest.VariableWithValue(
200-
variableName,
201+
clusterconfig.MetaVariableName,
201202
v1alpha1.CNI{
202203
Provider: v1alpha1.CNIProviderCalico,
203204
},
204-
variablePath...,
205+
"addons",
206+
v1alpha1.CNIVariableName,
205207
),
206208
},
207209
RequestItem: request.NewAWSClusterTemplateRequestItem(
@@ -273,5 +275,17 @@ func TestGeneratePatches(
273275
),
274276
}},
275277
},
276-
)
277-
}
278+
}
279+
280+
// create test node for each case
281+
for testIdx := range testDefs {
282+
tt := testDefs[testIdx]
283+
It(tt.Name, func() {
284+
capitest.AssertGeneratePatches(
285+
GinkgoT(),
286+
patchGenerator,
287+
&tt,
288+
)
289+
})
290+
}
291+
})

pkg/handlers/aws/mutation/metapatch_handler_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ import (
88

99
"sigs.k8s.io/controller-runtime/pkg/manager"
1010

11-
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
1211
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
1312

14-
calicotests "github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/mutation/cni/calico/tests"
15-
1613
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig"
1714
auditpolicytests "github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/mutation/auditpolicy/tests"
1815
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/mutation/etcd"
@@ -46,14 +43,6 @@ func TestGeneratePatches(t *testing.T) {
4643

4744
mgr := testEnv.Manager
4845

49-
calicotests.TestGeneratePatches(
50-
t,
51-
metaPatchGeneratorFunc(mgr),
52-
clusterconfig.MetaVariableName,
53-
"addons",
54-
v1alpha1.CNIVariableName,
55-
)
56-
5746
auditpolicytests.TestGeneratePatches(
5847
t,
5948
metaPatchGeneratorFunc(mgr),

0 commit comments

Comments
 (0)