mirror of
https://github.com/spf13/viper
synced 2024-11-04 20:27:02 +00:00
Moved shared resources out of the loops in TestBindPFlagsStringSlice()
Common code and resources put out of the loops, to improve efficiency and readability.
This commit is contained in:
parent
69647fb422
commit
ae103d7e59
1 changed files with 11 additions and 9 deletions
|
@ -613,23 +613,25 @@ func TestBindPFlags(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBindPFlagsStringSlice(t *testing.T) {
|
func TestBindPFlagsStringSlice(t *testing.T) {
|
||||||
defaultVal := []string{"default"}
|
tests := []struct {
|
||||||
|
|
||||||
for _, testValue := range []struct {
|
|
||||||
Expected []string
|
Expected []string
|
||||||
Value string
|
Value string
|
||||||
}{
|
}{
|
||||||
{[]string{}, ""},
|
{[]string{}, ""},
|
||||||
{[]string{"jeden"}, "jeden"},
|
{[]string{"jeden"}, "jeden"},
|
||||||
{[]string{"dwa", "trzy"}, "dwa,trzy"},
|
{[]string{"dwa", "trzy"}, "dwa,trzy"},
|
||||||
{[]string{"cztery", "piec , szesc"}, "cztery,\"piec , szesc\""}} {
|
{[]string{"cztery", "piec , szesc"}, "cztery,\"piec , szesc\""},
|
||||||
|
}
|
||||||
|
|
||||||
|
v := New() // create independent Viper object
|
||||||
|
defaultVal := []string{"default"}
|
||||||
|
v.SetDefault("stringslice", defaultVal)
|
||||||
|
|
||||||
|
for _, testValue := range tests {
|
||||||
|
flagSet := pflag.NewFlagSet("test", pflag.ContinueOnError)
|
||||||
|
flagSet.StringSlice("stringslice", testValue.Expected, "test")
|
||||||
|
|
||||||
for _, changed := range []bool{true, false} {
|
for _, changed := range []bool{true, false} {
|
||||||
v := New() // create independent Viper object
|
|
||||||
v.SetDefault("stringslice", defaultVal)
|
|
||||||
|
|
||||||
flagSet := pflag.NewFlagSet("test", pflag.ContinueOnError)
|
|
||||||
flagSet.StringSlice("stringslice", testValue.Expected, "test")
|
|
||||||
flagSet.VisitAll(func(f *pflag.Flag) {
|
flagSet.VisitAll(func(f *pflag.Flag) {
|
||||||
f.Value.Set(testValue.Value)
|
f.Value.Set(testValue.Value)
|
||||||
f.Changed = changed
|
f.Changed = changed
|
||||||
|
|
Loading…
Reference in a new issue