From eed10ce514f28e4acf772f76c92ca05eebec105f Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Thu, 5 May 2022 21:20:22 -0600 Subject: Fix various problems with the srv build --- srv/src/cfg/cfg_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 srv/src/cfg/cfg_test.go (limited to 'srv/src/cfg/cfg_test.go') diff --git a/srv/src/cfg/cfg_test.go b/srv/src/cfg/cfg_test.go new file mode 100644 index 0000000..7ccf94a --- /dev/null +++ b/srv/src/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) +} -- cgit v1.2.3