17
17
package consul
18
18
19
19
import (
20
- "github.com/edgexfoundry/go-mod-registry"
21
20
"log"
22
21
"net/http"
23
22
"net/http/httptest"
@@ -31,6 +30,8 @@ import (
31
30
"github.com/hashicorp/consul/api"
32
31
"github.com/pelletier/go-toml"
33
32
"github.com/stretchr/testify/assert"
33
+
34
+ "github.com/edgexfoundry/go-mod-registry/pkg/types"
34
35
)
35
36
36
37
const (
@@ -55,7 +56,7 @@ type LoggingInfo struct {
55
56
56
57
type MyConfig struct {
57
58
Logging LoggingInfo
58
- Service registry .ServiceEndpoint
59
+ Service types .ServiceEndpoint
59
60
Port int
60
61
Host string
61
62
LogLevel string
@@ -116,7 +117,7 @@ func TestHasConfigurationTrue(t *testing.T) {
116
117
}
117
118
118
119
// Now push a value so the configuration will exist
119
- client .PutConfigurationValue ("Dummy" , []byte ("Value" ))
120
+ _ = client .PutConfigurationValue ("Dummy" , []byte ("Value" ))
120
121
121
122
actual , err := client .HasConfiguration ()
122
123
if ! assert .NoError (t , err ) {
@@ -164,7 +165,7 @@ func TestRegisterWithPingCallback(t *testing.T) {
164
165
receivedPing = true
165
166
166
167
writer .Header ().Set ("Content-Type" , "text/plain" )
167
- writer .Write ([]byte ("pong" ))
168
+ _ , _ = writer .Write ([]byte ("pong" ))
168
169
169
170
doneChan <- true
170
171
}
@@ -178,13 +179,13 @@ func TestRegisterWithPingCallback(t *testing.T) {
178
179
179
180
client := makeConsulClient (t , serverPort , true )
180
181
// Make sure service is not already registered.
181
- client .consulClient .Agent ().ServiceDeregister (client .serviceKey )
182
- client .consulClient .Agent ().CheckDeregister (client .serviceKey )
182
+ _ = client .consulClient .Agent ().ServiceDeregister (client .serviceKey )
183
+ _ = client .consulClient .Agent ().CheckDeregister (client .serviceKey )
183
184
184
185
// Try to clean-up after test
185
186
defer func (client * consulClient ) {
186
- client .consulClient .Agent ().ServiceDeregister (client .serviceKey )
187
- client .consulClient .Agent ().CheckDeregister (client .serviceKey )
187
+ _ = client .consulClient .Agent ().ServiceDeregister (client .serviceKey )
188
+ _ = client .consulClient .Agent ().CheckDeregister (client .serviceKey )
188
189
}(client )
189
190
190
191
// Register the service endpoint and health check callback
@@ -203,22 +204,22 @@ func TestRegisterWithPingCallback(t *testing.T) {
203
204
}
204
205
205
206
func TestGetServiceEndpoint (t * testing.T ) {
206
- expectedNotFoundEndpoint := registry .ServiceEndpoint {}
207
- expectedFoundEndpoint := registry .ServiceEndpoint {
207
+ expectedNotFoundEndpoint := types .ServiceEndpoint {}
208
+ expectedFoundEndpoint := types .ServiceEndpoint {
208
209
ServiceId : serviceName ,
209
210
Host : serviceHost ,
210
211
Port : defaultServicePort ,
211
212
}
212
213
213
214
client := makeConsulClient (t , defaultServicePort , true )
214
215
// Make sure service is not already registered.
215
- client .consulClient .Agent ().ServiceDeregister (client .serviceKey )
216
- client .consulClient .Agent ().CheckDeregister (client .serviceKey )
216
+ _ = client .consulClient .Agent ().ServiceDeregister (client .serviceKey )
217
+ _ = client .consulClient .Agent ().CheckDeregister (client .serviceKey )
217
218
218
219
// Try to clean-up after test
219
220
defer func (client * consulClient ) {
220
- client .consulClient .Agent ().ServiceDeregister (client .serviceKey )
221
- client .consulClient .Agent ().CheckDeregister (client .serviceKey )
221
+ _ = client .consulClient .Agent ().ServiceDeregister (client .serviceKey )
222
+ _ = client .consulClient .Agent ().CheckDeregister (client .serviceKey )
222
223
}(client )
223
224
224
225
// Test for endpoint not found
@@ -251,8 +252,8 @@ func TestIsServiceAvailableNotRegistered(t *testing.T) {
251
252
client := makeConsulClient (t , defaultServicePort , true )
252
253
253
254
// Make sure service is not already registered.
254
- client .consulClient .Agent ().ServiceDeregister (client .serviceKey )
255
- client .consulClient .Agent ().CheckDeregister (client .serviceKey )
255
+ _ = client .consulClient .Agent ().ServiceDeregister (client .serviceKey )
256
+ _ = client .consulClient .Agent ().CheckDeregister (client .serviceKey )
256
257
257
258
actual := client .IsServiceAvailable (client .serviceKey )
258
259
if ! assert .Error (t , actual , "expected error" ) {
@@ -267,13 +268,13 @@ func TestIsServiceAvailableNotHealthy(t *testing.T) {
267
268
client := makeConsulClient (t , defaultServicePort , true )
268
269
269
270
// Make sure service is not already registered.
270
- client .consulClient .Agent ().ServiceDeregister (client .serviceKey )
271
- client .consulClient .Agent ().CheckDeregister (client .serviceKey )
271
+ _ = client .consulClient .Agent ().ServiceDeregister (client .serviceKey )
272
+ _ = client .consulClient .Agent ().CheckDeregister (client .serviceKey )
272
273
273
274
// Try to clean-up after test
274
275
defer func (client * consulClient ) {
275
- client .consulClient .Agent ().ServiceDeregister (client .serviceKey )
276
- client .consulClient .Agent ().CheckDeregister (client .serviceKey )
276
+ _ = client .consulClient .Agent ().ServiceDeregister (client .serviceKey )
277
+ _ = client .consulClient .Agent ().CheckDeregister (client .serviceKey )
277
278
}(client )
278
279
279
280
// Register the service endpoint, without test service to respond to health check
@@ -303,7 +304,7 @@ func TestIsServiceAvailableHealthy(t *testing.T) {
303
304
switch request .Method {
304
305
case "GET" :
305
306
writer .Header ().Set ("Content-Type" , "text/plain" )
306
- writer .Write ([]byte ("pong" ))
307
+ _ , _ = writer .Write ([]byte ("pong" ))
307
308
308
309
doneChan <- true
309
310
}
@@ -317,13 +318,13 @@ func TestIsServiceAvailableHealthy(t *testing.T) {
317
318
318
319
client := makeConsulClient (t , serverPort , true )
319
320
// Make sure service is not already registered.
320
- client .consulClient .Agent ().ServiceDeregister (client .serviceKey )
321
- client .consulClient .Agent ().CheckDeregister (client .serviceKey )
321
+ _ = client .consulClient .Agent ().ServiceDeregister (client .serviceKey )
322
+ _ = client .consulClient .Agent ().CheckDeregister (client .serviceKey )
322
323
323
324
// Try to clean-up after test
324
325
defer func (client * consulClient ) {
325
- client .consulClient .Agent ().ServiceDeregister (client .serviceKey )
326
- client .consulClient .Agent ().CheckDeregister (client .serviceKey )
326
+ _ = client .consulClient .Agent ().ServiceDeregister (client .serviceKey )
327
+ _ = client .consulClient .Agent ().CheckDeregister (client .serviceKey )
327
328
}(client )
328
329
329
330
// Register the service endpoint
@@ -366,7 +367,7 @@ func TestConfigurationValueExists(t *testing.T) {
366
367
if ! assert .NoError (t , err ) {
367
368
t .Fatal ()
368
369
}
369
- if ! assert .Equal ( t , expected , actual ) {
370
+ if ! assert .False ( t , actual ) {
370
371
t .Fatal ()
371
372
}
372
373
@@ -423,7 +424,7 @@ func TestPutConfigurationValue(t *testing.T) {
423
424
client := makeConsulClient (t , defaultServicePort , true )
424
425
425
426
//clean up the the key, if it exists
426
- client .consulClient .KV ().Delete (expectedFullKey , nil )
427
+ _ , _ = client .consulClient .KV ().Delete (expectedFullKey , nil )
427
428
428
429
err := client .PutConfigurationValue (key , expected )
429
430
assert .NoError (t , err )
@@ -448,7 +449,7 @@ func TestGetConfiguration(t *testing.T) {
448
449
EnableRemote : true ,
449
450
File : "NONE" ,
450
451
},
451
- Service : registry .ServiceEndpoint {
452
+ Service : types .ServiceEndpoint {
452
453
ServiceId : "Dummy" ,
453
454
Host : "10.6.7.8" ,
454
455
Port : 8080 ,
@@ -460,14 +461,14 @@ func TestGetConfiguration(t *testing.T) {
460
461
461
462
client := makeConsulClient (t , defaultServicePort , true )
462
463
463
- client .PutConfigurationValue ("Logging/EnableRemote" , []byte (strconv .FormatBool (expected .Logging .EnableRemote )))
464
- client .PutConfigurationValue ("Logging/File" , []byte (expected .Logging .File ))
465
- client .PutConfigurationValue ("Service/ServiceId" , []byte (expected .Service .ServiceId ))
466
- client .PutConfigurationValue ("Service/Host" , []byte (expected .Service .Host ))
467
- client .PutConfigurationValue ("Service/Port" , []byte (strconv .Itoa (expected .Service .Port )))
468
- client .PutConfigurationValue ("Port" , []byte (strconv .Itoa (expected .Port )))
469
- client .PutConfigurationValue ("Host" , []byte (expected .Host ))
470
- client .PutConfigurationValue ("LogLevel" , []byte (expected .LogLevel ))
464
+ _ = client .PutConfigurationValue ("Logging/EnableRemote" , []byte (strconv .FormatBool (expected .Logging .EnableRemote )))
465
+ _ = client .PutConfigurationValue ("Logging/File" , []byte (expected .Logging .File ))
466
+ _ = client .PutConfigurationValue ("Service/ServiceId" , []byte (expected .Service .ServiceId ))
467
+ _ = client .PutConfigurationValue ("Service/Host" , []byte (expected .Service .Host ))
468
+ _ = client .PutConfigurationValue ("Service/Port" , []byte (strconv .Itoa (expected .Service .Port )))
469
+ _ = client .PutConfigurationValue ("Port" , []byte (strconv .Itoa (expected .Port )))
470
+ _ = client .PutConfigurationValue ("Host" , []byte (expected .Host ))
471
+ _ = client .PutConfigurationValue ("LogLevel" , []byte (expected .LogLevel ))
471
472
472
473
result , err := client .GetConfiguration (& MyConfig {})
473
474
@@ -497,7 +498,7 @@ func TestPutConfiguration(t *testing.T) {
497
498
EnableRemote : true ,
498
499
File : "NONE" ,
499
500
},
500
- Service : registry .ServiceEndpoint {
501
+ Service : types .ServiceEndpoint {
501
502
ServiceId : "Dummy" ,
502
503
Host : "10.6.7.8" ,
503
504
Port : 8080 ,
@@ -511,11 +512,11 @@ func TestPutConfiguration(t *testing.T) {
511
512
client := makeConsulClient (t , defaultServicePort , true )
512
513
513
514
// Make sure the tree of values doesn't exist.
514
- client .consulClient .KV ().DeleteTree (consulBasePath , nil )
515
+ _ , _ = client .consulClient .KV ().DeleteTree (consulBasePath , nil )
515
516
516
517
defer func () {
517
518
// Clean up
518
- client .consulClient .KV ().DeleteTree (consulBasePath , nil )
519
+ _ , _ = client .consulClient .KV ().DeleteTree (consulBasePath , nil )
519
520
}()
520
521
521
522
err := client .PutConfiguration (expected , true )
@@ -538,7 +539,7 @@ func TestPutConfiguration(t *testing.T) {
538
539
assert .True (t ,configValueSet ("LogLevel" , client ))
539
540
}
540
541
541
- func configValueSet (key string , client registry. Client ) bool {
542
+ func configValueSet (key string , client * consulClient ) bool {
542
543
exists , _ := client .ConfigurationValueExists (key )
543
544
return exists
544
545
}
@@ -547,11 +548,11 @@ func TestPutConfigurationTomlNoPreviousValues(t *testing.T) {
547
548
client := makeConsulClient (t , defaultServicePort , true )
548
549
549
550
// Make sure the tree of values doesn't exist.
550
- client .consulClient .KV ().DeleteTree (consulBasePath , nil )
551
+ _ , _ = client .consulClient .KV ().DeleteTree (consulBasePath , nil )
551
552
552
553
defer func () {
553
554
// Clean up
554
- client .consulClient .KV ().DeleteTree (consulBasePath , nil )
555
+ _ , _ = client .consulClient .KV ().DeleteTree (consulBasePath , nil )
555
556
}()
556
557
557
558
configMap := createKeyValueMap ()
@@ -582,11 +583,11 @@ func TestPutConfigurationTomlWithoutOverWrite(t *testing.T) {
582
583
client := makeConsulClient (t , defaultServicePort , true )
583
584
584
585
// Make sure the tree of values doesn't exist.
585
- client .consulClient .KV ().DeleteTree (consulBasePath , nil )
586
+ _ , _ = client .consulClient .KV ().DeleteTree (consulBasePath , nil )
586
587
587
588
defer func () {
588
589
// Clean up
589
- client .consulClient .KV ().DeleteTree (consulBasePath , nil )
590
+ _ , _ = client .consulClient .KV ().DeleteTree (consulBasePath , nil )
590
591
}()
591
592
592
593
configMap := createKeyValueMap ()
@@ -629,10 +630,10 @@ func TestPutConfigurationTomlOverWrite(t *testing.T) {
629
630
client := makeConsulClient (t , defaultServicePort , true )
630
631
631
632
// Make sure the tree of values doesn't exist.
632
- client .consulClient .KV ().DeleteTree (consulBasePath , nil )
633
+ _ , _ = client .consulClient .KV ().DeleteTree (consulBasePath , nil )
633
634
// Clean up after unit test
634
635
defer func () {
635
- client .consulClient .KV ().DeleteTree (consulBasePath , nil )
636
+ _ , _ = client .consulClient .KV ().DeleteTree (consulBasePath , nil )
636
637
}()
637
638
638
639
configMap := createKeyValueMap ()
@@ -676,7 +677,7 @@ func TestWatchForChanges(t *testing.T) {
676
677
EnableRemote : true ,
677
678
File : "NONE" ,
678
679
},
679
- Service : registry .ServiceEndpoint {
680
+ Service : types .ServiceEndpoint {
680
681
ServiceId : "Dummy" ,
681
682
Host : "10.6.7.8" ,
682
683
Port : 8080 ,
@@ -691,20 +692,20 @@ func TestWatchForChanges(t *testing.T) {
691
692
client := makeConsulClient (t , defaultServicePort , false )
692
693
693
694
// Make sure the tree of values doesn't exist.
694
- client .consulClient .KV ().DeleteTree (consulBasePath , nil )
695
+ _ , _ = client .consulClient .KV ().DeleteTree (consulBasePath , nil )
695
696
// Clean up after unit test
696
697
defer func () {
697
- client .consulClient .KV ().DeleteTree (consulBasePath , nil )
698
+ _ , _ = client .consulClient .KV ().DeleteTree (consulBasePath , nil )
698
699
}()
699
700
700
- client .PutConfigurationValue ("Logging/EnableRemote" , []byte (strconv .FormatBool (expectedConfig .Logging .EnableRemote )))
701
- client .PutConfigurationValue ("Logging/File" , []byte (expectedConfig .Logging .File ))
702
- client .PutConfigurationValue ("Service/ServiceId" , []byte (expectedConfig .Service .ServiceId ))
703
- client .PutConfigurationValue ("Service/Host" , []byte (expectedConfig .Service .Host ))
704
- client .PutConfigurationValue ("Service/Port" , []byte (strconv .Itoa (expectedConfig .Service .Port )))
705
- client .PutConfigurationValue ("Port" , []byte (strconv .Itoa (expectedConfig .Port )))
706
- client .PutConfigurationValue ("Host" , []byte (expectedConfig .Host ))
707
- client .PutConfigurationValue ("LogLevel" , []byte (expectedConfig .LogLevel ))
701
+ _ = client .PutConfigurationValue ("Logging/EnableRemote" , []byte (strconv .FormatBool (expectedConfig .Logging .EnableRemote )))
702
+ _ = client .PutConfigurationValue ("Logging/File" , []byte (expectedConfig .Logging .File ))
703
+ _ = client .PutConfigurationValue ("Service/ServiceId" , []byte (expectedConfig .Service .ServiceId ))
704
+ _ = client .PutConfigurationValue ("Service/Host" , []byte (expectedConfig .Service .Host ))
705
+ _ = client .PutConfigurationValue ("Service/Port" , []byte (strconv .Itoa (expectedConfig .Service .Port )))
706
+ _ = client .PutConfigurationValue ("Port" , []byte (strconv .Itoa (expectedConfig .Port )))
707
+ _ = client .PutConfigurationValue ("Host" , []byte (expectedConfig .Host ))
708
+ _ = client .PutConfigurationValue ("LogLevel" , []byte (expectedConfig .LogLevel ))
708
709
709
710
updateChannel := make (chan interface {})
710
711
errorChannel := make (chan error )
@@ -728,7 +729,7 @@ func TestWatchForChanges(t *testing.T) {
728
729
}
729
730
730
731
// Make a change to logging
731
- client .PutConfigurationValue ("Logging/File" , []byte (expectedChange ))
732
+ _ = client .PutConfigurationValue ("Logging/File" , []byte (expectedChange ))
732
733
733
734
pass --
734
735
continue
@@ -745,7 +746,7 @@ func TestWatchForChanges(t *testing.T) {
745
746
}
746
747
747
748
func makeConsulClient (t * testing.T , servicePort int , setServiceInfo bool ) * consulClient {
748
- registryConfig := registry .Config {
749
+ registryConfig := types .Config {
749
750
Host : testHost ,
750
751
Port : port ,
751
752
Stem : "edgex/core/1.0/" ,
0 commit comments