Skip to content

Commit 2a883fc

Browse files
committed
increase coverage ratio of remote_v1.lua
1 parent 85a1423 commit 2a883fc

File tree

1 file changed

+47
-8
lines changed

1 file changed

+47
-8
lines changed
+47-8
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,68 @@
1-
local loader = require 'apicast.configuration_loader.remote_v1'
1+
local _M = require 'apicast.configuration_loader.remote_v1'
22

33
describe('Configuration object', function()
4+
describe('.wait', function()
5+
before_each(function()
6+
stub(ngx, 'now', function() return 0 end)
7+
end)
8+
9+
describe('when endpoint is missing', function()
10+
it('returns error', function()
11+
local ret, err = _M.wait(nil, 0)
12+
assert.is_nil(ret)
13+
assert.same('missing endpoint', err)
14+
end)
15+
end)
16+
17+
describe('when port is missing', function()
18+
describe('and scheme is http', function()
19+
it('returns true', function()
20+
local ret, err = _M.wait('http://test.port.missing/', 0)
21+
assert.is_nil(err)
22+
assert.is_true(ret)
23+
end)
24+
end)
25+
26+
describe('and scheme is https', function()
27+
it('returns true', function()
28+
local ret, err = _M.wait('https://test.port.missing/', 0)
29+
assert.is_nil(err)
30+
assert.is_true(ret)
31+
end)
32+
end)
33+
34+
describe('and scheme is neither http nor https', function()
35+
it('returns error', function()
36+
local ret, err = _M.wait('redis://test.port.missing/', 0)
37+
assert.is_nil(ret)
38+
assert.same('unknown scheme redis and port missing', err)
39+
end)
40+
end)
41+
end)
42+
end)
443

544
describe('.download', function()
645
it('returns error on missing endpoint', function()
7-
assert.same({nil, 'missing endpoint'}, { loader.download() })
46+
assert.same({nil, 'missing endpoint'}, { _M.download() })
847
end)
948

1049
it('returns error on invalid URI', function()
11-
assert.same({nil, 'missing scheme'}, { loader.download('foobar') })
50+
assert.same({nil, 'missing scheme'}, { _M.download('foobar') })
1251
end)
1352

1453
it('returns error on invalid URI', function()
15-
assert.same({nil, 'connection refused'}, { loader.download('http://127.0.0.1:1234/config/') })
54+
assert.same({nil, 'connection refused'}, { _M.download('http://127.0.0.1:1234/config/') })
1655
end)
1756

1857

1958
it('.download', function()
20-
loader.download('http://user:pass@localhost:3000')
21-
loader.download('https://user@localhost')
22-
loader.download('http://:[email protected]:3000')
59+
_M.download('http://user:pass@localhost:3000')
60+
_M.download('https://user@localhost')
61+
_M.download('http://:[email protected]:3000')
2362
end)
2463

2564
it('decodes config #network', function()
26-
assert(loader.download('http://127.0.0.1:1984/json'))
65+
assert(_M.download('http://127.0.0.1:1984/json'))
2766
end)
2867
end)
2968
end)

0 commit comments

Comments
 (0)