2020-09-16 14:19:51 +00:00
|
|
|
// Copyright 2020 the Pinniped contributors. All Rights Reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2020-08-01 00:37:59 +00:00
|
|
|
|
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
|
2020-09-18 19:56:24 +00:00
|
|
|
"go.pinniped.dev/test/library"
|
2020-08-01 00:37:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetAPIResourceList(t *testing.T) {
|
2020-08-07 01:44:14 +00:00
|
|
|
library.SkipUnlessIntegration(t)
|
|
|
|
|
2020-08-20 17:54:15 +00:00
|
|
|
client := library.NewPinnipedClientset(t)
|
2020-08-01 00:37:59 +00:00
|
|
|
|
|
|
|
groups, resources, err := client.Discovery().ServerGroupsAndResources()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-09-09 15:36:38 +00:00
|
|
|
tests := []struct {
|
|
|
|
group metav1.APIGroup
|
|
|
|
resourceByVersion map[string][]metav1.APIResource
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
group: metav1.APIGroup{
|
2020-09-18 22:15:04 +00:00
|
|
|
Name: "login.pinniped.dev",
|
2020-09-09 15:36:38 +00:00
|
|
|
Versions: []metav1.GroupVersionForDiscovery{
|
|
|
|
{
|
2020-09-18 22:15:04 +00:00
|
|
|
GroupVersion: "login.pinniped.dev/v1alpha1",
|
2020-09-09 15:36:38 +00:00
|
|
|
Version: "v1alpha1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PreferredVersion: metav1.GroupVersionForDiscovery{
|
2020-09-18 22:15:04 +00:00
|
|
|
GroupVersion: "login.pinniped.dev/v1alpha1",
|
2020-09-09 15:23:28 +00:00
|
|
|
Version: "v1alpha1",
|
|
|
|
},
|
|
|
|
},
|
2020-09-09 15:36:38 +00:00
|
|
|
resourceByVersion: map[string][]metav1.APIResource{
|
2020-09-18 22:15:04 +00:00
|
|
|
"login.pinniped.dev/v1alpha1": {
|
2020-09-09 15:36:38 +00:00
|
|
|
{
|
2020-09-18 22:15:04 +00:00
|
|
|
Name: "tokencredentialrequests",
|
|
|
|
Kind: "TokenCredentialRequest",
|
2020-09-09 15:36:38 +00:00
|
|
|
Verbs: []string{"create"},
|
2020-09-18 22:15:04 +00:00
|
|
|
Namespaced: true,
|
2020-08-01 00:37:59 +00:00
|
|
|
|
2020-09-09 15:36:38 +00:00
|
|
|
// 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: "",
|
|
|
|
},
|
|
|
|
},
|
2020-09-09 15:23:28 +00:00
|
|
|
},
|
2020-09-09 15:36:38 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
group: metav1.APIGroup{
|
2020-09-18 21:38:45 +00:00
|
|
|
Name: "config.pinniped.dev",
|
2020-09-09 15:36:38 +00:00
|
|
|
Versions: []metav1.GroupVersionForDiscovery{
|
|
|
|
{
|
2020-09-18 21:38:45 +00:00
|
|
|
GroupVersion: "config.pinniped.dev/v1alpha1",
|
2020-09-09 15:36:38 +00:00
|
|
|
Version: "v1alpha1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PreferredVersion: metav1.GroupVersionForDiscovery{
|
2020-09-18 21:38:45 +00:00
|
|
|
GroupVersion: "config.pinniped.dev/v1alpha1",
|
2020-09-09 15:36:38 +00:00
|
|
|
Version: "v1alpha1",
|
|
|
|
},
|
2020-09-09 15:23:28 +00:00
|
|
|
},
|
2020-09-09 15:36:38 +00:00
|
|
|
resourceByVersion: map[string][]metav1.APIResource{
|
2020-09-18 21:38:45 +00:00
|
|
|
"config.pinniped.dev/v1alpha1": {
|
2020-09-09 15:36:38 +00:00
|
|
|
{
|
|
|
|
Name: "credentialissuerconfigs",
|
|
|
|
SingularName: "credentialissuerconfig",
|
|
|
|
Namespaced: true,
|
|
|
|
Kind: "CredentialIssuerConfig",
|
|
|
|
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
|
|
|
|
ShortNames: []string{"cic"},
|
|
|
|
},
|
2020-10-07 00:53:29 +00:00
|
|
|
{
|
|
|
|
Name: "oidcproviderconfigs",
|
|
|
|
SingularName: "oidcproviderconfig",
|
|
|
|
Namespaced: true,
|
|
|
|
Kind: "OIDCProviderConfig",
|
|
|
|
Verbs: []string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"},
|
|
|
|
ShortNames: []string{"opc"},
|
|
|
|
},
|
2020-09-09 15:36:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
group: metav1.APIGroup{
|
|
|
|
Name: "idp.pinniped.dev",
|
|
|
|
Versions: []metav1.GroupVersionForDiscovery{
|
|
|
|
{
|
|
|
|
GroupVersion: "idp.pinniped.dev/v1alpha1",
|
|
|
|
Version: "v1alpha1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-08-01 00:37:59 +00:00
|
|
|
}
|
2020-09-09 15:23:28 +00:00
|
|
|
|
2020-09-09 15:36:38 +00:00
|
|
|
for _, tt := range tests {
|
|
|
|
tt := tt
|
|
|
|
t.Run(tt.group.Name, func(t *testing.T) {
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
})
|
2020-09-09 15:23:28 +00:00
|
|
|
}
|
2020-08-01 00:37:59 +00:00
|
|
|
}
|