-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautomapper_test.go
72 lines (59 loc) · 1.19 KB
/
automapper_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package restutils
import (
"testing"
"reflect"
"fmt"
)
// Embedded struct for source
type ES struct {
CS string // common
I int
}
// Embedded struct for destination
type ED struct {
CS string // common
II int
}
// Source
type S struct {
S1 string
CI int // common
CS string // common
CSL []string // common
CIL []int // common
ES ES // partially common
}
// Destination
type D struct {
D1 string
CI int // common
CS string // common
CSL []string // common
CIL []int // common
ES ED // partially common
}
func TestBasic(t *testing.T) {
source := S{"S1", 1, "CS", []string{"l1"}, []int{1}, ES{"CES", 1}}
dest := D{D1:"D1", ES:ED{II:2}}
// Mapping source to dest results in this structure
expected := D{"D1", 1, "CS", []string{"l1"}, []int{1}, ED{"CES", 2}}
Mapper(&source, &dest)
// compare
if reflect.DeepEqual(dest, expected) == false {
t.Error("mapping failed: expected=", expected, ", got", dest)
}
}
type Source struct {
SourceOnly string
Common string
}
type Destination struct {
DestinationOnly int
Common string
}
func TestExample(t *testing.T) {
s := &Source{"SourceOnly", "Common"}
d := &Destination{DestinationOnly:1}
Mapper(s, d)
fmt.Println(d)
}