Skip to content

Commit d06473a

Browse files
Merge pull request #34 from qa-dev/fix_tests
fix tests
2 parents e2f8bac + 3b218e7 commit d06473a

File tree

6 files changed

+67
-49
lines changed

6 files changed

+67
-49
lines changed

pool/capabilities/comparator_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func TestComparator_Compare(t *testing.T) {
6565

6666
comp := NewComparator()
6767
for i, test := range dataProvider {
68+
comp.Register(test.available)
6869
result := comp.Compare(test.required, test.available)
6970
assert.Equal(t, test.expectedResult, result, "Test #"+strconv.Itoa(i))
7071
}

pool/pool_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,18 @@ func TestPool_fixNodeStatus_NegativeReserved(t *testing.T) {
299299
a.Error(err)
300300
}
301301

302+
func TestPool_SetBusyNodeDuration(t *testing.T) {
303+
expected := time.Second
304+
p := NewPool(nil, nil)
305+
p.SetBusyNodeDuration(expected)
306+
assert.Equal(t, expected, p.busyNodeDuration)
307+
}
308+
309+
func TestPool_SetReservedNodeDuration(t *testing.T) {
310+
expected := time.Second
311+
p := NewPool(nil, nil)
312+
p.SetReservedNodeDuration(expected)
313+
assert.Equal(t, expected, p.reservedNodeDuration)
314+
}
315+
302316
//---------------------------------

pool/strategy/persistent/nodeHelper_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ func TestNodeHelper_removeAllSessions_Negative_Sessions_Error(t *testing.T) {
5151

5252
func TestNodeHelper_removeAllSessions_Negative_Sessions_MessageStatusNotOk(t *testing.T) {
5353
cm := new(jsonwire.ClientMock)
54+
cm.On("Address").Return("0.0.0.0")
5455
nodeHelper := &nodeHelper{cm}
5556
sessions := new(jsonwire.Sessions)
5657
sessions.Status = 99999
57-
cm.On("Sessions").Return(new(jsonwire.Sessions), errors.New("Err"))
58+
cm.On("Sessions").Return(sessions, nil)
5859
_, err := nodeHelper.removeAllSessions()
5960
assert.NotNil(t, err)
6061
}
@@ -78,6 +79,7 @@ func TestNodeHelper_removeAllSessions_Negative_CloseSession_Error(t *testing.T)
7879

7980
func TestNodeHelper_removeAllSessions_Negative_CloseSession_MessageStatusNotOk(t *testing.T) {
8081
cm := new(jsonwire.ClientMock)
82+
cm.On("Address").Return("0.0.0.0")
8183
nodeHelper := &nodeHelper{cm}
8284
sessions := new(jsonwire.Sessions)
8385
sessions.Value = []struct {
@@ -89,7 +91,7 @@ func TestNodeHelper_removeAllSessions_Negative_CloseSession_MessageStatusNotOk(t
8991
cm.On("Sessions").Return(sessions, nil)
9092
message := new(jsonwire.Message)
9193
message.Status = 999999
92-
cm.On("CloseSession", mock.AnythingOfType("string")).Return(message, errors.New("Err"))
94+
cm.On("CloseSession", mock.AnythingOfType("string")).Return(message, nil)
9395
_, err := nodeHelper.removeAllSessions()
9496
assert.NotNil(t, err)
9597
}

pool/strategy/persistent/strategy_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ func TestStrategy_Reserve_Negative_NotMatchCapabilities(t *testing.T) {
7171
func TestStrategy_Reserve_Negative_ReserveAvailable(t *testing.T) {
7272
sm := new(pool.StorageMock)
7373
eError := errors.New("Error")
74-
sm.On("GetAll").Return([]pool.Node{{}}, nil)
74+
sm.On("GetAll").Return([]pool.Node{{CapabilitiesList: []capabilities.Capabilities{{}}}}, nil)
7575
cm := new(capabilities.ComparatorMock)
76+
cm.On("Register", mock.AnythingOfType("capabilities.Capabilities")).Return()
7677
cm.On("Compare", mock.AnythingOfType("capabilities.Capabilities"), mock.AnythingOfType("capabilities.Capabilities")).Return(true)
77-
sm.On("ReserveAvailable", mock.AnythingOfType("[]pool.Node")).Return([]pool.Node{}, eError)
78+
sm.On("ReserveAvailable", mock.AnythingOfType("[]pool.Node")).Return(pool.Node{}, eError)
7879
s := Strategy{storage: sm, capsComparator: cm}
7980
_, err := s.Reserve(capabilities.Capabilities{})
8081
assert.NotNil(t, err)

storage/tests/mysql_test.go renamed to storage/mysql/mysql_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tests
1+
package mysql
22

33
import (
44
"crypto/rand"
@@ -7,7 +7,7 @@ import (
77
_ "github.com/go-sql-driver/mysql"
88
"github.com/jmoiron/sqlx"
99
"github.com/qa-dev/jsonwire-grid/pool"
10-
"github.com/qa-dev/jsonwire-grid/storage/mysql"
10+
"github.com/qa-dev/jsonwire-grid/storage/tests"
1111
"github.com/rubenv/sql-migrate"
1212
"os"
1313
"strings"
@@ -75,7 +75,7 @@ func (p PrepareMysql) CreateStorage() (pool.StorageInterface, func()) {
7575
panic("Migrations failed, " + err.Error())
7676
}
7777

78-
storage := mysql.NewMysqlStorage(db)
78+
storage := NewMysqlStorage(db)
7979
if err != nil {
8080
panic("Error initialisation storage: " + err.Error())
8181
}
@@ -96,72 +96,72 @@ func TestMain(m *testing.M) {
9696

9797
// TestMysqlStorage_Add see testStorage_Add
9898
func TestMysqlStorage_Add(t *testing.T) {
99-
testStorage_Add(t, mv)
99+
tests.TestStorage_Add(t, mv)
100100
}
101101

102102
// TestMysqlStorage_Add_Repeat see testStorage_Add_Repeat
103103
func TestMysqlStorage_Add_Repeat(t *testing.T) {
104-
testStorage_Add_Repeat(t, mv)
104+
tests.TestStorage_Add_Repeat(t, mv)
105105

106106
}
107107

108108
// TestStorage_Add_Limit_Overflow see testStorage_Add_Limit_Overflow
109109
func TestStorage_Add_Limit_Overflow(t *testing.T) {
110-
testStorage_Add_Limit_Overflow(t, mv)
110+
tests.TestStorage_Add_Limit_Overflow(t, mv)
111111

112112
}
113113

114114
// TestMysqlStorage_GetAll see testStorage_GetAll
115115
func TestMysqlStorage_GetAll(t *testing.T) {
116-
testStorage_GetAll(t, mv)
116+
tests.TestStorage_GetAll(t, mv)
117117
}
118118

119119
// TestMysqlStorage_GetByAddress see testStorage_GetByAddress
120120
func TestMysqlStorage_GetByAddress(t *testing.T) {
121-
testStorage_GetByAddress(t, mv)
121+
tests.TestStorage_GetByAddress(t, mv)
122122
}
123123

124124
// TestMysqlStorage_GetBySession see testStorage_GetBySession
125125
func TestMysqlStorage_GetBySession(t *testing.T) {
126-
testStorage_GetBySession(t, mv)
126+
tests.TestStorage_GetBySession(t, mv)
127127
}
128128

129129
// TestMysqlStorage_GetCountWithStatus see testStorage_GetCountWithStatus
130130
func TestMysqlStorage_GetCountWithStatus(t *testing.T) {
131-
testStorage_GetCountWithStatus(t, mv)
131+
tests.TestStorage_GetCountWithStatus(t, mv)
132132
}
133133

134134
// TestMysqlStorage_Remove see testStorage_Remove
135135
func TestMysqlStorage_Remove(t *testing.T) {
136-
testStorage_Remove(t, mv)
136+
tests.TestStorage_Remove(t, mv)
137137
}
138138

139139
// TestMysqlStorage_ReserveAvailable_Positive see testStorage_ReserveAvailable_Positive
140140
func TestMysqlStorage_ReserveAvailable_Positive(t *testing.T) {
141-
testStorage_ReserveAvailable_Positive(t, mv)
141+
tests.TestStorage_ReserveAvailable_Positive(t, mv)
142142
}
143143

144144
// TestMysqlStorage_ReserveAvailable_Negative see testStorage_ReserveAvailable_Negative
145145
func TestMysqlStorage_ReserveAvailable_Negative(t *testing.T) {
146-
testStorage_ReserveAvailable_Negative(t, mv)
146+
tests.TestStorage_ReserveAvailable_Negative(t, mv)
147147
}
148148

149149
// TestMysqlStorage_SetAvailable see testStorage_SetAvailable
150150
func TestMysqlStorage_SetAvailable(t *testing.T) {
151-
testStorage_SetAvailable(t, mv)
151+
tests.TestStorage_SetAvailable(t, mv)
152152
}
153153

154154
// TestMysqlStorage_SetBusy see testStorage_SetBusy
155155
func TestMysqlStorage_SetBusy(t *testing.T) {
156-
testStorage_SetBusy(t, mv)
156+
tests.TestStorage_SetBusy(t, mv)
157157
}
158158

159159
// TestMysqlStorage_UpdateAdderss_UpdatesValue see testStorage_UpdateAdderss_UpdatesValue
160160
func TestMysqlStorage_UpdateAdderss_UpdatesValue(t *testing.T) {
161-
testStorage_UpdateAdderss_UpdatesValue(t, mv)
161+
tests.TestStorage_UpdateAdderss_UpdatesValue(t, mv)
162162
}
163163

164164
// TestMysqlStorage_UpdateAdderss_ReturnsErrNotFound see testStorage_UpdateAdderss_ReturnsErrNotFound
165165
func TestMysqlStorage_UpdateAdderss_ReturnsErrNotFound(t *testing.T) {
166-
testStorage_UpdateAdderss_ReturnsErrNotFound(t, mv)
166+
tests.TestStorage_UpdateAdderss_ReturnsErrNotFound(t, mv)
167167
}

storage/tests/comon_test.go renamed to storage/tests/comon.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ type PrepareInterface interface {
1616
CreateStorage() (pool.StorageInterface, func())
1717
}
1818

19-
// testStorage_Add проверка корректости добавления ноды в хранилище
20-
func testStorage_Add(t *testing.T, p PrepareInterface) {
19+
// TestStorage_Add проверка корректости добавления ноды в хранилище
20+
func TestStorage_Add(t *testing.T, p PrepareInterface) {
2121
t.Parallel()
2222

2323
storage, deferFunc := p.CreateStorage()
@@ -50,8 +50,8 @@ func testStorage_Add(t *testing.T, p PrepareInterface) {
5050
//assert.Equal(t, expectedNode.CapabilitiesList, nodeList[0].CapabilitiesList) //todo: доделать
5151
}
5252

53-
// testStorage_Add_Repeat проверка того что при повторном добавлении ноды вместо дублирования происходит корректный апдейт
54-
func testStorage_Add_Repeat(t *testing.T, p PrepareInterface) {
53+
// TestStorage_Add_Repeat проверка того что при повторном добавлении ноды вместо дублирования происходит корректный апдейт
54+
func TestStorage_Add_Repeat(t *testing.T, p PrepareInterface) {
5555
t.Parallel()
5656
storage, deferFunc := p.CreateStorage()
5757
defer deferFunc()
@@ -72,8 +72,8 @@ func testStorage_Add_Repeat(t *testing.T, p PrepareInterface) {
7272
//todo: доделать capabilities
7373
}
7474

75-
// testStorage_Add_Limit_Overflow проверка того что при переполнении лимита, запись не добавляется в хранилище
76-
func testStorage_Add_Limit_Overflow(t *testing.T, p PrepareInterface) {
75+
// TestStorage_Add_Limit_Overflow проверка того что при переполнении лимита, запись не добавляется в хранилище
76+
func TestStorage_Add_Limit_Overflow(t *testing.T, p PrepareInterface) {
7777
t.Parallel()
7878
storage, deferFunc := p.CreateStorage()
7979
defer deferFunc()
@@ -94,8 +94,8 @@ func testStorage_Add_Limit_Overflow(t *testing.T, p PrepareInterface) {
9494
assert.Len(t, nodeList, limit, "Added more than "+strconv.Itoa(limit)+"one node")
9595
}
9696

97-
// testStorage_GetAll проверка получения всех нод
98-
func testStorage_GetAll(t *testing.T, p PrepareInterface) {
97+
// TestStorage_GetAll проверка получения всех нод
98+
func TestStorage_GetAll(t *testing.T, p PrepareInterface) {
9999
t.Parallel()
100100
storage, deferFunc := p.CreateStorage()
101101
defer deferFunc()
@@ -134,8 +134,8 @@ func testStorage_GetAll(t *testing.T, p PrepareInterface) {
134134
}
135135
}
136136

137-
// testStorage_GetByAddress проверка получения ноды по адресу
138-
func testStorage_GetByAddress(t *testing.T, p PrepareInterface) {
137+
// TestStorage_GetByAddress проверка получения ноды по адресу
138+
func TestStorage_GetByAddress(t *testing.T, p PrepareInterface) {
139139
t.Parallel()
140140
storage, deferFunc := p.CreateStorage()
141141
defer deferFunc()
@@ -155,8 +155,8 @@ func testStorage_GetByAddress(t *testing.T, p PrepareInterface) {
155155

156156
}
157157

158-
// testStorage_GetBySession проверка получения ноды по sessionId
159-
func testStorage_GetBySession(t *testing.T, p PrepareInterface) {
158+
// TestStorage_GetBySession проверка получения ноды по sessionId
159+
func TestStorage_GetBySession(t *testing.T, p PrepareInterface) {
160160
t.Parallel()
161161
storage, deferFunc := p.CreateStorage()
162162
defer deferFunc()
@@ -177,8 +177,8 @@ func testStorage_GetBySession(t *testing.T, p PrepareInterface) {
177177

178178
}
179179

180-
// testStorage_GetCountWithStatus проверка получения колличества нод с определенным статусом
181-
func testStorage_GetCountWithStatus(t *testing.T, p PrepareInterface) {
180+
// TestStorage_GetCountWithStatus проверка получения колличества нод с определенным статусом
181+
func TestStorage_GetCountWithStatus(t *testing.T, p PrepareInterface) {
182182
t.Parallel()
183183
storage, deferFunc := p.CreateStorage()
184184
defer deferFunc()
@@ -200,8 +200,8 @@ func testStorage_GetCountWithStatus(t *testing.T, p PrepareInterface) {
200200
assert.Equal(t, count, 1)
201201
}
202202

203-
// testStorage_Remove проверка удаления ноды
204-
func testStorage_Remove(t *testing.T, p PrepareInterface) {
203+
// TestStorage_Remove проверка удаления ноды
204+
func TestStorage_Remove(t *testing.T, p PrepareInterface) {
205205
t.Parallel()
206206
storage, deferFunc := p.CreateStorage()
207207
defer deferFunc()
@@ -216,8 +216,8 @@ func testStorage_Remove(t *testing.T, p PrepareInterface) {
216216
assert.Error(t, err)
217217
}
218218

219-
// testStorage_ReserveAvailable_Positive проверка резервирования ноды
220-
func testStorage_ReserveAvailable_Positive(t *testing.T, p PrepareInterface) {
219+
// TestStorage_ReserveAvailable_Positive проверка резервирования ноды
220+
func TestStorage_ReserveAvailable_Positive(t *testing.T, p PrepareInterface) {
221221
t.Parallel()
222222
storage, deferFunc := p.CreateStorage()
223223
defer deferFunc()
@@ -242,8 +242,8 @@ func testStorage_ReserveAvailable_Positive(t *testing.T, p PrepareInterface) {
242242
assert.Equal(t, pool.NodeStatusReserved, node.Status, "Node not Reserved")
243243
}
244244

245-
// testStorage_ReserveAvailable_Negative проверка резервирования ноды, при условии отсутствия доступных нод
246-
func testStorage_ReserveAvailable_Negative(t *testing.T, p PrepareInterface) {
245+
// TestStorage_ReserveAvailable_Negative проверка резервирования ноды, при условии отсутствия доступных нод
246+
func TestStorage_ReserveAvailable_Negative(t *testing.T, p PrepareInterface) {
247247
t.Parallel()
248248
storage, deferFunc := p.CreateStorage()
249249
defer deferFunc()
@@ -256,8 +256,8 @@ func testStorage_ReserveAvailable_Negative(t *testing.T, p PrepareInterface) {
256256
assert.Error(t, err)
257257
}
258258

259-
// testStorage_SetAvailable проверка изменения статуса ноды на Available
260-
func testStorage_SetAvailable(t *testing.T, p PrepareInterface) {
259+
// TestStorage_SetAvailable проверка изменения статуса ноды на Available
260+
func TestStorage_SetAvailable(t *testing.T, p PrepareInterface) {
261261
t.Parallel()
262262
storage, deferFunc := p.CreateStorage()
263263
defer deferFunc()
@@ -275,8 +275,8 @@ func testStorage_SetAvailable(t *testing.T, p PrepareInterface) {
275275
assert.Equal(t, pool.NodeStatusAvailable, node.Status, "Node not Available")
276276
}
277277

278-
// testStorage_SetBusy проверка изменения статуса ноды на Busy
279-
func testStorage_SetBusy(t *testing.T, p PrepareInterface) {
278+
// TestStorage_SetBusy проверка изменения статуса ноды на Busy
279+
func TestStorage_SetBusy(t *testing.T, p PrepareInterface) {
280280
t.Parallel()
281281
storage, deferFunc := p.CreateStorage()
282282
defer deferFunc()
@@ -296,8 +296,8 @@ func testStorage_SetBusy(t *testing.T, p PrepareInterface) {
296296
assert.Equal(t, expectedSessionID, node.SessionID, "Not saved sessionID")
297297
}
298298

299-
// testStorage_UpdateAdderss_UpdatesValue успешное обновления адреса ноды
300-
func testStorage_UpdateAdderss_UpdatesValue(t *testing.T, p PrepareInterface) {
299+
// TestStorage_UpdateAdderss_UpdatesValue успешное обновления адреса ноды
300+
func TestStorage_UpdateAdderss_UpdatesValue(t *testing.T, p PrepareInterface) {
301301
t.Parallel()
302302
storage, deferFunc := p.CreateStorage()
303303
defer deferFunc()
@@ -316,8 +316,8 @@ func testStorage_UpdateAdderss_UpdatesValue(t *testing.T, p PrepareInterface) {
316316
assert.Equal(t, expectedAddress, node.Address, "Not updated address")
317317
}
318318

319-
// testStorage_UpdateAdderss_ReturnsErrNotFound попытка обновить несуществующую ноду
320-
func testStorage_UpdateAdderss_ReturnsErrNotFound(t *testing.T, p PrepareInterface) {
319+
// TestStorage_UpdateAdderss_ReturnsErrNotFound попытка обновить несуществующую ноду
320+
func TestStorage_UpdateAdderss_ReturnsErrNotFound(t *testing.T, p PrepareInterface) {
321321
t.Parallel()
322322
storage, deferFunc := p.CreateStorage()
323323
defer deferFunc()

0 commit comments

Comments
 (0)