Skip to content

Commit 301be09

Browse files
committed
update failuredomain replacement unit testing
1 parent 553d922 commit 301be09

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

controllers/cloudstackmachine_controller_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package controllers_test
1818

1919
import (
20+
"fmt"
2021
"github.com/golang/mock/gomock"
2122
. "github.com/onsi/ginkgo/v2"
2223
. "github.com/onsi/gomega"
@@ -73,13 +74,14 @@ var _ = Describe("CloudStackMachineReconciler", func() {
7374
}, timeout).WithPolling(pollInterval).Should(BeTrue())
7475
})
7576

76-
It("Should replace ds.meta_data.hostname with capi machine name.", func() {
77+
It("Should replace ds.meta_data.xxx with proper values.", func() {
7778
// Mock a call to GetOrCreateVMInstance and set the machine to running.
7879
mockCloudClient.EXPECT().GetOrCreateVMInstance(
7980
gomock.Any(), gomock.Any(), gomock.Any(),
8081
gomock.Any(), gomock.Any(), gomock.Any()).Do(
8182
func(arg1, _, _, _, _, userdata interface{}) {
82-
Ω(userdata == dummies.CAPIMachine.Name).Should(BeTrue())
83+
expectedUserdata := fmt.Sprintf("%s{{%s}}", dummies.CAPIMachine.Name, dummies.CSMachine1.Spec.FailureDomainName)
84+
Ω(userdata == expectedUserdata).Should(BeTrue())
8385
arg1.(*infrav1.CloudStackMachine).Status.InstanceState = "Running"
8486
}).AnyTimes()
8587

test/dummies/v1beta2/vars.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,9 @@ func SetDummyCSMachineVars() {
227227
Labels: ClusterLabel,
228228
},
229229
Spec: infrav1.CloudStackMachineSpec{
230-
Name: "test-machine-1",
231-
InstanceID: pointer.String("Instance1"),
230+
Name: "test-machine-1",
231+
InstanceID: pointer.String("Instance1"),
232+
FailureDomainName: GetYamlVal("CLOUDSTACK_FD1_NAME"),
232233
Template: infrav1.CloudStackResourceIdentifier{
233234
Name: GetYamlVal("CLOUDSTACK_TEMPLATE_NAME"),
234235
},
@@ -398,7 +399,7 @@ func SetDummyIsoNetToNameOnly() {
398399

399400
func SetDummyBootstrapSecretVar() {
400401
BootstrapSecretName := "such-secret-much-wow"
401-
BootstrapSecretValue := "{{ ds.meta_data.hostname }}"
402+
BootstrapSecretValue := "{{ ds.meta_data.hostname }}{{ds.meta_data.failuredomain}}"
402403
BootstrapSecret = &corev1.Secret{
403404
ObjectMeta: metav1.ObjectMeta{
404405
Namespace: ClusterNameSpace,

0 commit comments

Comments
 (0)