Skip to content

Commit

Permalink
chore(cli): extend tests for CLI to capture how flags with - are in…
Browse files Browse the repository at this point in the history
… configs

the config for a daemon should use keys that match the flags of the
daemon it is provided too.
  • Loading branch information
jsteenb2 committed Jun 17, 2020
1 parent aa1e29f commit ce6827c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion kit/cli/viper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -110,7 +111,9 @@ func ExampleNewCommand() {

func Test_NewProgram(t *testing.T) {
testFilePath, cleanup := newConfigFile(t, map[string]string{
"FOO": "bar",
// config values should be same as flags
"foo": "bar",
"shoe-fly": "yadon",
})
defer cleanup()
defer setEnvVar("TEST_CONFIG_FILE", testFilePath)()
Expand Down Expand Up @@ -150,6 +153,7 @@ func Test_NewProgram(t *testing.T) {
}

var testVar string
var testFly string
program := &Program{
Name: "test",
Opts: []Opt{
Expand All @@ -158,6 +162,10 @@ func Test_NewProgram(t *testing.T) {
Flag: "foo",
Required: true,
},
{
DestP: &testFly,
Flag: "shoe-fly",
},
},
Run: func() error { return nil },
}
Expand All @@ -167,6 +175,7 @@ func Test_NewProgram(t *testing.T) {
require.NoError(t, cmd.Execute())

require.Equal(t, tt.expected, testVar)
assert.Equal(t, "yadon", testFly)
}

t.Run(tt.name, fn)
Expand Down

0 comments on commit ce6827c

Please sign in to comment.