Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix map of slices #102

Merged
merged 2 commits into from Aug 15, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions aconfig_test.go
Expand Up @@ -2,6 +2,7 @@ package aconfig

import (
"io/ioutil"
"net/url"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -1389,3 +1390,31 @@ func TestMapOfMap(t *testing.T) {
t.Fatalf("want %v, got %v", want, got)
}
}

func TestBad(t *testing.T) {
type TestConfig struct {
Params url.Values
}
var cfg TestConfig
os.Setenv("PARAMS", "foo:bar")
defer os.Unsetenv("PARAMS")

loader := LoaderFor(&cfg, Config{
SkipFlags: true,
})
if err := loader.Load(); err != nil {
t.Fatal(err)
}

p, err := url.ParseQuery("foo=bar")
if err != nil {
t.Fatal(err)
}
var want = TestConfig{
Params: p,
}

if got := cfg; !reflect.DeepEqual(want, got) {
t.Fatalf("want %v, got %v", want, got)
}
}
1 change: 1 addition & 0 deletions reflection.go
Expand Up @@ -320,6 +320,7 @@ func (l *Loader) setMap(field *fieldData, value string) error {
}

fdv := l.newSimpleFieldData(reflect.New(field.field.Type.Elem()).Elem())
fdv.field.Type = field.field.Type.Elem()
if err := l.setFieldData(fdv, val); err != nil {
return fmt.Errorf("incorrect map value %q: %w", val, err)
}
Expand Down