Skip to content

Commit a3e3b35

Browse files
authored
Merge pull request kubernetes#92619 from ii/heyste-get-apigroup-list-test
Write checkAPIGroupPreferredVersion Test - +16 Endpoint coverage
2 parents 23b66ea + ca550a2 commit a3e3b35

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/e2e/apimachinery/discovery.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package apimachinery
1818

1919
import (
20+
"context"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2022
utilversion "k8s.io/apimachinery/pkg/util/version"
2123
"k8s.io/apiserver/pkg/endpoints/discovery"
2224
"k8s.io/kubernetes/test/e2e/framework"
@@ -77,4 +79,37 @@ var _ = SIGDescribe("Discovery", func() {
7779
framework.Failf("didn't find resource %s in the discovery doc", spec.Names.Plural)
7880
}
7981
})
82+
83+
ginkgo.It("should validate PreferredVersion for each APIGroup", func() {
84+
85+
// get list of APIGroup endpoints
86+
list := &metav1.APIGroupList{}
87+
err := f.ClientSet.Discovery().RESTClient().Get().AbsPath("/apis/").Do(context.TODO()).Into(list)
88+
framework.ExpectNoError(err, "Failed to find /apis/")
89+
framework.ExpectNotEqual(len(list.Groups), 0, "Missing APIGroups")
90+
91+
for _, group := range list.Groups {
92+
framework.Logf("Checking APIGroup: %v", group.Name)
93+
94+
// locate APIGroup endpoint
95+
checkGroup := &metav1.APIGroup{}
96+
apiPath := "/apis/" + group.Name + "/"
97+
err = f.ClientSet.Discovery().RESTClient().Get().AbsPath(apiPath).Do(context.TODO()).Into(checkGroup)
98+
framework.ExpectNoError(err, "Fail to access: %s", apiPath)
99+
framework.ExpectNotEqual(len(checkGroup.Versions), 0, "No version found for %v", group.Name)
100+
framework.Logf("PreferredVersion.GroupVersion: %s", checkGroup.PreferredVersion.GroupVersion)
101+
framework.Logf("Versions found %v", checkGroup.Versions)
102+
103+
// confirm that the PreferredVersion is a valid version
104+
match := false
105+
for _, version := range checkGroup.Versions {
106+
if version.GroupVersion == checkGroup.PreferredVersion.GroupVersion {
107+
framework.Logf("%s matches %s", version.GroupVersion, checkGroup.PreferredVersion.GroupVersion)
108+
match = true
109+
break
110+
}
111+
}
112+
framework.ExpectEqual(true, match, "failed to find a valid version for PreferredVersion")
113+
}
114+
})
80115
})

0 commit comments

Comments
 (0)