...
1 package mergo_test
2
3 import (
4 "encoding/json"
5 "testing"
6
7 "github.com/imdario/mergo"
8 )
9
10 const issue138configuration string = `
11 {
12 "Port": 80
13 }
14 `
15
16 func TestIssue138(t *testing.T) {
17 type config struct {
18 Port uint16
19 }
20 type compatibleConfig struct {
21 Port float64
22 }
23
24 foo := make(map[string]interface{})
25
26
27 json.Unmarshal([]byte(issue138configuration), &foo)
28
29 err := mergo.Map(&config{}, foo)
30 if err == nil {
31 t.Error("expected type mismatch error, got nil")
32 } else {
33 if err.Error() != "type mismatch on Port field: found float64, expected uint16" {
34 t.Errorf("expected type mismatch error, got %q", err)
35 }
36 }
37
38 c := compatibleConfig{}
39 if err := mergo.Map(&c, foo); err != nil {
40 t.Error(err)
41 }
42 }
43
View as plain text