1
1
// Copyright 2023 D2iQ, Inc. All rights reserved.
2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
- package tests
4
+ package network
5
5
6
6
import (
7
7
"testing"
8
8
9
+ . "github.com/onsi/ginkgo/v2"
9
10
"github.com/onsi/gomega"
11
+ . "github.com/onsi/gomega"
10
12
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
11
13
12
14
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
13
15
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
14
16
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
15
17
"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"
16
19
)
17
20
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
+ }
25
30
26
- capitest .ValidateGeneratePatches (
27
- t ,
28
- generatorFunc ,
29
- capitest.PatchTestDef {
31
+ testDefs := []capitest.PatchTestDef {
32
+ {
30
33
Name : "unset variable" ,
31
34
},
32
- capitest. PatchTestDef {
35
+ {
33
36
Name : "VPC ID set" ,
34
37
Vars : []runtimehooksv1.Variable {
35
38
capitest .VariableWithValue (
36
- variableName ,
39
+ clusterconfig . MetaVariableName ,
37
40
v1alpha1.AWSNetwork {
38
41
VPC : & v1alpha1.VPC {
39
42
ID : "vpc-1234" ,
40
43
},
41
44
},
42
- variablePath ... ,
45
+ v1alpha1 .AWSVariableName ,
46
+ VariableName ,
43
47
),
44
48
},
45
49
RequestItem : request .NewAWSClusterTemplateRequestItem ("1234" ),
@@ -49,19 +53,20 @@ func TestGeneratePatches(
49
53
ValueMatcher : gomega .Equal ("vpc-1234" ),
50
54
}},
51
55
},
52
- capitest. PatchTestDef {
56
+ {
53
57
Name : "Subnet IDs set" ,
54
58
Vars : []runtimehooksv1.Variable {
55
59
capitest .VariableWithValue (
56
- variableName ,
60
+ clusterconfig . MetaVariableName ,
57
61
v1alpha1.AWSNetwork {
58
62
Subnets : v1alpha1.Subnets {
59
63
{ID : "subnet-1" },
60
64
{ID : "subnet-2" },
61
65
{ID : "subnet-3" },
62
66
},
63
67
},
64
- variablePath ... ,
68
+ v1alpha1 .AWSVariableName ,
69
+ VariableName ,
65
70
),
66
71
},
67
72
RequestItem : request .NewAWSClusterTemplateRequestItem ("1234" ),
@@ -71,11 +76,11 @@ func TestGeneratePatches(
71
76
ValueMatcher : gomega .HaveLen (3 ),
72
77
}},
73
78
},
74
- capitest. PatchTestDef {
79
+ {
75
80
Name : "both VPC ID and Subnet IDs set" ,
76
81
Vars : []runtimehooksv1.Variable {
77
82
capitest .VariableWithValue (
78
- variableName ,
83
+ clusterconfig . MetaVariableName ,
79
84
v1alpha1.AWSNetwork {
80
85
VPC : & v1alpha1.VPC {
81
86
ID : "vpc-1234" ,
@@ -86,7 +91,8 @@ func TestGeneratePatches(
86
91
{ID : "subnet-3" },
87
92
},
88
93
},
89
- variablePath ... ,
94
+ v1alpha1 .AWSVariableName ,
95
+ VariableName ,
90
96
),
91
97
},
92
98
RequestItem : request .NewAWSClusterTemplateRequestItem ("1234" ),
@@ -100,5 +106,17 @@ func TestGeneratePatches(
100
106
ValueMatcher : gomega .HaveLen (3 ),
101
107
}},
102
108
},
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