From 00458cf1a052a1c08f6544c77ac3174676debaa6 Mon Sep 17 00:00:00 2001 From: jiapengcs Date: Tue, 24 Jul 2018 10:18:57 +0800 Subject: [PATCH 1/2] fixes #1759 baiji-group=264-3 --- daemon/config/config_test.go | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/daemon/config/config_test.go b/daemon/config/config_test.go index ecaa6389a..d011292fc 100644 --- a/daemon/config/config_test.go +++ b/daemon/config/config_test.go @@ -1,9 +1,10 @@ package config import ( - "testing" - + "fmt" + "github.com/spf13/pflag" "github.com/stretchr/testify/assert" + "testing" ) func TestIterateConfig(t *testing.T) { @@ -49,7 +50,28 @@ func TestConfigValidate(t *testing.T) { } func TestGetConflictConfigurations(t *testing.T) { - // TODO + assert := assert.New(t) + + fileFlags := map[string]interface{}{ + "flag1": "1", + "flag2": "2", + } + + flagSet := pflag.NewFlagSet("FlagConfig", pflag.ContinueOnError) + flagSet.String("flag1", "1", "flag1") + flagSet.String("flag2", "2", "flag2") + flagSet.String("flag3", "3", "flag3") + flagSet.IntSlice("slice", []int{1, 2, 3}, "slice data") + + assert.Equal(nil, getConflictConfigurations(flagSet, fileFlags)) + + flagSet.Set("flag1", "2") + assert.Equal(fmt.Errorf("found conflict flags in command line and config file: from flag: 2 and from config file: 1"), + getConflictConfigurations(flagSet, fileFlags)) + + flagSet.Set("flag2", "1") + assert.Equal(fmt.Errorf("found conflict flags in command line and config file: from flag: 2 and from config file: 1, from flag: 1 and from config file: 2"), + getConflictConfigurations(flagSet, fileFlags)) } func TestGetUnknownFlags(t *testing.T) { From 5aed1af582025c2162604cfcd1470bf4a76eea76 Mon Sep 17 00:00:00 2001 From: jiapengcs Date: Tue, 24 Jul 2018 11:26:35 +0800 Subject: [PATCH 2/2] fixes #1759 baiji-group=264-3 --- daemon/config/config_test.go | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/daemon/config/config_test.go b/daemon/config/config_test.go index d011292fc..14352bd42 100644 --- a/daemon/config/config_test.go +++ b/daemon/config/config_test.go @@ -1,10 +1,10 @@ package config import ( - "fmt" "github.com/spf13/pflag" "github.com/stretchr/testify/assert" "testing" + "errors" ) func TestIterateConfig(t *testing.T) { @@ -50,28 +50,26 @@ func TestConfigValidate(t *testing.T) { } func TestGetConflictConfigurations(t *testing.T) { - assert := assert.New(t) + assert := assert.New(t) - fileFlags := map[string]interface{}{ - "flag1": "1", - "flag2": "2", - } + fileFlags := map[string]interface{}{ + "flag1": "1", + "flag2": "2", + } - flagSet := pflag.NewFlagSet("FlagConfig", pflag.ContinueOnError) - flagSet.String("flag1", "1", "flag1") - flagSet.String("flag2", "2", "flag2") - flagSet.String("flag3", "3", "flag3") - flagSet.IntSlice("slice", []int{1, 2, 3}, "slice data") + flagSet := pflag.NewFlagSet("FlagConfig", pflag.ContinueOnError) + flagSet.String("flag1", "1", "flag1") + flagSet.String("flag2", "2", "flag2") + flagSet.String("flag3", "3", "flag3") + flagSet.IntSlice("slice", []int{1, 2, 3}, "slice data") - assert.Equal(nil, getConflictConfigurations(flagSet, fileFlags)) + assert.Equal(nil, getConflictConfigurations(flagSet, fileFlags)) - flagSet.Set("flag1", "2") - assert.Equal(fmt.Errorf("found conflict flags in command line and config file: from flag: 2 and from config file: 1"), - getConflictConfigurations(flagSet, fileFlags)) + flagSet.Set("flag1", "2") + assert.Equal(getConflictConfigurations(flagSet, fileFlags), errors.New("found conflict flags in command line and config file: from flag: 2 and from config file: 1")) - flagSet.Set("flag2", "1") - assert.Equal(fmt.Errorf("found conflict flags in command line and config file: from flag: 2 and from config file: 1, from flag: 1 and from config file: 2"), - getConflictConfigurations(flagSet, fileFlags)) + flagSet.Set("flag2", "1") + assert.Equal(getConflictConfigurations(flagSet, fileFlags), errors.New("found conflict flags in command line and config file: from flag: 2 and from config file: 1, from flag: 1 and from config file: 2")) } func TestGetUnknownFlags(t *testing.T) {