1
1
// Copyright 2023 D2iQ, Inc. All rights reserved.
2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
- package tests
4
+ package ami
5
5
6
6
import (
7
- "testing"
8
-
7
+ . "github.com/onsi/ginkgo/v2"
9
8
"github.com/onsi/gomega"
10
9
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
11
10
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
@@ -14,99 +13,23 @@ import (
14
13
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
15
14
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
16
15
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
16
+ "github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/workerconfig"
17
17
)
18
18
19
- func TestControlPlaneGeneratePatches (
20
- t * testing.T ,
21
- generatorFunc func () mutation.GeneratePatches ,
22
- variableName string ,
23
- variablePath ... string ,
24
- ) {
25
- t .Helper ()
26
-
27
- capitest .ValidateGeneratePatches (
28
- t ,
29
- generatorFunc ,
30
- capitest.PatchTestDef {
31
- Name : "AMI set for control plane" ,
32
- Vars : []runtimehooksv1.Variable {
33
- capitest .VariableWithValue (
34
- variableName ,
35
- v1alpha1.AMISpec {ID : "ami-controlplane" },
36
- variablePath ... ,
37
- ),
38
- },
39
- RequestItem : request .NewCPAWSMachineTemplateRequestItem ("1234" ),
40
- ExpectedPatchMatchers : []capitest.JSONPatchMatcher {
41
- {
42
- Operation : "add" ,
43
- Path : "/spec/template/spec/ami/id" ,
44
- ValueMatcher : gomega .Equal ("ami-controlplane" ),
45
- },
46
- },
47
- },
48
- capitest.PatchTestDef {
49
- Name : "AMI lookup format set for control plane" ,
50
- Vars : []runtimehooksv1.Variable {
51
- capitest .VariableWithValue (
52
- variableName ,
53
- v1alpha1.AMISpec {
54
- Lookup : & v1alpha1.AMILookup {
55
- Format : "test-{{.kubernetesVersion}}-format" ,
56
- Org : "12345" ,
57
- BaseOS : "testOS" ,
58
- },
59
- },
60
- variablePath ... ,
61
- ),
62
- },
63
- RequestItem : request .NewCPAWSMachineTemplateRequestItem ("1234" ),
64
- ExpectedPatchMatchers : []capitest.JSONPatchMatcher {
65
- {
66
- Operation : "add" ,
67
- Path : "/spec/template/spec/imageLookupFormat" ,
68
- ValueMatcher : gomega .Equal ("test-{{.kubernetesVersion}}-format" ),
69
- },
70
- {
71
- Operation : "add" ,
72
- Path : "/spec/template/spec/imageLookupOrg" ,
73
- ValueMatcher : gomega .Equal ("12345" ),
74
- },
75
- {
76
- Operation : "add" ,
77
- Path : "/spec/template/spec/imageLookupBaseOS" ,
78
- ValueMatcher : gomega .Equal ("testOS" ),
79
- },
80
- },
81
- UnexpectedPatchMatchers : []capitest.JSONPatchMatcher {
82
- {
83
- Operation : "add" ,
84
- Path : "/spec/template/spec/ami/id" ,
85
- ValueMatcher : gomega .Equal ("" ),
86
- },
87
- },
88
- },
89
- )
90
- }
91
-
92
- func TestWorkerGeneratePatches (
93
- t * testing.T ,
94
- generatorFunc func () mutation.GeneratePatches ,
95
- variableName string ,
96
- variablePath ... string ,
97
- ) {
98
- t .Helper ()
19
+ var _ = Describe ("Generate AMI patches for Worker" , func () {
20
+ patchGenerator := func () mutation.GeneratePatches {
21
+ return mutation .NewMetaGeneratePatchesHandler ("" , NewWorkerPatch ()).(mutation.GeneratePatches )
22
+ }
99
23
100
- capitest .ValidateGeneratePatches (
101
- t ,
102
- generatorFunc ,
103
- capitest.PatchTestDef {
24
+ testDefs := []capitest.PatchTestDef {
25
+ {
104
26
Name : "AMI set for workers" ,
105
27
Vars : []runtimehooksv1.Variable {
106
28
capitest .VariableWithValue (
107
- variableName ,
29
+ workerconfig . MetaVariableName ,
108
30
v1alpha1.AMISpec {ID : "ami-controlplane" },
109
- variablePath ... ,
31
+ v1alpha1 .AWSVariableName ,
32
+ VariableName ,
110
33
),
111
34
capitest .VariableWithValue (
112
35
"builtin" ,
@@ -124,20 +47,20 @@ func TestWorkerGeneratePatches(
124
47
},
125
48
},
126
49
},
127
- capitest. PatchTestDef {
50
+ {
128
51
Name : "AMI lookup format set for worker" ,
129
52
Vars : []runtimehooksv1.Variable {
130
53
capitest .VariableWithValue (
131
- variableName ,
54
+ workerconfig . MetaVariableName ,
132
55
v1alpha1.AMISpec {
133
56
Lookup : & v1alpha1.AMILookup {
134
57
Format : "test-{{.kubernetesVersion}}-format" ,
135
58
Org : "12345" ,
136
59
BaseOS : "testOS" ,
137
60
},
138
61
},
139
-
140
- variablePath ... ,
62
+ v1alpha1 . AWSVariableName ,
63
+ VariableName ,
141
64
),
142
65
capitest .VariableWithValue (
143
66
"builtin" ,
@@ -172,5 +95,17 @@ func TestWorkerGeneratePatches(
172
95
},
173
96
},
174
97
},
175
- )
176
- }
98
+ }
99
+
100
+ // create test node for each case
101
+ for testIdx := range testDefs {
102
+ tt := testDefs [testIdx ]
103
+ It (tt .Name , func () {
104
+ capitest .AssertGeneratePatches (
105
+ GinkgoT (),
106
+ patchGenerator ,
107
+ & tt ,
108
+ )
109
+ })
110
+ }
111
+ })
0 commit comments