Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
atburke committed Sep 22, 2023
1 parent 8de80ba commit 0464480
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4690,7 +4690,7 @@ func ParseJoinParamsSpec(spec string) (map[string]string, error) {

// parseKeyValueSpec parses a string like 'name=value,"long name"="quoted value"` into a map like
// { "name" -> "value", "long name" -> "quoted value" }
func parseKeyValueSpec(spec, name string) (map[string]string, error) {
func parseKeyValueSpec(spec, specKind string) (map[string]string, error) {
var tokens []string
openQuotes := false
var tokenStart, assignCount int
Expand Down Expand Up @@ -4722,7 +4722,7 @@ func parseKeyValueSpec(spec, name string) (map[string]string, error) {
// simple validation of tokenization: must have an even number of tokens (because they're pairs)
// and the number of such pairs must be equal the number of assignments
if len(tokens)%2 != 0 || assignCount != len(tokens)/2 {
return nil, fmt.Errorf("invalid %s spec: '%s', should be 'key=value'", name, spec)
return nil, fmt.Errorf("invalid %s spec: '%s', should be 'key=value'", specKind, spec)
}
// break tokens in pairs and put into a map:
values := make(map[string]string)
Expand Down
15 changes: 15 additions & 0 deletions lib/config/fileconf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,21 @@ func TestMakeSampleFileConfig(t *testing.T) {
require.Error(t, err)
})

t.Run("Join Params - Azure client ID", func(t *testing.T) {
fc, err := MakeSampleFileConfig(SampleFlags{
JoinParams: "azure_client_id=abcd1234",
})
require.NoError(t, err)
require.Equal(t, "abcd1234", fc.JoinParams.Azure.ClientID)
})

t.Run("Join Params - invalid", func(t *testing.T) {
_, err := MakeSampleFileConfig(SampleFlags{
JoinParams: "azure_client_id=abcd,1234",
})
require.Error(t, err)
})

t.Run("CAPin", func(t *testing.T) {
fc, err := MakeSampleFileConfig(SampleFlags{
CAPin: "sha256:7e12c17c20d9cb",
Expand Down

0 comments on commit 0464480

Please sign in to comment.