mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-20 12:23:22 +00:00
Fixes bug with Root not handling Group without Version
Kubernetes-commit: 17cd59ec1cf5c0a83d52bc94995025e802f1a123
This commit is contained in:
parent
91199a69ee
commit
6ddf61b8c1
@ -157,6 +157,10 @@ func pathToGroupVersion(path string) (schema.GroupVersion, error) {
|
||||
}
|
||||
apiPrefix := parts[0]
|
||||
if apiPrefix == "apis" {
|
||||
// Example: apis/apps (without version)
|
||||
if len(parts) < 3 {
|
||||
return gv, fmt.Errorf("Group without Version not allowed")
|
||||
}
|
||||
gv.Group = parts[1]
|
||||
gv.Version = parts[2]
|
||||
} else if apiPrefix == "api" {
|
||||
|
@ -70,6 +70,7 @@ func TestOpenAPIV3Root_GroupVersions(t *testing.T) {
|
||||
"foo/apps/v1": nil, // bad prefix
|
||||
"apis/networking.k8s.io/v1alpha1": nil,
|
||||
"api": nil, // No version
|
||||
"apis/apps": nil, // Missing Version
|
||||
"apis/apps/v1": nil,
|
||||
},
|
||||
// Alphabetical ordering, since GV's are returned sorted.
|
||||
@ -268,18 +269,24 @@ func TestOpenAPIV3Root_GroupVersionToPath(t *testing.T) {
|
||||
|
||||
func TestOpenAPIV3Root_PathToGroupVersion(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
path string
|
||||
expectedGV schema.GroupVersion
|
||||
name string
|
||||
path string
|
||||
expectedGV schema.GroupVersion
|
||||
expectedErr bool
|
||||
}{
|
||||
{
|
||||
name: "OpenAPI V3 Root: Path to GroupVersion apps group",
|
||||
name: "OpenAPI V3 Root: Path to GroupVersion apps/v1 group",
|
||||
path: "apis/apps/v1",
|
||||
expectedGV: schema.GroupVersion{
|
||||
Group: "apps",
|
||||
Version: "v1",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Group without Version throws error",
|
||||
path: "apis/apps",
|
||||
expectedErr: true,
|
||||
},
|
||||
{
|
||||
name: "OpenAPI V3 Root: Path to GroupVersion batch group",
|
||||
path: "apis/batch/v1beta1",
|
||||
@ -300,9 +307,13 @@ func TestOpenAPIV3Root_PathToGroupVersion(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
actualGV, err := pathToGroupVersion(test.path)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, test.expectedGV, actualGV, "expected GroupVersion (%s), got (%s)",
|
||||
test.expectedGV, actualGV)
|
||||
if test.expectedErr {
|
||||
require.Error(t, err, "should have received error for path: %s", test.path)
|
||||
} else {
|
||||
require.NoError(t, err, "expected no error, got (%v)", err)
|
||||
assert.Equal(t, test.expectedGV, actualGV, "expected GroupVersion (%s), got (%s)",
|
||||
test.expectedGV, actualGV)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user