-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgosingleton_test.go
57 lines (49 loc) · 1015 Bytes
/
gosingleton_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
package gosingleton
import (
"sync"
"testing"
)
type Person struct {
Name string
Age int
}
func testReg(t *testing.T) {
RegisterType("person", GetTypeInfo(Person{}))
}
func testGetInst1(t *testing.T) {
v := GetInstance("person").(*Person)
t.Log(v.Age == 0)
t.Log(v.Name == "")
v.Name = "fuck"
v.Age = 100
}
func testGetInst2(t *testing.T) {
v := GetInstance("person").(*Person)
t.Log(v.Age == 100)
t.Log(v.Name == "fuck")
}
func testGetInst3(t *testing.T) {
var wg sync.WaitGroup
wg.Add(2)
go func() {
v := GetInstance("person").(*Person)
v.Name = "fuck1"
v.Age = 101
wg.Done()
}()
go func() {
v := GetInstance("person").(*Person)
t.Log("-------------------1")
t.Log(v.Name)
t.Log(v.Age)
t.Log("-------------------2")
wg.Done()
}()
wg.Wait()
}
func TestAll(t *testing.T) {
t.Run("Reg", testReg)
t.Run("testGetInst1", testGetInst1)
t.Run("testGetInst2", testGetInst2)
t.Run("testGetInst3", testGetInst3)
}