Update tests to account for ensuring phase is always set
@@ -43,6 +43,26 @@ var (
)
func TestReconcileRequest(t *testing.T) {
+ machineNoPhase := machinev1.Machine{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "Machine",
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "emptyPhase",
+ Namespace: "default",
+ Finalizers: []string{machinev1.MachineFinalizer, metav1.FinalizerDeleteDependents},
+ Labels: map[string]string{
+ machinev1.MachineClusterIDLabel: "testcluster",
+ },
+ },
+ Spec: machinev1.MachineSpec{
+ ProviderSpec: machinev1.ProviderSpec{
+ Value: &runtime.RawExtension{
+ Raw: []byte("{}"),
+ },
+ },
+ },
+ }
machineProvisioning := machinev1.Machine{
TypeMeta: metav1.TypeMeta{
Kind: "Machine",
@@ -62,6 +82,9 @@ func TestReconcileRequest(t *testing.T) {
},
},
},
+ Status: machinev1.MachineStatus{
+ Phase: pointer.StringPtr(phaseProvisioning),
+ },
}
machineProvisioned := machinev1.Machine{
TypeMeta: metav1.TypeMeta{
@@ -189,6 +212,19 @@ func TestReconcileRequest(t *testing.T) {
existsValue bool
expected expected
}{
+ {
+ request: reconcile.Request{NamespacedName: types.NamespacedName{Name: machineNoPhase.Name, Namespace: machineNoPhase.Namespace}},
+ existsValue: false,
+ expected: expected{
+ createCallCount: 0,
+ existCallCount: 1,
+ updateCallCount: 0,
+ deleteCallCount: 0,
+ result: reconcile.Result{RequeueAfter: requeueAfter},
+ error: false,
+ phase: phaseProvisioning,
+ },
+ },
{
request: reconcile.Request{NamespacedName: types.NamespacedName{Name: machineProvisioning.Name, Namespace: machineProvisioning.Namespace}},
existsValue: false,
@@ -270,11 +306,13 @@ func TestReconcileRequest(t *testing.T) {
}
for _, tc := range testCases {
+ t.Run(tc.request.Name, func(t *testing.T) {
act := newTestActuator()
act.ExistsValue = tc.existsValue
machinev1.AddToScheme(scheme.Scheme)
r := &ReconcileMachine{
Client: fake.NewFakeClientWithScheme(scheme.Scheme,
+ &machineNoPhase,
&machineProvisioning,
&machineProvisioned,
&machineDeleting,
@@ -323,6 +361,7 @@ func TestReconcileRequest(t *testing.T) {
if tc.expected.phase != stringPointerDeref(machine.Status.Phase) {
t.Errorf("Case %s. Got: %v, expected: %v", tc.request.Name, stringPointerDeref(machine.Status.Phase), tc.expected.phase)
}
+ })
}
}
