Expect the WebhookIdentityProvider CRD to be installed.
Signed-off-by: Matt Moyer <moyerm@vmware.com>
This commit is contained in:
parent
557fd0df26
commit
3344b5b86a
@ -22,65 +22,119 @@ func TestGetAPIResourceList(t *testing.T) {
|
|||||||
groups, resources, err := client.Discovery().ServerGroupsAndResources()
|
groups, resources, err := client.Discovery().ServerGroupsAndResources()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Run("has group", func(t *testing.T) {
|
tests := []struct {
|
||||||
require.Contains(t, groups, &metav1.APIGroup{
|
group metav1.APIGroup
|
||||||
Name: "pinniped.dev",
|
resourceByVersion map[string][]metav1.APIResource
|
||||||
Versions: []metav1.GroupVersionForDiscovery{
|
}{
|
||||||
{
|
{
|
||||||
|
group: metav1.APIGroup{
|
||||||
|
Name: "pinniped.dev",
|
||||||
|
Versions: []metav1.GroupVersionForDiscovery{
|
||||||
|
{
|
||||||
|
GroupVersion: "pinniped.dev/v1alpha1",
|
||||||
|
Version: "v1alpha1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
PreferredVersion: metav1.GroupVersionForDiscovery{
|
||||||
GroupVersion: "pinniped.dev/v1alpha1",
|
GroupVersion: "pinniped.dev/v1alpha1",
|
||||||
Version: "v1alpha1",
|
Version: "v1alpha1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
PreferredVersion: metav1.GroupVersionForDiscovery{
|
resourceByVersion: map[string][]metav1.APIResource{
|
||||||
GroupVersion: "pinniped.dev/v1alpha1",
|
"pinniped.dev/v1alpha1": {
|
||||||
Version: "v1alpha1",
|
{
|
||||||
|
Name: "credentialrequests",
|
||||||
|
Kind: "CredentialRequest",
|
||||||
|
Verbs: []string{"create"},
|
||||||
|
Namespaced: false,
|
||||||
|
|
||||||
|
// This is currently an empty string in the response; maybe it should not be
|
||||||
|
// empty? Seems like no harm in keeping it like this for now, but feel free
|
||||||
|
// to update in the future if there is a compelling reason to do so.
|
||||||
|
SingularName: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
},
|
||||||
})
|
{
|
||||||
|
group: metav1.APIGroup{
|
||||||
t.Run("has non-CRD APIs", func(t *testing.T) {
|
Name: "crd.pinniped.dev",
|
||||||
expectResources(t, "pinniped.dev/v1alpha1", resources, []metav1.APIResource{
|
Versions: []metav1.GroupVersionForDiscovery{
|
||||||
{
|
{
|
||||||
Name: "credentialrequests",
|
GroupVersion: "crd.pinniped.dev/v1alpha1",
|
||||||
Kind: "CredentialRequest",
|
Version: "v1alpha1",
|
||||||
Verbs: []string{"create"},
|
},
|
||||||
Namespaced: false,
|
},
|
||||||
|
PreferredVersion: metav1.GroupVersionForDiscovery{
|
||||||
// This is currently an empty string in the response; maybe it should not be
|
GroupVersion: "crd.pinniped.dev/v1alpha1",
|
||||||
// empty? Seems like no harm in keeping it like this for now, but feel free
|
Version: "v1alpha1",
|
||||||
// to update in the future if there is a compelling reason to do so.
|
},
|
||||||
SingularName: "",
|
|
||||||
},
|
},
|
||||||
})
|
resourceByVersion: map[string][]metav1.APIResource{
|
||||||
})
|
"crd.pinniped.dev/v1alpha1": {
|
||||||
|
{
|
||||||
t.Run("has CRD APIs", func(t *testing.T) {
|
Name: "credentialissuerconfigs",
|
||||||
expectResources(t, "crd.pinniped.dev/v1alpha1", resources, []metav1.APIResource{
|
SingularName: "credentialissuerconfig",
|
||||||
{
|
Namespaced: true,
|
||||||
Name: "credentialissuerconfigs",
|
Kind: "CredentialIssuerConfig",
|
||||||
SingularName: "credentialissuerconfig",
|
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
|
||||||
Namespaced: true,
|
ShortNames: []string{"cic"},
|
||||||
Kind: "CredentialIssuerConfig",
|
},
|
||||||
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
|
},
|
||||||
ShortNames: []string{"cic"},
|
|
||||||
},
|
},
|
||||||
})
|
},
|
||||||
})
|
{
|
||||||
}
|
group: metav1.APIGroup{
|
||||||
|
Name: "idp.pinniped.dev",
|
||||||
func expectResources(t *testing.T, groupVersion string, resources []*metav1.APIResourceList, expected []metav1.APIResource) {
|
Versions: []metav1.GroupVersionForDiscovery{
|
||||||
var actualResourceList *metav1.APIResourceList
|
{
|
||||||
for _, resource := range resources {
|
GroupVersion: "idp.pinniped.dev/v1alpha1",
|
||||||
if resource.GroupVersion == groupVersion {
|
Version: "v1alpha1",
|
||||||
actualResourceList = resource.DeepCopy()
|
},
|
||||||
}
|
},
|
||||||
|
PreferredVersion: metav1.GroupVersionForDiscovery{
|
||||||
|
GroupVersion: "idp.pinniped.dev/v1alpha1",
|
||||||
|
Version: "v1alpha1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
resourceByVersion: map[string][]metav1.APIResource{
|
||||||
|
"idp.pinniped.dev/v1alpha1": {
|
||||||
|
{
|
||||||
|
Name: "webhookidentityproviders",
|
||||||
|
SingularName: "webhookidentityprovider",
|
||||||
|
Namespaced: true,
|
||||||
|
Kind: "WebhookIdentityProvider",
|
||||||
|
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
|
||||||
|
ShortNames: []string{"webhookidp", "webhookidps"},
|
||||||
|
Categories: []string{"all", "idp", "idps"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
require.NotNilf(t, actualResourceList, "could not find groupVersion %s", groupVersion)
|
|
||||||
|
|
||||||
// Because its hard to predict the storage version hash (e.g. "t/+v41y+3e4="), we just don't
|
for _, tt := range tests {
|
||||||
// worry about comparing that field.
|
tt := tt
|
||||||
for i := range actualResourceList.APIResources {
|
t.Run(tt.group.Name, func(t *testing.T) {
|
||||||
actualResourceList.APIResources[i].StorageVersionHash = ""
|
require.Contains(t, groups, &tt.group)
|
||||||
|
|
||||||
|
for groupVersion, expectedResources := range tt.resourceByVersion {
|
||||||
|
// Find the actual resource list and make a copy.
|
||||||
|
var actualResourceList *metav1.APIResourceList
|
||||||
|
for _, resource := range resources {
|
||||||
|
if resource.GroupVersion == groupVersion {
|
||||||
|
actualResourceList = resource.DeepCopy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
require.NotNilf(t, actualResourceList, "could not find groupVersion %s", groupVersion)
|
||||||
|
|
||||||
|
// Because its hard to predict the storage version hash (e.g. "t/+v41y+3e4="), we just don't
|
||||||
|
// worry about comparing that field.
|
||||||
|
for i := range actualResourceList.APIResources {
|
||||||
|
actualResourceList.APIResources[i].StorageVersionHash = ""
|
||||||
|
}
|
||||||
|
require.EqualValues(t, expectedResources, actualResourceList.APIResources, "unexpected API resources")
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
require.EqualValues(t, expected, actualResourceList.APIResources, "unexpected API resources")
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user