@@ -45,14 +45,14 @@ func TestClientSetupAndFileNotExisted(t *testing.T) {
45
45
}
46
46
47
47
rsp := configService .GetConfigFileForClient (defaultCtx , fileInfo )
48
- assert .Equal (t , uint32 ( api .NotFoundResource ) , rsp .Code .GetValue (), "GetConfigFileForClient must notfound" )
48
+ assert .Equal (t , api .NotFoundResource , rsp .Code .GetValue (), "GetConfigFileForClient must notfound" )
49
49
50
50
rsp2 := configService .CheckClientConfigFileByVersion (defaultCtx , assembleDefaultClientConfigFile (0 ))
51
- assert .Equal (t , uint32 ( api .DataNoChange ) , rsp2 .Code .GetValue (), "CheckClientConfigFileByVersion must nochange" )
51
+ assert .Equal (t , api .DataNoChange , rsp2 .Code .GetValue (), "CheckClientConfigFileByVersion must nochange" )
52
52
assert .Nil (t , rsp2 .ConfigFile )
53
53
54
54
rsp3 := configService .CheckClientConfigFileByMd5 (defaultCtx , assembleDefaultClientConfigFile (0 ))
55
- assert .Equal (t , uint32 ( api .DataNoChange ) , rsp3 .Code .GetValue ())
55
+ assert .Equal (t , api .DataNoChange , rsp3 .Code .GetValue ())
56
56
assert .Nil (t , rsp3 .ConfigFile )
57
57
}
58
58
@@ -78,7 +78,8 @@ func TestClientSetupAndFileExisted(t *testing.T) {
78
78
79
79
// 拉取配置接口
80
80
rsp3 := configService .GetConfigFileForClient (defaultCtx , fileInfo )
81
- assert .Equalf (t , api .ExecuteSuccess , rsp3 .Code .GetValue (), "GetConfigFileForClient must success, acutal code : %d" , rsp3 .Code .GetValue ())
81
+ assert .Equalf (t , api .ExecuteSuccess , rsp3 .Code .GetValue (),
82
+ "GetConfigFileForClient must success, acutal code : %d" , rsp3 .Code .GetValue ())
82
83
assert .NotNil (t , rsp3 .ConfigFile )
83
84
assert .Equal (t , uint64 (1 ), rsp3 .ConfigFile .Version .GetValue ())
84
85
assert .Equal (t , configFile .Content .GetValue (), rsp3 .ConfigFile .Content .GetValue ())
@@ -164,17 +165,18 @@ func TestWatchConfigFileAtFirstPublish(t *testing.T) {
164
165
received := make (chan uint64 )
165
166
166
167
watchConfigFiles := assembleDefaultClientConfigFile (0 )
167
- clientId := "TestWatchConfigFileAtFirstPublish-first"
168
+ clientID := "TestWatchConfigFileAtFirstPublish-first"
168
169
169
170
defer func () {
170
- configService .WatchCenter ().RemoveWatcher (clientId , watchConfigFiles )
171
+ configService .WatchCenter ().RemoveWatcher (clientID , watchConfigFiles )
171
172
}()
172
173
173
- configService .WatchCenter ().AddWatcher (clientId , watchConfigFiles , func (clientId string , rsp * api.ConfigClientResponse ) bool {
174
- t .Logf ("clientId=[%s] receive config publish msg" , clientId )
175
- received <- rsp .ConfigFile .Version .GetValue ()
176
- return true
177
- })
174
+ configService .WatchCenter ().AddWatcher (clientID ,
175
+ watchConfigFiles , func (clientId string , rsp * api.ConfigClientResponse ) bool {
176
+ t .Logf ("clientId=[%s] receive config publish msg" , clientId )
177
+ received <- rsp .ConfigFile .Version .GetValue ()
178
+ return true
179
+ })
178
180
179
181
rsp := configService .CreateConfigFile (defaultCtx , configFile )
180
182
assert .Equal (t , api .ExecuteSuccess , rsp .Code .GetValue ())
@@ -193,13 +195,14 @@ func TestWatchConfigFileAtFirstPublish(t *testing.T) {
193
195
// 版本号由于发布过一次,所以是1
194
196
watchConfigFiles := assembleDefaultClientConfigFile (1 )
195
197
196
- clientId := "TestWatchConfigFileAtFirstPublish-second"
198
+ clientID := "TestWatchConfigFileAtFirstPublish-second"
197
199
198
- configService .WatchCenter ().AddWatcher (clientId , watchConfigFiles , func (clientId string , rsp * api.ConfigClientResponse ) bool {
199
- t .Logf ("clientId=[%s] receive config publish msg" , clientId )
200
- received <- rsp .ConfigFile .Version .GetValue ()
201
- return true
202
- })
200
+ configService .WatchCenter ().AddWatcher (clientID ,
201
+ watchConfigFiles , func (clientId string , rsp * api.ConfigClientResponse ) bool {
202
+ t .Logf ("clientId=[%s] receive config publish msg" , clientId )
203
+ received <- rsp .ConfigFile .Version .GetValue ()
204
+ return true
205
+ })
203
206
204
207
rsp3 := configService .PublishConfigFile (defaultCtx , assembleConfigFileRelease (configFile ))
205
208
assert .Equal (t , api .ExecuteSuccess , rsp3 .Code .GetValue ())
@@ -209,7 +212,7 @@ func TestWatchConfigFileAtFirstPublish(t *testing.T) {
209
212
assert .Equal (t , uint64 (2 ), receivedVersion )
210
213
211
214
// 为了避免影响其它 case,删除订阅
212
- configService .WatchCenter ().RemoveWatcher (clientId , watchConfigFiles )
215
+ configService .WatchCenter ().RemoveWatcher (clientID , watchConfigFiles )
213
216
})
214
217
}
215
218
@@ -224,14 +227,15 @@ func Test10000ClientWatchConfigFile(t *testing.T) {
224
227
receivedVersion := make (map [string ]uint64 )
225
228
watchConfigFiles := assembleDefaultClientConfigFile (0 )
226
229
for i := 0 ; i < clientSize ; i ++ {
227
- clientId := fmt .Sprintf ("Test10000ClientWatchConfigFile-client-id=%d" , i )
228
- received [clientId ] = false
229
- receivedVersion [clientId ] = uint64 (0 )
230
- configService .WatchCenter ().AddWatcher (clientId , watchConfigFiles , func (clientId string , rsp * api.ConfigClientResponse ) bool {
231
- received [clientId ] = true
232
- receivedVersion [clientId ] = rsp .ConfigFile .Version .GetValue ()
233
- return true
234
- })
230
+ clientID := fmt .Sprintf ("Test10000ClientWatchConfigFile-client-id=%d" , i )
231
+ received [clientID ] = false
232
+ receivedVersion [clientID ] = uint64 (0 )
233
+ configService .WatchCenter ().AddWatcher (clientID ,
234
+ watchConfigFiles , func (clientId string , rsp * api.ConfigClientResponse ) bool {
235
+ received [clientId ] = true
236
+ receivedVersion [clientId ] = rsp .ConfigFile .Version .GetValue ()
237
+ return true
238
+ })
235
239
}
236
240
237
241
// 创建并发布配置文件
@@ -258,11 +262,11 @@ func Test10000ClientWatchConfigFile(t *testing.T) {
258
262
for _ , v := range receivedVersion {
259
263
receivedVerCnt += v
260
264
}
261
- assert .Equal (t , uint64 (len (receivedVersion )), uint64 ( receivedVerCnt ) )
265
+ assert .Equal (t , uint64 (len (receivedVersion )), receivedVerCnt )
262
266
263
267
// 为了避免影响其它case,删除订阅
264
- for clientId := range received {
265
- configService .WatchCenter ().RemoveWatcher (clientId , watchConfigFiles )
268
+ for clientID := range received {
269
+ configService .WatchCenter ().RemoveWatcher (clientID , watchConfigFiles )
266
270
}
267
271
}
268
272
@@ -282,16 +286,17 @@ func TestDeleteConfigFile(t *testing.T) {
282
286
time .Sleep (1200 * time .Millisecond )
283
287
284
288
// 客户端订阅
285
- clientId := randomStr ()
289
+ clientID := randomStr ()
286
290
received := make (chan uint64 )
287
291
watchConfigFiles := assembleDefaultClientConfigFile (0 )
288
292
289
293
t .Log ("add config watcher" )
290
294
291
- configService .WatchCenter ().AddWatcher (clientId , watchConfigFiles , func (clientId string , rsp * api.ConfigClientResponse ) bool {
292
- received <- rsp .ConfigFile .Version .GetValue ()
293
- return true
294
- })
295
+ configService .WatchCenter ().AddWatcher (clientID ,
296
+ watchConfigFiles , func (clientId string , rsp * api.ConfigClientResponse ) bool {
297
+ received <- rsp .ConfigFile .Version .GetValue ()
298
+ return true
299
+ })
295
300
296
301
// 删除配置文件
297
302
t .Log ("remove config file" )
@@ -312,5 +317,5 @@ func TestDeleteConfigFile(t *testing.T) {
312
317
313
318
// 重新拉取配置,获取不到配置文件
314
319
rsp4 := configService .GetConfigFileForClient (defaultCtx , fileInfo )
315
- assert .Equal (t , uint32 ( api .NotFoundResource ) , rsp4 .Code .GetValue ())
320
+ assert .Equal (t , api .NotFoundResource , rsp4 .Code .GetValue ())
316
321
}
0 commit comments