balena-supervisor/test/legacy/31-docker-utils.spec.ts
Felipe Lalanne e1e35eb83b Move the current test suite under test/legacy
We are refactoring the supervisor test suite into unit tests (for
algorithms an domain model tests) and integration
tests (for interaction with out-of-process dependencies).
This means the current test suite needs to be classified into
these two categories, and fixed whenever possible.

This commit moves the test suite under the `test/legacy` folder, this
folder should be progressively migrated and eventually removed.
Subsequent commits will begin to split these files into unit and
integration whenever possible.

Depends-on: #1996
Change-type: patch
2022-08-22 17:21:51 -04:00

57 lines
1.4 KiB
TypeScript

import { expect } from 'chai';
import { testWithData } from '~/test-lib/mocked-dockerode';
import * as dockerUtils from '~/lib/docker-utils';
describe('Docker Utils', () => {
describe('Supervisor Address', () => {
// setup some fake data...
const networks = {
supervisor0: {
IPAM: {
Config: [
{
Gateway: '10.0.105.1',
Subnet: '10.0.105.0/16',
},
],
},
},
};
// test using existing data...
it('should return the correct gateway address for supervisor0', async () => {
await testWithData({ networks }, async () => {
const gateway = await dockerUtils.getNetworkGateway('supervisor0');
expect(gateway).to.equal('10.0.105.1');
});
});
it('should return the correct gateway address for host', async () => {
await testWithData({ networks }, async () => {
const gateway = await dockerUtils.getNetworkGateway('host');
expect(gateway).to.equal('127.0.0.1');
});
});
});
describe('Image Environment', () => {
const images = {
['test-image']: {
Config: {
Env: ['TEST_VAR_1=1234', 'TEST_VAR_2=5678'],
},
},
};
// test using existing data...
it('should return the correct image environment', async () => {
await testWithData({ images }, async () => {
const obj = await dockerUtils.getImageEnv('test-image');
expect(obj).to.have.property('TEST_VAR_1').equal('1234');
expect(obj).to.have.property('TEST_VAR_2').equal('5678');
});
});
});
});