-
Notifications
You must be signed in to change notification settings - Fork 2
/
ore_test.go
115 lines (95 loc) · 2.41 KB
/
ore_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
110
111
112
113
114
115
package ore
import (
"testing"
"github.com/firasdarwish/ore/internal/interfaces"
"github.com/firasdarwish/ore/internal/models"
"github.com/stretchr/testify/assert"
)
func TestSeal(t *testing.T) {
clearAll()
RegisterCreator[interfaces.SomeCounter](Scoped, &models.SimpleCounter{})
Seal()
assert.Panics(t, func() {
RegisterCreator[interfaces.SomeCounter](Scoped, &models.SimpleCounter{})
})
}
func TestIsSeal(t *testing.T) {
clearAll()
RegisterCreator[interfaces.SomeCounter](Scoped, &models.SimpleCounter{})
if got := IsSealed(); got != false {
t.Errorf("IsSealed() = %v; want %v", got, false)
}
Seal()
if got := IsSealed(); got != true {
t.Errorf("IsSealed() = %v; want %v", got, true)
}
}
func TestContainerName(t *testing.T) {
if got := Name(); got != "DEFAULT" {
t.Errorf("Name() = %v; want %v", got, "DEFAULT")
}
}
func TestContainerSetName(t *testing.T) {
con := NewContainer().SetName("ORE")
if got := con.Name(); got != "ORE" {
t.Errorf("Name() = %v; want %v", got, "ORE")
}
}
func TestNewContainerName(t *testing.T) {
con := NewContainer()
if got := con.Name(); got != "" {
t.Errorf("Name() = `%v`; want `%v`", got, "")
}
}
func TestContainerReSetName(t *testing.T) {
con := NewContainer().SetName("ORE")
assert.Panics(t, func() {
con.SetName("ORE1")
})
}
func TestContainerID(t *testing.T) {
if got := ContainerID(); got != 1 {
t.Errorf("ContainerID() = %v; want 1", got)
}
}
func TestNewContainerIDSerial(t *testing.T) {
clearAll()
con := NewContainer()
if got := con.ContainerID(); got < 2 {
t.Errorf("ContainerID() = %v; want >= 2", got)
}
}
type A1 struct{}
type A2 struct{}
func TestTypeIdentifierNilkey(t *testing.T) {
id1 := typeIdentifier[*A1](nilKey)
id2 := typeIdentifier[*A1](0)
//nilKey looks like 0 but it is not equal 0
assert.NotEqual(t, id1, id2)
id21 := typeIdentifier[*A1](0)
assert.Equal(t, id2, id21)
id3 := typeIdentifier[*A1]("a")
id4 := typeIdentifier[*A1]("a")
assert.Equal(t, id3, id4)
}
func TestTypeIdentifierComplexKey(t *testing.T) {
key1 := contextKey{
typeID: typeID{
pointerTypeName: "toto",
oreKey: models.Trader{Name: "Hiep"},
},
containerID: 1,
resolverID: 2,
}
key2 := contextKey{
typeID: typeID{
pointerTypeName: "toto",
oreKey: models.Trader{Name: "Hiep"},
},
containerID: 1,
resolverID: 2,
}
id1 := typeIdentifier[A1](key1)
id2 := typeIdentifier[A1](key2)
assert.Equal(t, id1, id2)
}