From 4d2332582355c0b4c70d7817e569139d502d97a1 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Tue, 17 May 2022 11:56:17 -0600 Subject: Implement cfg.BoolVar method --- srv/src/cfg/cfg_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'srv/src/cfg/cfg_test.go') diff --git a/srv/src/cfg/cfg_test.go b/srv/src/cfg/cfg_test.go index 7ccf94a..8266c89 100644 --- a/srv/src/cfg/cfg_test.go +++ b/srv/src/cfg/cfg_test.go @@ -44,3 +44,24 @@ func TestIntVar(t *testing.T) { assert.Equal(t, 222, bar) assert.Equal(t, 333, baz) } + +func TestBoolVar(t *testing.T) { + + cfg := New(Params{ + Args: []string{"--foo=1"}, + Env: map[string]string{"FOO": "0", "BAR": "anything", "BIZ": "0"}, + }) + + var foo, bar, baz, biz bool + + cfg.BoolVar(&foo, "foo", false, "") + cfg.BoolVar(&bar, "bar", false, "") + cfg.BoolVar(&baz, "baz", false, "") + cfg.BoolVar(&biz, "biz", true, "") + + assert.NoError(t, cfg.Init(context.Background())) + assert.Equal(t, true, foo) + assert.Equal(t, true, bar) + assert.Equal(t, false, baz) + assert.Equal(t, false, biz) +} -- cgit v1.2.3