Skip to content

Commit

Permalink
Issue #138 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
darccio committed May 17, 2020
1 parent ea5937a commit cc5acfb
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions issue138_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package mergo

import (
"encoding/json"
"testing"
)

const issue138configuration string = `
{
"Port": 80
}
`

func TestIssue138(t *testing.T) {
type config struct {
Port uint16
}
type compatibleConfig struct {
Port float64
}

foo := make(map[string]interface{})
// encoding/json unmarshals numbers as float64
// https://golang.org/pkg/encoding/json/#Unmarshal
json.Unmarshal([]byte(issue138configuration), &foo)

err := Map(&config{}, foo)
if err == nil {
t.Fatal("expected type mismatch error, got nil")
} else {
if err.Error() != "type mismatch on Port field: found float64, expected uint16" {
t.Fatalf("expected type mismatch error, got %q", err)
}
}

c := compatibleConfig{}
if err := Map(&c, foo); err != nil {
t.Fatal(err)
}
}

0 comments on commit cc5acfb

Please sign in to comment.