diff --git a/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/jsonpath_flags.go b/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/jsonpath_flags.go index 6f75af91b43..8fc2227cf1c 100644 --- a/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/jsonpath_flags.go +++ b/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/jsonpath_flags.go @@ -19,6 +19,7 @@ package genericclioptions import ( "fmt" "io/ioutil" + "sort" "strings" "github.com/spf13/cobra" @@ -49,6 +50,7 @@ func (f *JSONPathPrintFlags) AllowedFormats() []string { for format := range jsonFormats { formats = append(formats, format) } + sort.Strings(formats) return formats } diff --git a/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/jsonpath_flags_test.go b/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/jsonpath_flags_test.go index bf0c087bc1b..bba946f4039 100644 --- a/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/jsonpath_flags_test.go +++ b/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/jsonpath_flags_test.go @@ -21,6 +21,7 @@ import ( "fmt" "io/ioutil" "os" + "sort" "strings" "testing" @@ -101,6 +102,9 @@ func TestPrinterSupportsExpectedJSONPathFormats(t *testing.T) { printFlags := JSONPathPrintFlags{ TemplateArgument: templateArg, } + if !sort.StringsAreSorted(printFlags.AllowedFormats()) { + t.Fatalf("allowed formats are not sorted") + } p, err := printFlags.ToPrinter(tc.outputFormat) if tc.expectNoMatch { @@ -180,6 +184,9 @@ func TestJSONPathPrinterDefaultsAllowMissingKeysToTrue(t *testing.T) { TemplateArgument: &tc.templateArg, AllowMissingKeys: tc.allowMissingKeys, } + if !sort.StringsAreSorted(printFlags.AllowedFormats()) { + t.Fatalf("allowed formats are not sorted") + } outputFormat := "jsonpath" p, err := printFlags.ToPrinter(outputFormat) diff --git a/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/template_flags.go b/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/template_flags.go index eeae7ac7d6e..08954b24173 100644 --- a/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/template_flags.go +++ b/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/template_flags.go @@ -19,6 +19,7 @@ package genericclioptions import ( "fmt" "io/ioutil" + "sort" "strings" "github.com/spf13/cobra" @@ -51,6 +52,7 @@ func (f *GoTemplatePrintFlags) AllowedFormats() []string { for format := range templateFormats { formats = append(formats, format) } + sort.Strings(formats) return formats } diff --git a/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/template_flags_test.go b/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/template_flags_test.go index e1f5ae60e5c..194a335e420 100644 --- a/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/template_flags_test.go +++ b/staging/src/k8s.io/cli-runtime/pkg/genericclioptions/template_flags_test.go @@ -21,6 +21,7 @@ import ( "fmt" "io/ioutil" "os" + "sort" "strings" "testing" @@ -101,6 +102,9 @@ func TestPrinterSupportsExpectedTemplateFormats(t *testing.T) { printFlags := GoTemplatePrintFlags{ TemplateArgument: templateArg, } + if !sort.StringsAreSorted(printFlags.AllowedFormats()) { + t.Fatalf("allowed formats are not sorted") + } p, err := printFlags.ToPrinter(tc.outputFormat) if tc.expectNoMatch { @@ -174,6 +178,9 @@ func TestTemplatePrinterDefaultsAllowMissingKeysToTrue(t *testing.T) { TemplateArgument: &tc.templateArg, AllowMissingKeys: tc.allowMissingKeys, } + if !sort.StringsAreSorted(printFlags.AllowedFormats()) { + t.Fatalf("allowed formats are not sorted") + } outputFormat := "template" p, err := printFlags.ToPrinter(outputFormat)