|
1 |
| -local loader = require 'apicast.configuration_loader.remote_v1' |
| 1 | +local _M = require 'apicast.configuration_loader.remote_v1' |
2 | 2 |
|
3 | 3 | 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) |
4 | 43 |
|
5 | 44 | describe('.download', function()
|
6 | 45 | it('returns error on missing endpoint', function()
|
7 |
| - assert.same({nil, 'missing endpoint'}, { loader.download() }) |
| 46 | + assert.same({nil, 'missing endpoint'}, { _M.download() }) |
8 | 47 | end)
|
9 | 48 |
|
10 | 49 | 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') }) |
12 | 51 | end)
|
13 | 52 |
|
14 | 53 | 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/') }) |
16 | 55 | end)
|
17 | 56 |
|
18 | 57 |
|
19 | 58 | 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') |
23 | 62 | end)
|
24 | 63 |
|
25 | 64 | 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')) |
27 | 66 | end)
|
28 | 67 | end)
|
29 | 68 | end)
|
0 commit comments