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

Commit f53e530

Browse files
committed
test: move aws network tests to its own package
1 parent 65e6709 commit f53e530

File tree

1 file changed

+41
-23
lines changed

1 file changed

+41
-23
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,49 @@
11
// Copyright 2023 D2iQ, Inc. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package tests
4+
package network
55

66
import (
77
"testing"
88

9+
. "github.com/onsi/ginkgo/v2"
910
"github.com/onsi/gomega"
11+
. "github.com/onsi/gomega"
1012
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
1113

1214
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
1315
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
1416
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
1517
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
18+
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig"
1619
)
1720

18-
func TestGeneratePatches(
19-
t *testing.T,
20-
generatorFunc func() mutation.GeneratePatches,
21-
variableName string,
22-
variablePath ...string,
23-
) {
24-
t.Helper()
21+
func TestNetworkPatch(t *testing.T) {
22+
RegisterFailHandler(Fail)
23+
RunSpecs(t, "AWS Network mutator suite")
24+
}
25+
26+
var _ = Describe("Generate AWS Network patches", func() {
27+
patchGenerator := func() mutation.GeneratePatches {
28+
return mutation.NewMetaGeneratePatchesHandler("", NewPatch()).(mutation.GeneratePatches)
29+
}
2530

26-
capitest.ValidateGeneratePatches(
27-
t,
28-
generatorFunc,
29-
capitest.PatchTestDef{
31+
testDefs := []capitest.PatchTestDef{
32+
{
3033
Name: "unset variable",
3134
},
32-
capitest.PatchTestDef{
35+
{
3336
Name: "VPC ID set",
3437
Vars: []runtimehooksv1.Variable{
3538
capitest.VariableWithValue(
36-
variableName,
39+
clusterconfig.MetaVariableName,
3740
v1alpha1.AWSNetwork{
3841
VPC: &v1alpha1.VPC{
3942
ID: "vpc-1234",
4043
},
4144
},
42-
variablePath...,
45+
v1alpha1.AWSVariableName,
46+
VariableName,
4347
),
4448
},
4549
RequestItem: request.NewAWSClusterTemplateRequestItem("1234"),
@@ -49,19 +53,20 @@ func TestGeneratePatches(
4953
ValueMatcher: gomega.Equal("vpc-1234"),
5054
}},
5155
},
52-
capitest.PatchTestDef{
56+
{
5357
Name: "Subnet IDs set",
5458
Vars: []runtimehooksv1.Variable{
5559
capitest.VariableWithValue(
56-
variableName,
60+
clusterconfig.MetaVariableName,
5761
v1alpha1.AWSNetwork{
5862
Subnets: v1alpha1.Subnets{
5963
{ID: "subnet-1"},
6064
{ID: "subnet-2"},
6165
{ID: "subnet-3"},
6266
},
6367
},
64-
variablePath...,
68+
v1alpha1.AWSVariableName,
69+
VariableName,
6570
),
6671
},
6772
RequestItem: request.NewAWSClusterTemplateRequestItem("1234"),
@@ -71,11 +76,11 @@ func TestGeneratePatches(
7176
ValueMatcher: gomega.HaveLen(3),
7277
}},
7378
},
74-
capitest.PatchTestDef{
79+
{
7580
Name: "both VPC ID and Subnet IDs set",
7681
Vars: []runtimehooksv1.Variable{
7782
capitest.VariableWithValue(
78-
variableName,
83+
clusterconfig.MetaVariableName,
7984
v1alpha1.AWSNetwork{
8085
VPC: &v1alpha1.VPC{
8186
ID: "vpc-1234",
@@ -86,7 +91,8 @@ func TestGeneratePatches(
8691
{ID: "subnet-3"},
8792
},
8893
},
89-
variablePath...,
94+
v1alpha1.AWSVariableName,
95+
VariableName,
9096
),
9197
},
9298
RequestItem: request.NewAWSClusterTemplateRequestItem("1234"),
@@ -100,5 +106,17 @@ func TestGeneratePatches(
100106
ValueMatcher: gomega.HaveLen(3),
101107
}},
102108
},
103-
)
104-
}
109+
}
110+
111+
// create test node for each case
112+
for testIdx := range testDefs {
113+
tt := testDefs[testIdx]
114+
It(tt.Name, func() {
115+
capitest.AssertGeneratePatches(
116+
GinkgoT(),
117+
patchGenerator,
118+
&tt,
119+
)
120+
})
121+
}
122+
})

0 commit comments

Comments
 (0)