Skip to content

Commit

Permalink
UPSTREAM: <carry>: openshift: Add unit test for exists()
Browse files Browse the repository at this point in the history
  • Loading branch information
enxebre authored and openshift-merge-robot committed Aug 7, 2019
1 parent e93128f commit 408d4c8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/cloud/azure/actuators/machine/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ go_test(
srcs = [
"actuator_test.go",
"conditions_test.go",
"reconciler_test.go",
],
embed = [":go_default_library"],
deps = [
Expand Down
51 changes: 51 additions & 0 deletions pkg/cloud/azure/actuators/machine/reconciler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package machine

import (
"context"
"testing"

"sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1beta1"
)

func TestExists(t *testing.T) {
testCases := []struct {
vmService *FakeVMService
expected bool
}{
{
vmService: &FakeVMService{
Name: "machine-test",
ID: "machine-test-ID",
ProvisioningState: string(v1beta1.VMStateSucceeded),
},
expected: true,
},
{
vmService: &FakeVMService{
Name: "machine-test",
ID: "machine-test-ID",
ProvisioningState: string(v1beta1.VMStateUpdating),
},
expected: true,
},
{
vmService: &FakeVMService{
Name: "machine-test",
ID: "machine-test-ID",
ProvisioningState: "",
},
expected: false,
},
}
for _, tc := range testCases {
r := newFakeReconciler(t)
r.virtualMachinesSvc = tc.vmService
exists, err := r.Exists(context.TODO())
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if exists != tc.expected {
t.Fatalf("Expected: %v, got: %v", tc.expected, exists)
}
}
}

0 comments on commit 408d4c8

Please sign in to comment.