2020-08-01 00:37:59 +00:00
|
|
|
/*
|
|
|
|
Copyright 2020 VMware, Inc.
|
|
|
|
SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
|
2020-08-20 17:54:15 +00:00
|
|
|
"github.com/suzerain-io/pinniped/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-08-20 17:54:15 +00:00
|
|
|
groupName := "pinniped.dev"
|
2020-08-01 00:37:59 +00:00
|
|
|
actualGroup := findGroup(groupName, groups)
|
|
|
|
require.NotNil(t, actualGroup)
|
|
|
|
|
|
|
|
expectedGroup := &metav1.APIGroup{
|
2020-08-20 17:54:15 +00:00
|
|
|
Name: "pinniped.dev",
|
2020-08-01 00:37:59 +00:00
|
|
|
Versions: []metav1.GroupVersionForDiscovery{
|
|
|
|
{
|
2020-08-20 17:54:15 +00:00
|
|
|
GroupVersion: "pinniped.dev/v1alpha1",
|
2020-08-01 00:37:59 +00:00
|
|
|
Version: "v1alpha1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PreferredVersion: metav1.GroupVersionForDiscovery{
|
2020-08-20 17:54:15 +00:00
|
|
|
GroupVersion: "pinniped.dev/v1alpha1",
|
2020-08-01 00:37:59 +00:00
|
|
|
Version: "v1alpha1",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
require.Equal(t, expectedGroup, actualGroup)
|
|
|
|
|
2020-08-20 17:54:15 +00:00
|
|
|
actualPinnipedResources := findResources("pinniped.dev/v1alpha1", resources)
|
|
|
|
require.NotNil(t, actualPinnipedResources)
|
|
|
|
actualCrdPinnipedResources := findResources("crd.pinniped.dev/v1alpha1", resources)
|
|
|
|
require.NotNil(t, actualPinnipedResources)
|
2020-08-01 00:37:59 +00:00
|
|
|
|
2020-08-14 14:11:14 +00:00
|
|
|
expectedCredentialRequestAPIResource := metav1.APIResource{
|
|
|
|
Name: "credentialrequests",
|
|
|
|
Kind: "CredentialRequest",
|
2020-08-01 00:37:59 +00:00
|
|
|
Verbs: metav1.Verbs([]string{
|
|
|
|
"create",
|
|
|
|
}),
|
|
|
|
Namespaced: false,
|
2020-08-03 14:29:54 +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-08-01 00:37:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 01:07:34 +00:00
|
|
|
expectedCredentialIssuerConfigResource := metav1.APIResource{
|
2020-08-21 16:55:44 +00:00
|
|
|
Name: "credentialissuerconfigs",
|
|
|
|
SingularName: "credentialissuerconfig",
|
2020-08-01 00:37:59 +00:00
|
|
|
Namespaced: true,
|
2020-08-21 16:55:44 +00:00
|
|
|
Kind: "CredentialIssuerConfig",
|
2020-08-01 00:37:59 +00:00
|
|
|
Verbs: metav1.Verbs([]string{
|
|
|
|
"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch",
|
|
|
|
}),
|
2020-08-21 16:55:44 +00:00
|
|
|
ShortNames: []string{"cic"},
|
2020-08-01 00:37:59 +00:00
|
|
|
StorageVersionHash: "unknown: to be filled in automatically below",
|
|
|
|
}
|
|
|
|
|
2020-08-20 17:54:15 +00:00
|
|
|
require.Len(t, actualPinnipedResources.APIResources, 1)
|
|
|
|
require.Equal(t, expectedCredentialRequestAPIResource, actualPinnipedResources.APIResources[0])
|
2020-08-01 00:37:59 +00:00
|
|
|
|
2020-08-20 17:54:15 +00:00
|
|
|
require.Len(t, actualCrdPinnipedResources.APIResources, 1)
|
|
|
|
actualAPIResource := actualCrdPinnipedResources.APIResources[0]
|
2020-08-01 00:37:59 +00:00
|
|
|
// workaround because its hard to predict the storage version hash (e.g. "t/+v41y+3e4=")
|
|
|
|
// so just don't worry about comparing that field
|
2020-08-25 01:07:34 +00:00
|
|
|
expectedCredentialIssuerConfigResource.StorageVersionHash = actualAPIResource.StorageVersionHash
|
|
|
|
require.Equal(t, expectedCredentialIssuerConfigResource, actualAPIResource)
|
2020-08-01 00:37:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func findGroup(name string, groups []*metav1.APIGroup) *metav1.APIGroup {
|
|
|
|
for _, group := range groups {
|
|
|
|
if group.Name == name {
|
|
|
|
return group
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func findResources(groupVersion string, resources []*metav1.APIResourceList) *metav1.APIResourceList {
|
|
|
|
for _, resource := range resources {
|
|
|
|
if resource.GroupVersion == groupVersion {
|
|
|
|
return resource
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|