Skip to content

Commit

Permalink
Better struct assert (#97)
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Kovalov <oleg@hey.com>
  • Loading branch information
cristaloleg committed Jul 17, 2021
1 parent 0d4c5d9 commit 5ae6b2e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion aconfig_test.go
Expand Up @@ -1061,7 +1061,7 @@ func TestDontFillFlagsIfDisabled(t *testing.T) {
}
}

func TestPassNonStructs(t *testing.T) {
func TestPassBadStructs(t *testing.T) {
f := func(cfg interface{}) {
t.Helper()

Expand All @@ -1080,6 +1080,11 @@ func TestPassNonStructs(t *testing.T) {
f([]string{})
f([4]string{})
f(func() {})

type S struct {
Foo int
}
f(S{})
}

func TestBadRequiredTag(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions utils.go
Expand Up @@ -15,6 +15,9 @@ func assertStruct(x interface{}) {
panic("aconfig: nil should not be passed to the Loader")
}
value := reflect.ValueOf(x)
if value.Type().Kind() != reflect.Ptr {
panic("aconfig: destination must be a pointer")
}
for value.Type().Kind() == reflect.Ptr {
value = value.Elem()
}
Expand Down

0 comments on commit 5ae6b2e

Please sign in to comment.