Created
September 2, 2019 00:07
-
-
Save mszostok/11278dbc9316d526cd8a2e09f063e50f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Describe("choose leader election APIs", func() { | |
cases := map[string]struct { | |
supportedGroups []v1.APIGroup | |
expectedLockType resourcelock.Interface | |
}{ | |
"Should use the Lease lock because coordination group is available": { | |
supportedGroups: []v1.APIGroup{ | |
{Name: coordinationv1.GroupName}, | |
}, | |
expectedLockType: &resourcelock.LeaseLock{}, | |
}, | |
"Should use the ConfigMap lock because coordination group is unavailable": { | |
supportedGroups: []v1.APIGroup{ /* no coordination group */ }, | |
expectedLockType: &resourcelock.ConfigMapLock{}, | |
}, | |
} | |
for tname, tcase := range cases { | |
It(tname, func() { | |
clientConfig := &restclient.Config{ | |
Transport: interceptAPIGroupCall(&v1.APIGroupList{ | |
Groups: tcase.supportedGroups, | |
}), | |
} | |
rProvider, err := recorder.NewProvider(clientConfig, scheme.Scheme, tlog.NullLogger{}) | |
Expect(err).ToNot(HaveOccurred()) | |
lock, err := NewResourceLock(clientConfig, rProvider, Options{LeaderElection: true, LeaderElectionNamespace: "test-ns"}) | |
Expect(err).ToNot(HaveOccurred()) | |
Expect(lock).To(BeAssignableToTypeOf(tcase.expectedLockType)) | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment