Fix for the 'kubectl explain crd --recursive' goes into an infinite loop issue
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
tst "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/testing"
|
||||
)
|
||||
|
||||
func TestRecursiveFields(t *testing.T) {
|
||||
@@ -59,3 +60,42 @@ field2 <[]map[string]string>
|
||||
t.Errorf("Got:\n%v\nWant:\n%v\n", buf.String(), want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecursiveFieldsWithSelfReferenceObjects(t *testing.T) {
|
||||
var resources = tst.NewFakeResources("test-recursive-swagger.json")
|
||||
schema := resources.LookupResource(schema.GroupVersionKind{
|
||||
Group: "",
|
||||
Version: "v2",
|
||||
Kind: "OneKind",
|
||||
})
|
||||
if schema == nil {
|
||||
t.Fatal("Couldn't find schema v2.OneKind")
|
||||
}
|
||||
|
||||
want := `field1 <Object>
|
||||
referencefield <Object>
|
||||
referencesarray <[]Object>
|
||||
field2 <Object>
|
||||
reference <Object>
|
||||
referencefield <Object>
|
||||
referencesarray <[]Object>
|
||||
string <string>
|
||||
`
|
||||
|
||||
buf := bytes.Buffer{}
|
||||
f := Formatter{
|
||||
Writer: &buf,
|
||||
Wrap: 80,
|
||||
}
|
||||
s, err := LookupSchemaForField(schema, []string{})
|
||||
if err != nil {
|
||||
t.Fatalf("Invalid path %v: %v", []string{}, err)
|
||||
}
|
||||
if err := (fieldsPrinterBuilder{Recursive: true}).BuildFieldsPrinter(&f).PrintFields(s); err != nil {
|
||||
t.Fatalf("Failed to print fields: %v", err)
|
||||
}
|
||||
got := buf.String()
|
||||
if got != want {
|
||||
t.Errorf("Got:\n%v\nWant:\n%v\n", buf.String(), want)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user