Skip to content

Commit

Permalink
add unit-test for daemon/config/getUnknownFlags
Browse files Browse the repository at this point in the history
Signed-off-by: Erhuan <553614753@qq.com>
  • Loading branch information
cyrann committed Jul 24, 2018
1 parent 2f0b5cf commit 965b7ae
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion daemon/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"testing"

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

Expand Down Expand Up @@ -53,5 +54,44 @@ func TestGetConflictConfigurations(t *testing.T) {
}

func TestGetUnknownFlags(t *testing.T) {
// TODO

flagSet := new(pflag.FlagSet)
flagSet.String("a", "a", "a")
flagSet.Bool("b", false, "b")
flagSet.Int("c", -500, "c")

flagSetNil := new(pflag.FlagSet)

assert := assert.New(t)

fileFlagsKnown := map[string]interface{}{
"a": "a",
"b": true,
}

fileFlagsUnknown := map[string]interface{}{
"c": 100,
"d": "d",
}

fileFlagsNil := map[string]interface{}{}

error := getUnknownFlags(flagSet, fileFlagsKnown)
assert.Equal(error, nil)

error = getUnknownFlags(flagSet, fileFlagsUnknown)
assert.NotNil(error)

error = getUnknownFlags(flagSet, fileFlagsNil)
assert.Equal(error, nil)

error = getUnknownFlags(flagSetNil, fileFlagsUnknown)
assert.NotNil(error)

error = getUnknownFlags(flagSetNil, fileFlagsKnown)
assert.NotNil(error)

error = getUnknownFlags(flagSetNil, fileFlagsNil)
assert.Equal(error, nil)

}

0 comments on commit 965b7ae

Please sign in to comment.