mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Fix printing control character in kubectl explain
This commit is contained in:
parent
45b6af6b71
commit
e4dbaef3cc
@ -68,7 +68,7 @@ func (m *modelPrinter) PrintDescription(schema proto.Schema) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := m.Writer.Indent(descriptionIndentLevel).WriteWrapped(desc); err != nil {
|
if err := m.Writer.Indent(descriptionIndentLevel).WriteWrapped("%s", desc); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,19 +24,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestModel(t *testing.T) {
|
func TestModel(t *testing.T) {
|
||||||
gvk := schema.GroupVersionKind{
|
oneKind := schema.GroupVersionKind{
|
||||||
Group: "",
|
Group: "",
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
Kind: "OneKind",
|
Kind: "OneKind",
|
||||||
}
|
}
|
||||||
schema := resources.LookupResource(gvk)
|
|
||||||
if schema == nil {
|
controlCharacterKind := schema.GroupVersionKind{
|
||||||
t.Fatal("Couldn't find schema v1.OneKind")
|
Group: "",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "ControlCharacterKind",
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
path []string
|
path []string
|
||||||
want string
|
want string
|
||||||
|
gvk schema.GroupVersionKind
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
want: `KIND: OneKind
|
want: `KIND: OneKind
|
||||||
@ -60,6 +63,7 @@ FIELDS:
|
|||||||
|
|
||||||
`,
|
`,
|
||||||
path: []string{},
|
path: []string{},
|
||||||
|
gvk: oneKind,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
want: `KIND: OneKind
|
want: `KIND: OneKind
|
||||||
@ -95,6 +99,7 @@ FIELDS:
|
|||||||
|
|
||||||
`,
|
`,
|
||||||
path: []string{"field1"},
|
path: []string{"field1"},
|
||||||
|
gvk: oneKind,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
want: `KIND: OneKind
|
want: `KIND: OneKind
|
||||||
@ -106,6 +111,7 @@ DESCRIPTION:
|
|||||||
This string must be a string
|
This string must be a string
|
||||||
`,
|
`,
|
||||||
path: []string{"field1", "string"},
|
path: []string{"field1", "string"},
|
||||||
|
gvk: oneKind,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
want: `KIND: OneKind
|
want: `KIND: OneKind
|
||||||
@ -119,12 +125,32 @@ DESCRIPTION:
|
|||||||
This is an int in an array
|
This is an int in an array
|
||||||
`,
|
`,
|
||||||
path: []string{"field1", "array"},
|
path: []string{"field1", "array"},
|
||||||
|
gvk: oneKind,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
want: `KIND: ControlCharacterKind
|
||||||
|
VERSION: v1
|
||||||
|
|
||||||
|
DESCRIPTION:
|
||||||
|
Control character %
|
||||||
|
|
||||||
|
FIELDS:
|
||||||
|
field1 <>
|
||||||
|
Control character %
|
||||||
|
|
||||||
|
`,
|
||||||
|
path: []string{},
|
||||||
|
gvk: controlCharacterKind,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
schema := resources.LookupResource(test.gvk)
|
||||||
|
if schema == nil {
|
||||||
|
t.Fatalf("Couldn't find schema %v", test.gvk)
|
||||||
|
}
|
||||||
buf := bytes.Buffer{}
|
buf := bytes.Buffer{}
|
||||||
if err := PrintModelDescription(test.path, &buf, schema, gvk, false); err != nil {
|
if err := PrintModelDescription(test.path, &buf, schema, test.gvk, false); err != nil {
|
||||||
t.Fatalf("Failed to PrintModelDescription for path %v: %v", test.path, err)
|
t.Fatalf("Failed to PrintModelDescription for path %v: %v", test.path, err)
|
||||||
}
|
}
|
||||||
got := buf.String()
|
got := buf.String()
|
||||||
|
@ -39,6 +39,21 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"ControlCharacterKind": {
|
||||||
|
"description": "Control character %",
|
||||||
|
"properties": {
|
||||||
|
"field1": {
|
||||||
|
"description": "Control character %",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"x-kubernetes-group-version-kind": [
|
||||||
|
{
|
||||||
|
"group": "",
|
||||||
|
"kind": "ControlCharacterKind",
|
||||||
|
"version": "v1"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"OtherKind": {
|
"OtherKind": {
|
||||||
"description": "This is another kind of Kind",
|
"description": "This is another kind of Kind",
|
||||||
"required": [
|
"required": [
|
||||||
|
Loading…
Reference in New Issue
Block a user