Skip to content

Commit e3c25c1

Browse files
committed
add unit test case for machine
1 parent c6e3d8d commit e3c25c1

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

cloud/scope/machine_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,50 @@ func TestInstanceReconciliation(t *testing.T) {
400400
gomock.InOrder(first, second)
401401
},
402402
},
403+
{
404+
name: "retries fault domains discovered from availability domain cache",
405+
errorExpected: false,
406+
testSpecificSetup: func(machineScope *MachineScope, computeClient *mock_compute.MockComputeClient) {
407+
setupAllParams(ms)
408+
ociCluster := ms.OCIClusterAccessor.(OCISelfManagedCluster).OCICluster
409+
ociCluster.Status.FailureDomains = map[string]clusterv1.FailureDomainSpec{
410+
"1": {
411+
Attributes: map[string]string{
412+
"AvailabilityDomain": "ad1",
413+
},
414+
},
415+
}
416+
ociCluster.Spec.AvailabilityDomains = map[string]infrastructurev1beta2.OCIAvailabilityDomain{
417+
"ad1": {
418+
Name: "ad1",
419+
FaultDomains: []string{"FAULT-DOMAIN-1", "FAULT-DOMAIN-2"},
420+
},
421+
}
422+
ms.Machine.Spec.FailureDomain = common.String("1")
423+
computeClient.EXPECT().ListInstances(gomock.Any(), gomock.Eq(core.ListInstancesRequest{
424+
DisplayName: common.String("name"),
425+
CompartmentId: common.String("test"),
426+
})).Return(core.ListInstancesResponse{}, nil)
427+
428+
first := computeClient.EXPECT().LaunchInstance(gomock.Any(), Eq(func(request interface{}) error {
429+
return faultDomainRequestMatcher(request, "")
430+
})).Return(core.LaunchInstanceResponse{}, newOutOfCapacityServiceError("out of host capacity"))
431+
432+
second := computeClient.EXPECT().LaunchInstance(gomock.Any(), Eq(func(request interface{}) error {
433+
return faultDomainRequestMatcher(request, "FAULT-DOMAIN-1")
434+
})).Return(core.LaunchInstanceResponse{}, newOutOfCapacityServiceError("out of host capacity"))
435+
436+
third := computeClient.EXPECT().LaunchInstance(gomock.Any(), Eq(func(request interface{}) error {
437+
return faultDomainRequestMatcher(request, "FAULT-DOMAIN-2")
438+
})).Return(core.LaunchInstanceResponse{
439+
Instance: core.Instance{
440+
Id: common.String("instance-id"),
441+
},
442+
}, nil)
443+
444+
gomock.InOrder(first, second, third)
445+
},
446+
},
403447
{
404448
name: "check all params together",
405449
errorExpected: false,

0 commit comments

Comments
 (0)