diff options
author | Brian Picciano <mediocregopher@gmail.com> | 2022-05-05 20:17:59 -0600 |
---|---|---|
committer | Brian Picciano <mediocregopher@gmail.com> | 2022-05-05 20:30:36 -0600 |
commit | 5c247b6f2907e8c4da5a66fa2192fcba95e100f2 (patch) | |
tree | f5462cd7b31181d7b0217cb899c49e0ae5790e53 /srv/cfg/cfg_test.go | |
parent | 0277c0276715d326a4bcf2be37d2aec5982078f7 (diff) |
Refactor cfg to use envvars as well
Diffstat (limited to 'srv/cfg/cfg_test.go')
-rw-r--r-- | srv/cfg/cfg_test.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/srv/cfg/cfg_test.go b/srv/cfg/cfg_test.go new file mode 100644 index 0000000..7ccf94a --- /dev/null +++ b/srv/cfg/cfg_test.go @@ -0,0 +1,46 @@ +package cfg + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestStringVar(t *testing.T) { + + cfg := New(Params{ + Args: []string{"--foo=CLI"}, + Env: map[string]string{"FOO": "ENV", "BAR": "ENV"}, + }) + + var foo, bar, baz string + + cfg.StringVar(&foo, "foo", "DEF", "") + cfg.StringVar(&bar, "bar", "DEF", "") + cfg.StringVar(&baz, "baz", "DEF", "") + + assert.NoError(t, cfg.Init(context.Background())) + assert.Equal(t, "CLI", foo) + assert.Equal(t, "ENV", bar) + assert.Equal(t, "DEF", baz) +} + +func TestIntVar(t *testing.T) { + + cfg := New(Params{ + Args: []string{"--foo=111"}, + Env: map[string]string{"FOO": "222", "BAR": "222"}, + }) + + var foo, bar, baz int + + cfg.IntVar(&foo, "foo", 333, "") + cfg.IntVar(&bar, "bar", 333, "") + cfg.IntVar(&baz, "baz", 333, "") + + assert.NoError(t, cfg.Init(context.Background())) + assert.Equal(t, 111, foo) + assert.Equal(t, 222, bar) + assert.Equal(t, 333, baz) +} |