Skip to content

Instantly share code, notes, and snippets.

@mszostok
Created September 2, 2019 00:07
Show Gist options
  • Save mszostok/11278dbc9316d526cd8a2e09f063e50f to your computer and use it in GitHub Desktop.
Save mszostok/11278dbc9316d526cd8a2e09f063e50f to your computer and use it in GitHub Desktop.
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