mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 05:21:58 +00:00
Fix for man pages do not build reproducibly
In different distros or environments, we may end up with a different order of the strings printed during help and man page generation, So we should sort so the strings in the man pages is the same everytime. Change-Id: Id8fcbd89336aad8d709ba3adac4b29c808d97ebe
This commit is contained in:
parent
7ef6f0b625
commit
f777715262
@ -19,6 +19,7 @@ package genericclioptions
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -49,6 +50,7 @@ func (f *JSONPathPrintFlags) AllowedFormats() []string {
|
|||||||
for format := range jsonFormats {
|
for format := range jsonFormats {
|
||||||
formats = append(formats, format)
|
formats = append(formats, format)
|
||||||
}
|
}
|
||||||
|
sort.Strings(formats)
|
||||||
return formats
|
return formats
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -101,6 +102,9 @@ func TestPrinterSupportsExpectedJSONPathFormats(t *testing.T) {
|
|||||||
printFlags := JSONPathPrintFlags{
|
printFlags := JSONPathPrintFlags{
|
||||||
TemplateArgument: templateArg,
|
TemplateArgument: templateArg,
|
||||||
}
|
}
|
||||||
|
if !sort.StringsAreSorted(printFlags.AllowedFormats()) {
|
||||||
|
t.Fatalf("allowed formats are not sorted")
|
||||||
|
}
|
||||||
|
|
||||||
p, err := printFlags.ToPrinter(tc.outputFormat)
|
p, err := printFlags.ToPrinter(tc.outputFormat)
|
||||||
if tc.expectNoMatch {
|
if tc.expectNoMatch {
|
||||||
@ -180,6 +184,9 @@ func TestJSONPathPrinterDefaultsAllowMissingKeysToTrue(t *testing.T) {
|
|||||||
TemplateArgument: &tc.templateArg,
|
TemplateArgument: &tc.templateArg,
|
||||||
AllowMissingKeys: tc.allowMissingKeys,
|
AllowMissingKeys: tc.allowMissingKeys,
|
||||||
}
|
}
|
||||||
|
if !sort.StringsAreSorted(printFlags.AllowedFormats()) {
|
||||||
|
t.Fatalf("allowed formats are not sorted")
|
||||||
|
}
|
||||||
|
|
||||||
outputFormat := "jsonpath"
|
outputFormat := "jsonpath"
|
||||||
p, err := printFlags.ToPrinter(outputFormat)
|
p, err := printFlags.ToPrinter(outputFormat)
|
||||||
|
@ -19,6 +19,7 @@ package genericclioptions
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -51,6 +52,7 @@ func (f *GoTemplatePrintFlags) AllowedFormats() []string {
|
|||||||
for format := range templateFormats {
|
for format := range templateFormats {
|
||||||
formats = append(formats, format)
|
formats = append(formats, format)
|
||||||
}
|
}
|
||||||
|
sort.Strings(formats)
|
||||||
return formats
|
return formats
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -101,6 +102,9 @@ func TestPrinterSupportsExpectedTemplateFormats(t *testing.T) {
|
|||||||
printFlags := GoTemplatePrintFlags{
|
printFlags := GoTemplatePrintFlags{
|
||||||
TemplateArgument: templateArg,
|
TemplateArgument: templateArg,
|
||||||
}
|
}
|
||||||
|
if !sort.StringsAreSorted(printFlags.AllowedFormats()) {
|
||||||
|
t.Fatalf("allowed formats are not sorted")
|
||||||
|
}
|
||||||
|
|
||||||
p, err := printFlags.ToPrinter(tc.outputFormat)
|
p, err := printFlags.ToPrinter(tc.outputFormat)
|
||||||
if tc.expectNoMatch {
|
if tc.expectNoMatch {
|
||||||
@ -174,6 +178,9 @@ func TestTemplatePrinterDefaultsAllowMissingKeysToTrue(t *testing.T) {
|
|||||||
TemplateArgument: &tc.templateArg,
|
TemplateArgument: &tc.templateArg,
|
||||||
AllowMissingKeys: tc.allowMissingKeys,
|
AllowMissingKeys: tc.allowMissingKeys,
|
||||||
}
|
}
|
||||||
|
if !sort.StringsAreSorted(printFlags.AllowedFormats()) {
|
||||||
|
t.Fatalf("allowed formats are not sorted")
|
||||||
|
}
|
||||||
|
|
||||||
outputFormat := "template"
|
outputFormat := "template"
|
||||||
p, err := printFlags.ToPrinter(outputFormat)
|
p, err := printFlags.ToPrinter(outputFormat)
|
||||||
|
Loading…
Reference in New Issue
Block a user