@@ -10,6 +10,10 @@ process.env.RUNNING_UNIT_TESTS = true
10
10
getNock = (host = ' http://127.0.0.1:4001' ) ->
11
11
nock host
12
12
13
+
14
+ beforeEach () ->
15
+ nock .cleanAll ()
16
+
13
17
# Tests for utility functions
14
18
15
19
describe ' Utility' , ->
@@ -28,6 +32,57 @@ describe 'Utility', ->
28
32
path : ' /v2/keypath/key'
29
33
}
30
34
35
+
36
+ describe ' Connecting' , ->
37
+
38
+ mock = (host = ' http://127.0.0.1:4001/' ) ->
39
+ nock (host)
40
+ .get (' /v2/keys/key' )
41
+ .reply (200 , ' {"action":"GET","key":"/key","value":"value","index":1}' )
42
+
43
+ it ' should support empty constructor (localhost:4001)' , (done ) ->
44
+ etcd = new Etcd
45
+ m = mock ()
46
+ etcd .get ' key' , (err , val ) ->
47
+ m .isDone ().should .be .true
48
+ done err, val
49
+
50
+ it ' should support string as connect host' , (done ) ->
51
+ etcd = new Etcd " testhost.com:4009"
52
+ m = mock (" http://testhost.com:4009" )
53
+ etcd .get ' key' , (err , val ) ->
54
+ m .isDone ().should .be .true
55
+ done err, val
56
+
57
+ it ' should support string prefixed by http:// as host' , (done ) ->
58
+ etcd = new Etcd " http://testhost.com:4009"
59
+ m = mock (" http://testhost.com:4009" )
60
+ etcd .get ' key' , (err , val ) ->
61
+ m .isDone ().should .be .true
62
+ done err, val
63
+
64
+ it ' should support string postfixed by / as host' , (done ) ->
65
+ etcd = new Etcd " http://testhost.com:4009/"
66
+ m = mock (" http://testhost.com:4009" )
67
+ etcd .get ' key' , (err , val ) ->
68
+ m .isDone ().should .be .true
69
+ done err, val
70
+
71
+ it ' should support array of strings as host' , (done ) ->
72
+ etcd = new Etcd [" http://testhost.com:4009" ]
73
+ m = mock (" http://testhost.com:4009" )
74
+ etcd .get ' key' , (err , val ) ->
75
+ m .isDone ().should .be .true
76
+ done err, val
77
+
78
+ it ' should support https strings' , (done ) ->
79
+ etcd = new Etcd [" https://testhost.com:1000" ]
80
+ m = mock (" https://testhost.com:1000" )
81
+ etcd .get ' key' , (err , val ) ->
82
+ m .isDone ().should .be .true
83
+ done err, val
84
+
85
+
31
86
describe ' Basic functions' , ->
32
87
33
88
etcd = new Etcd
@@ -308,13 +363,7 @@ describe 'Multiserver/Cluster support', ->
308
363
309
364
it ' should accept list of servers in constructor' , ->
310
365
etcd = new Etcd [' localhost:4001' , ' localhost:4002' ]
311
- etcd .getHosts ().should .eql [' localhost:4001' , ' localhost:4002' ]
312
-
313
-
314
- it ' should accept host and port in constructor' , ->
315
- etcd = new Etcd ' localhost' , 4001
316
- etcd .getHosts ().should .eql [' localhost:4001' ]
317
-
366
+ etcd .getHosts ().should .eql [' http://localhost:4001' , ' http://localhost:4002' ]
318
367
319
368
it ' should try next server in list on http error' , (done ) ->
320
369
path = ' /v2/keys/foo'
0 commit comments