Sort args to make log outputs a bit more deterministic

This commit is contained in:
YAMAMOTO Takashi 2019-07-24 13:16:14 +09:00
parent 1833b65fcd
commit 35d972fd72
2 changed files with 41 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"net"
"net/http"
"sort"
"strings"
"k8s.io/apiserver/pkg/authentication/authenticator"
@ -164,5 +165,6 @@ func GetArgsList(argsMap map[string]string, extraArgs []string) []string {
cmd := fmt.Sprintf("--%s=%s", arg, value)
args = append(args, cmd)
}
sort.Strings(args)
return args
}

View File

@ -0,0 +1,39 @@
package config
import (
"reflect"
"testing"
)
func TestGetArgsList(t *testing.T) {
argsMap := map[string]string{
"aaa": "A",
"bbb": "B",
"ccc": "C",
"ddd": "d",
"eee": "e",
"fff": "f",
"ggg": "g",
"hhh": "h",
}
extraArgs := []string{
"bbb=BB",
"ddd=DD",
"iii=II",
}
expected := []string{
"--aaa=A",
"--bbb=BB",
"--ccc=C",
"--ddd=DD",
"--eee=e",
"--fff=f",
"--ggg=g",
"--hhh=h",
"--iii=II",
}
actual := GetArgsList(argsMap, extraArgs)
if !reflect.DeepEqual(actual, expected) {
t.Errorf("got %v\nwant %v", actual, expected)
}
}