test('port is occupied by other process', () => { request.mockImplementation((opts, cb) => { const err = new Error('fake selenium error'); err.code = 'ECONNREFUSED'; return cb(err); }); portscanner.checkPortStatus.mockImplementation((port, host, cb) => cb(null, 'open')); const spy = sinon.spy(); checkPorts([10], spy); expect(spy.called).toEqual(true); expect(spy.args[0][0]).toEqual([{ 'port': 10, 'available': false }]); });
test('watchImage should return no result when no image found', () => { docker.configuration = {}; rp.mockImplementation(() => ({ results: [], })); expect(docker.watchImage(sampleSemver)).resolves.toMatchObject({ result: undefined, }); });
test('port isn\'t available', () => { request.mockImplementation((opts, cb) => cb(null)); const spy = sinon.spy(); checkPorts([10], spy); expect(spy.called).toEqual(true); expect(spy.args[0][0]).toEqual([{ 'port': 10, 'available': false }]); });
request.mockImplementation(function (options) { return Promise.resolve() })
test('authenticate should perform authenticate request', async () => { rp.mockImplementation(() => ({ token: 'token', })); expect(dockerHub.authenticate({ login: 'login', password: 'password' })).resolves.toEqual('token'); });
request.mockImplementation(function (options) { return Promise.resolve() })
test('findNewVersion should return undefined when no image found', () => { rp.mockImplementation(() => ({ results: [], })); expect(docker.findNewVersion(sampleSemver)).resolves.toStrictEqual(undefined); });
test('findNewVersion should return new image when found', () => { const foundVersion = { name: '7.8.9', last_updated: '2019-05-25T12:02:06.307Z', images: [{ architecture: 'arch', os: 'os', size: 10, }], }; rp.mockImplementation(() => ({ results: [foundVersion], })); expect(docker.findNewVersion(sampleSemver)).resolves.toMatchObject({ newVersion: foundVersion.name, newVersionDate: foundVersion.last_updated, }); });
test('watchImage should return new image when found', () => { docker.configuration = {}; const foundVersion = { name: '7.8.9', last_updated: '2019-05-25T12:02:06.307Z', images: [{ architecture: 'arch', os: 'os', size: 10, }], }; rp.mockImplementation(() => ({ results: [foundVersion], })); expect(docker.watchImage(sampleSemver)).resolves.toMatchObject({ result: { newVersion: foundVersion.name, newVersionDate: foundVersion.last_updated, }, }); });
test('port is available', () => { request.mockImplementation((opts, cb) => { const err = new Error('fake selenium error'); err.code = 'ECONNREFUSED'; return cb(err); }); portscanner.checkPortStatus.mockImplementation((port, host, cb) => cb(null, 'closed')); const spy = sinon.spy(); checkPorts([10], spy); expect(spy.called).toEqual(true); expect(spy.args[0][0]).toEqual([{ 'port': 10, 'available': true }]); });