-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfactory_map_test.go
109 lines (89 loc) · 2.88 KB
/
factory_map_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2021 Harold Campbell. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package salem_test
import (
"go-salem"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
type mapSuite struct {
suite.Suite
}
func Test_FactoryMap(t *testing.T) {
suite.Run(t, new(mapSuite))
}
func (s *mapSuite) Test_primative_types_map() {
type human struct {
Genes map[string]string // gene[name] -> (DNA string sequence)
VacationDays map[int]int // month -> days off
}
result := salem.Mock(human{}).
ExecuteToType().([]human)[0]
t := s.T()
assert.NotEmpty(t, result.Genes, "should create string map")
assert.Equal(t, 1, len(result.Genes), "should map with 1 item")
assert.NotEmpty(t, result.VacationDays, "should create numeric map")
assert.Equal(t, 1, len(result.VacationDays), "should map with 1 item")
}
func (s *mapSuite) Test_map_of_structs() {
type dna struct {
Sequence string
PatentHolder string
IsManMadeSequence *bool
}
type human struct {
Genes map[string]dna // gene -> DNA sequence
}
result := salem.Mock(human{}).
ExecuteToType().([]human)[0]
t := s.T()
assert.NotEmpty(t, result.Genes, "should create string map")
assert.Equal(t, 1, len(result.Genes), "should map with 1 item")
keys := []string{}
for key := range result.Genes {
keys = append(keys, key)
}
item := result.Genes[keys[0]]
assert.NotEmpty(t, item.Sequence, "should create nested Sequence")
assert.NotEmpty(t, item.PatentHolder, "should create nested PatentHolder")
assert.NotNil(t, item.IsManMadeSequence, "should create nested IsManMadeSequence")
}
func (s *mapSuite) Test_map_of_slices() {
type dna struct {
Sequence string
PatentHolder string
IsManMadeSequence *bool
}
type human struct {
Genes map[string][]dna // gene -> DNA sequence
}
result := salem.Mock(human{}).
ExecuteToType().([]human)[0]
t := s.T()
assert.NotEmpty(t, result.Genes, "should create string map")
assert.Equal(t, 1, len(result.Genes), "should map with 1 item")
keys := []string{}
for key := range result.Genes {
keys = append(keys, key)
}
item := result.Genes[keys[0]]
assert.Equal(t, 1, len(item), "should create slice")
assert.NotEmpty(t, item[0].Sequence, "should create nested Sequence")
assert.NotEmpty(t, item[0].PatentHolder, "should create nested PatentHolder")
assert.NotNil(t, item[0].IsManMadeSequence, "should create nested IsManMadeSequence")
}
func (s *mapSuite) test_map_of_maps() {
type part struct {
Name string // Exon | Intron | Exon
}
type human struct {
Genes map[string]map[string]part // gene[name] -> (part[key]-> part)
}
result := salem.Mock(human{}).
ExecuteToType().([]human)[0]
t := s.T()
assert.NotEmpty(t, result.Genes, "should create string map")
assert.Equal(t, 1, len(result.Genes), "should map with 1 item")
}