-
-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |