mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 13:31:52 +00:00
Add more tests that should exist but don't for some reason
This commit is contained in:
parent
5dca1be016
commit
b7cdbca237
@ -90,3 +90,69 @@ func TestSplitAndParseResourceRequest(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSplitAndParseResourceRequestWithMatchingPrefix(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
inResource string
|
||||||
|
|
||||||
|
expectedGVR schema.GroupVersionResource
|
||||||
|
expectedFieldsPath []string
|
||||||
|
expectedErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "no trailing period",
|
||||||
|
inResource: "pods.field2.field3",
|
||||||
|
|
||||||
|
expectedGVR: schema.GroupVersionResource{Resource: "pods", Version: "v1"},
|
||||||
|
expectedFieldsPath: []string{"field2", "field3"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "trailing period with correct fieldsPath",
|
||||||
|
inResource: "service.field2.field3.",
|
||||||
|
|
||||||
|
expectedGVR: schema.GroupVersionResource{Resource: "services", Version: "v1"},
|
||||||
|
expectedFieldsPath: []string{"field2", "field3"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "field with dots 1",
|
||||||
|
inResource: `service.field2['field\.with\.dots']`,
|
||||||
|
|
||||||
|
expectedGVR: schema.GroupVersionResource{Resource: "services", Version: "v1"},
|
||||||
|
expectedFieldsPath: []string{"field2", "field.with.dots"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "field with dots 2",
|
||||||
|
inResource: `service.field2.field\.with\.dots`,
|
||||||
|
|
||||||
|
expectedGVR: schema.GroupVersionResource{Resource: "services", Version: "v1"},
|
||||||
|
expectedFieldsPath: []string{"field2", "field.with.dots"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "trailing period with incorrect fieldsPath",
|
||||||
|
inResource: "node.field2.field3.",
|
||||||
|
|
||||||
|
expectedGVR: schema.GroupVersionResource{Resource: "nodes", Version: "v1"},
|
||||||
|
expectedFieldsPath: []string{"field2", "field3", ""},
|
||||||
|
expectedErr: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
mapper := testrestmapper.TestOnlyStaticRESTMapper(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...)
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
gotGVR, gotFieldsPath, err := SplitAndParseResourceRequestWithMatchingPrefix(tt.inResource, mapper)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(tt.expectedGVR, gotGVR) && !tt.expectedErr {
|
||||||
|
t.Errorf("%s: expected inResource: %s, got: %s", tt.name, tt.expectedGVR, gotGVR)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(tt.expectedFieldsPath, gotFieldsPath) && !tt.expectedErr {
|
||||||
|
t.Errorf("%s: expected fieldsPath: %s, got: %s", tt.name, tt.expectedFieldsPath, gotFieldsPath)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user