-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringDbModel_test.go
More file actions
115 lines (95 loc) · 2.63 KB
/
stringDbModel_test.go
File metadata and controls
115 lines (95 loc) · 2.63 KB
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 go_orm
import "testing"
// Тест покрывает инициализацию объекта и метод GetCache
func TestStringDbModelInit(t *testing.T) {
v := StringDbModel{}
v.GetCache()
if !v.isInit {
t.Error("String Db Model should be inited before GetCache")
}
}
//Тест покрывает инициализацию объекта и методы FindInCache, AddToCache
func TestStringDbModelFindInCache(t *testing.T) {
testCases := []testStringDbModelPotok{
{true, "1"},
{false, "1"},
{true, "2"},
{false, "2"},
}
v := StringDbModel{}
res := v.FindInCache("1")
if !v.isInit {
t.Error("String Db Model should be inited before FindInCache")
}
if res != nil {
t.Error("Not empty result")
}
for _, tc := range testCases {
v.AddToCache(testStringDbModelPotok{tc.active, tc.id})
if !v.isInit {
t.Error("String Db Model should be inited before AddToCache")
}
res = v.FindInCache(tc.id)
if tc.IsActive() && res == nil {
t.Error("Empty result after put")
}
if !tc.IsActive() && res != nil {
t.Error("Not active result found in cache")
}
}
}
//Тест покрывает инициализацию объекта и методы FindInCache, AddToCache, ClearCache
func TestStringDbModelClearCache(t *testing.T) {
v := StringDbModel{}
v.AddToCache(testStringDbModelPotok{true, "1"})
if !v.isInit {
t.Error("String Db Model should be inited before AddToCache")
}
res := v.FindInCache("1")
if res == nil {
t.Error("Empty result after put")
}
res = v.FindInCache("2")
if res != nil {
t.Error("Found bad result")
}
v.ClearCache()
if v.Len() != 0 {
t.Error("Not empty result after clear")
}
}
//Проверка добавления двух значений с одинаковым id
func TestStringDbModel_AddToCacheDuplicate(t *testing.T) {
v := StringDbModel{}
testCases := []testStringDbModelPotok{
{true, "1"},
{true, "1"},
}
for _, tc := range testCases {
v.AddToCache(testStringDbModelPotok{tc.active, tc.id})
}
if v.Len() != 1 {
t.Error("Remove of duplicates crashed.")
}
}
func TestStringDbModel_ClearOutDated(t *testing.T) {
v := StringDbModel{}
testCases := []testStringDbModelPotok{
{true, "1"},
{true, "1"},
}
for _, tc := range testCases {
v.AddToCache(testStringDbModelPotok{tc.active, tc.id})
}
v.ClearOutDated()
if v.Len() != 0 {
t.Error("Outdated were not removed.")
}
}
type testStringDbModelPotok struct {
active bool
id string
}
func (m testStringDbModelPotok) IsActive() bool { return m.active }
func (m testStringDbModelPotok) GetId() string { return m.id }
func (m testStringDbModelPotok) OutDated() bool { return true }