|
1 | 1 | // Copyright 2023 D2iQ, Inc. All rights reserved.
|
2 | 2 | // SPDX-License-Identifier: Apache-2.0
|
3 | 3 |
|
4 |
| -package tests |
| 4 | +package calico |
5 | 5 |
|
6 | 6 | import (
|
7 | 7 | "testing"
|
8 | 8 |
|
| 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" |
9 | 11 | "github.com/onsi/gomega"
|
10 |
| - "github.com/onsi/gomega/format" |
| 12 | + |
11 | 13 | runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
|
12 | 14 |
|
13 |
| - capav1 "github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" |
14 | 15 | "github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
|
15 | 16 | "github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
|
16 | 17 | "github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
|
17 | 18 | "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" |
18 | 20 | )
|
19 | 21 |
|
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 | +} |
27 | 26 |
|
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 | + } |
30 | 31 |
|
31 |
| - capitest.ValidateGeneratePatches( |
32 |
| - t, |
33 |
| - generatorFunc, |
34 |
| - capitest.PatchTestDef{ |
| 32 | + testDefs := []capitest.PatchTestDef{ |
| 33 | + { |
35 | 34 | Name: "unset variable",
|
36 | 35 | },
|
37 |
| - capitest.PatchTestDef{ |
| 36 | + { |
38 | 37 | Name: "provider set with AWSClusterTemplate",
|
39 | 38 | Vars: []runtimehooksv1.Variable{
|
40 | 39 | capitest.VariableWithValue(
|
41 |
| - variableName, |
| 40 | + clusterconfig.MetaVariableName, |
42 | 41 | v1alpha1.CNI{
|
43 | 42 | Provider: v1alpha1.CNIProviderCalico,
|
44 | 43 | },
|
45 |
| - variablePath..., |
| 44 | + "addons", |
| 45 | + v1alpha1.CNIVariableName, |
46 | 46 | ),
|
47 | 47 | },
|
48 | 48 | RequestItem: request.NewAWSClusterTemplateRequestItem("1234"),
|
@@ -101,15 +101,16 @@ func TestGeneratePatches(
|
101 | 101 | ),
|
102 | 102 | }},
|
103 | 103 | },
|
104 |
| - capitest.PatchTestDef{ |
| 104 | + { |
105 | 105 | Name: "provider set with AWSClusterTemplate pre-existing rules",
|
106 | 106 | Vars: []runtimehooksv1.Variable{
|
107 | 107 | capitest.VariableWithValue(
|
108 |
| - variableName, |
| 108 | + clusterconfig.MetaVariableName, |
109 | 109 | v1alpha1.CNI{
|
110 | 110 | Provider: v1alpha1.CNIProviderCalico,
|
111 | 111 | },
|
112 |
| - variablePath..., |
| 112 | + "addons", |
| 113 | + v1alpha1.CNIVariableName, |
113 | 114 | ),
|
114 | 115 | },
|
115 | 116 | RequestItem: request.NewAWSClusterTemplateRequestItem(
|
@@ -193,15 +194,16 @@ func TestGeneratePatches(
|
193 | 194 | ),
|
194 | 195 | }},
|
195 | 196 | },
|
196 |
| - capitest.PatchTestDef{ |
| 197 | + { |
197 | 198 | Name: "provider set with AWSClusterTemplate conflicting pre-existing rules",
|
198 | 199 | Vars: []runtimehooksv1.Variable{
|
199 | 200 | capitest.VariableWithValue(
|
200 |
| - variableName, |
| 201 | + clusterconfig.MetaVariableName, |
201 | 202 | v1alpha1.CNI{
|
202 | 203 | Provider: v1alpha1.CNIProviderCalico,
|
203 | 204 | },
|
204 |
| - variablePath..., |
| 205 | + "addons", |
| 206 | + v1alpha1.CNIVariableName, |
205 | 207 | ),
|
206 | 208 | },
|
207 | 209 | RequestItem: request.NewAWSClusterTemplateRequestItem(
|
@@ -273,5 +275,17 @@ func TestGeneratePatches(
|
273 | 275 | ),
|
274 | 276 | }},
|
275 | 277 | },
|
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 | +}) |
0 commit comments