Skip to content

Commit

Permalink
Merge pull request #1851 from SeaRise/fafafa
Browse files Browse the repository at this point in the history
add unit-test for daemon/config/getConfigurations team4
  • Loading branch information
allencloud authored Jul 24, 2018
2 parents 8272bb3 + a9a4cb0 commit 34ebc3f
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion daemon/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"github.com/spf13/pflag"
"github.com/stretchr/testify/assert"

"github.com/spf13/pflag"
)

func TestIterateConfig(t *testing.T) {
Expand Down Expand Up @@ -50,7 +52,33 @@ func TestConfigValidate(t *testing.T) {
}

func TestGetConflictConfigurations(t *testing.T) {
// TODO
assert := assert.New(t)

fileflags := map[string]interface{}{
"a": "a1",
"b": []string{"b1", "b2"},
}

flags := pflag.NewFlagSet("cmflags", pflag.ContinueOnError)

// Test No Flags
assert.Equal(nil, getConflictConfigurations(flags, fileflags))

flags.String("c", "c1", "c")
// Test No Conflicts
flags.Parse([]string{"--c=c1"})
assert.Equal(nil, getConflictConfigurations(flags, fileflags))

// Test Ignore Conflict of Type "Slice"
flags.StringSlice("b", []string{"b1", "b2"}, "b")
flags.Parse([]string{"--b=b1,b2"})
assert.Equal(nil, getConflictConfigurations(flags, fileflags))

// Test Conflict
flags.String("a", "a1", "a")
flags.Parse([]string{"--a=a1"})
assert.Equal("found conflict flags in command line and config file: from flag: a1 and from config file: a1",
getConflictConfigurations(flags, fileflags).Error())
}

func TestGetUnknownFlags(t *testing.T) {
Expand Down

0 comments on commit 34ebc3f

Please sign in to comment.