Skip to content

Commit

Permalink
Fixed unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: ItalyPaleAle <[email protected]>
  • Loading branch information
ItalyPaleAle committed Aug 3, 2023
1 parent 5bbd69d commit ca8fcbd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 6 additions & 2 deletions metadata/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,13 @@ func resolveAliases(md map[string]string, result any) error {
keys[lk] = k
}

// Return if result is not struct or pointer to struct
// Error if result is not pointer to struct, or pointer to pointer to struct
t := reflect.TypeOf(result)
if t.Kind() == reflect.Ptr {
if t.Kind() != reflect.Pointer {
return fmt.Errorf("not a pointer: %s", t.Kind().String())
}
t = t.Elem()
if t.Kind() == reflect.Pointer {
t = t.Elem()
}
if t.Kind() != reflect.Struct {
Expand Down
12 changes: 6 additions & 6 deletions metadata/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func TestResolveAliases(t *testing.T) {
"hello": "world",
"ciao": "mondo",
},
result: struct {
result: &struct {
Hello string `mapstructure:"hello"`
Ciao string `mapstructure:"ciao"`
Bonjour string `mapstructure:"bonjour"`
Expand All @@ -343,7 +343,7 @@ func TestResolveAliases(t *testing.T) {
md: map[string]string{
"ciao": "mondo",
},
result: struct {
result: &struct {
Hello string `mapstructure:"hello" mapstructurealiases:"ciao"`
Bonjour string `mapstructure:"bonjour"`
}{},
Expand All @@ -358,7 +358,7 @@ func TestResolveAliases(t *testing.T) {
"hello": "world",
"ciao": "mondo",
},
result: struct {
result: &struct {
Hello string `mapstructure:"hello" mapstructurealiases:"ciao"`
Bonjour string `mapstructure:"bonjour"`
}{},
Expand All @@ -372,7 +372,7 @@ func TestResolveAliases(t *testing.T) {
md: map[string]string{
"bonjour": "monde",
},
result: struct {
result: &struct {
Hello string `mapstructure:"hello" mapstructurealiases:"ciao"`
Bonjour string `mapstructure:"bonjour"`
}{},
Expand All @@ -385,7 +385,7 @@ func TestResolveAliases(t *testing.T) {
md: map[string]string{
"bonjour": "monde",
},
result: struct {
result: &struct {
Hello string `mapstructure:"hello" mapstructurealiases:"ciao,bonjour"`
}{},
wantMd: map[string]string{
Expand All @@ -399,7 +399,7 @@ func TestResolveAliases(t *testing.T) {
"ciao": "mondo",
"bonjour": "monde",
},
result: struct {
result: &struct {
Hello string `mapstructure:"hello" mapstructurealiases:"ciao,bonjour"`
}{},
wantMd: map[string]string{
Expand Down

0 comments on commit ca8fcbd

Please sign in to comment.