Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions pkg/provider/parse_options_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package provider

import (
"strings"
"testing"

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

func TestParseOptions(t *testing.T) {
cases := []struct {
name string
options []string
want map[string]string
wantErr string
}{
{
name: "empty input yields empty map",
options: []string{},
want: map[string]string{},
},
{
name: "single key value",
options: []string{"foo=bar"},
want: map[string]string{strings.ToUpper(testNameFoo): testNameBar},
},
{
name: "value containing equals is preserved",
options: []string{"foo=a=b"},
want: map[string]string{strings.ToUpper(testNameFoo): "a=b"},
},
{
name: "lowercase key is uppercased",
options: []string{"foo=bar"},
want: map[string]string{strings.ToUpper(testNameFoo): testNameBar},
},
{
name: "surrounding whitespace around key is trimmed",
options: []string{" foo =bar"},
want: map[string]string{strings.ToUpper(testNameFoo): testNameBar},
},
{
name: "multiple options are collected",
options: []string{"A=1", "B=two", "C="},
want: map[string]string{"A": "1", "B": "two", "C": ""},
},
{
name: "option without equals is rejected",
options: []string{strings.ToUpper(testNameFoo)},
wantErr: `invalid option "FOO", expected format KEY=VALUE`,
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got, err := ParseOptions(tc.options)
if tc.wantErr != "" {
require.EqualError(t, err, tc.wantErr)
require.Nil(t, got)
return
}
require.NoError(t, err)
require.Equal(t, tc.want, got)
})
}
}
1 change: 1 addition & 0 deletions pkg/provider/versions_testconst_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ const (
testTagV999 = "v9.9.9"
testNameABC = "abc"
testNameBar = "bar"
testNameFoo = "foo"
)
Loading