diff options
| author | Philipp Tanlak <philipp.tanlak@gmail.com> | 2023-11-18 22:49:26 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-18 22:49:26 +0100 |
| commit | 6aa52bdbe2cefdbc9219abfb4399afa0d492913d (patch) | |
| tree | 02c743b7d9393dbf024e14adada73c6594bdd34a /cmd/args_test.go | |
| parent | 94da9293f63e46712b0a890e1e0eab4153fdb3f9 (diff) | |
Support passing config options as CLI arguments (#15)
Diffstat (limited to 'cmd/args_test.go')
| -rw-r--r-- | cmd/args_test.go | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/cmd/args_test.go b/cmd/args_test.go new file mode 100644 index 0000000..3153fd8 --- /dev/null +++ b/cmd/args_test.go @@ -0,0 +1,75 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +package cmd + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestParseConfigUpdates(t *testing.T) { + tests := []struct { + flags string + err bool + updates map[string]any + }{ + { + flags: `--foo bar`, + updates: map[string]any{"foo": "bar"}, + }, + { + flags: `--foo=bar`, + updates: map[string]any{"foo": "bar"}, + }, + { + flags: `--foo`, + updates: map[string]any{"foo": true}, + }, + { + flags: `--foo false`, + updates: map[string]any{"foo": false}, + }, + { + flags: `--foo a --foo b`, + updates: map[string]any{"foo": []any{"a", "b"}}, + }, + { + flags: `--foo a --foo=b`, + updates: map[string]any{"foo": []any{"a", "b"}}, + }, + { + flags: `--foo 69`, + updates: map[string]any{"foo": 69}, + }, + { + flags: `--foo.bar a`, + updates: map[string]any{"foo.bar": "a"}, + }, + { + flags: `foo`, + err: true, + }, + { + flags: `--foo a b`, + err: true, + }, + } + for _, test := range tests { + t.Run(test.flags, func(t *testing.T) { + args, err := parseConfigArgs(strings.Fields(test.flags)) + + if test.err { + require.Error(t, err) + require.Empty(t, args) + return + } + + require.NoError(t, err) + require.Equal(t, test.updates, args) + }) + } +} |