Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add unit-test for daemon/config/getUnknownFlags #1808

Merged
merged 1 commit into from
Jul 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove redundant blank line here @cyrann

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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here

}