mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-04-07 19:34:17 +00:00
Split compose/service tests into unit/integration
This commit is contained in:
parent
cdc9868d29
commit
a5a24e6462
70
test/integration/compose/service.spec.ts
Normal file
70
test/integration/compose/service.spec.ts
Normal file
@ -0,0 +1,70 @@
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { expect } from 'chai';
|
||||
|
||||
import Service from '~/src/compose/service';
|
||||
import * as apiKeys from '~/lib/api-keys';
|
||||
|
||||
describe('compose/service: integration tests', () => {
|
||||
describe('Feature labels', () => {
|
||||
// TODO: this is the only part of the service module that needs to be integration tested. This is becase it
|
||||
// needs to access the database to get the service scoped api keys. If the keys were generated/queried in
|
||||
// App.fromTargetState and passed to the service as a parameter, it would push this module to the domain model
|
||||
// which is where it belongs
|
||||
describe('io.balena.supervisor-api', () => {
|
||||
it('sets BALENA_SUPERVISOR_HOST, BALENA_SUPERVISOR_PORT and BALENA_SUPERVISOR_ADDRESS env vars', async () => {
|
||||
const service = await Service.fromComposeObject(
|
||||
{
|
||||
appId: 123456,
|
||||
serviceId: 123456,
|
||||
serviceName: 'foobar',
|
||||
labels: {
|
||||
'io.balena.features.supervisor-api': '1',
|
||||
},
|
||||
},
|
||||
{
|
||||
appName: 'test',
|
||||
supervisorApiHost: 'supervisor',
|
||||
listenPort: 48484,
|
||||
} as any,
|
||||
);
|
||||
|
||||
expect(
|
||||
service.config.environment['BALENA_SUPERVISOR_HOST'],
|
||||
).to.be.equal('supervisor');
|
||||
|
||||
expect(
|
||||
service.config.environment['BALENA_SUPERVISOR_PORT'],
|
||||
).to.be.equal('48484');
|
||||
|
||||
expect(
|
||||
service.config.environment['BALENA_SUPERVISOR_ADDRESS'],
|
||||
).to.be.equal('http://supervisor:48484');
|
||||
});
|
||||
|
||||
it('sets BALENA_API_KEY env var to the scoped API key value', async () => {
|
||||
const mykey = await apiKeys.generateScopedKey(123456, 'foobar');
|
||||
|
||||
const service = await Service.fromComposeObject(
|
||||
{
|
||||
appId: 123456,
|
||||
serviceId: 123456,
|
||||
serviceName: 'foobar',
|
||||
labels: {
|
||||
'io.balena.features.supervisor-api': '1',
|
||||
},
|
||||
},
|
||||
{
|
||||
appName: 'test',
|
||||
supervisorApiHost: 'supervisor',
|
||||
listenPort: 48484,
|
||||
} as any,
|
||||
);
|
||||
|
||||
expect(
|
||||
service.config.environment['BALENA_SUPERVISOR_API_KEY'],
|
||||
).to.be.equal(mykey);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -8,7 +8,6 @@ import Service from '~/src/compose/service';
|
||||
import Volume from '~/src/compose/volume';
|
||||
import * as ServiceT from '~/src/compose/types/service';
|
||||
import * as constants from '~/lib/constants';
|
||||
import * as apiKeys from '~/lib/api-keys';
|
||||
|
||||
import log from '~/lib/supervisor-console';
|
||||
|
||||
@ -30,7 +29,7 @@ const configs = {
|
||||
},
|
||||
};
|
||||
|
||||
describe('compose/service', () => {
|
||||
describe('compose/service: unit tests', () => {
|
||||
before(() => {
|
||||
// disable log output during testing
|
||||
sinon.stub(log, 'debug');
|
||||
@ -825,66 +824,6 @@ describe('compose/service', () => {
|
||||
.that.deep.equals([gpuDeviceRequest]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('io.balena.supervisor-api', () => {
|
||||
it('sets BALENA_SUPERVISOR_HOST, BALENA_SUPERVISOR_PORT and BALENA_SUPERVISOR_ADDRESS env vars', async () => {
|
||||
const service = await Service.fromComposeObject(
|
||||
{
|
||||
appId: 123456,
|
||||
serviceId: 123456,
|
||||
serviceName: 'foobar',
|
||||
labels: {
|
||||
'io.balena.features.supervisor-api': '1',
|
||||
},
|
||||
},
|
||||
{
|
||||
appName: 'test',
|
||||
supervisorApiHost: 'supervisor',
|
||||
listenPort: 48484,
|
||||
} as any,
|
||||
);
|
||||
|
||||
expect(
|
||||
service.config.environment['BALENA_SUPERVISOR_HOST'],
|
||||
).to.be.equal('supervisor');
|
||||
|
||||
expect(
|
||||
service.config.environment['BALENA_SUPERVISOR_PORT'],
|
||||
).to.be.equal('48484');
|
||||
|
||||
expect(
|
||||
service.config.environment['BALENA_SUPERVISOR_ADDRESS'],
|
||||
).to.be.equal('http://supervisor:48484');
|
||||
});
|
||||
|
||||
it('sets BALENA_API_KEY env var to the scoped API key value', async () => {
|
||||
// TODO: should we add an integration test that checks that the value used for the API key comes
|
||||
// from the database
|
||||
sinon.stub(apiKeys, 'generateScopedKey').resolves('this is a secret');
|
||||
|
||||
const service = await Service.fromComposeObject(
|
||||
{
|
||||
appId: 123456,
|
||||
serviceId: 123456,
|
||||
serviceName: 'foobar',
|
||||
labels: {
|
||||
'io.balena.features.supervisor-api': '1',
|
||||
},
|
||||
},
|
||||
{
|
||||
appName: 'test',
|
||||
supervisorApiHost: 'supervisor',
|
||||
listenPort: 48484,
|
||||
} as any,
|
||||
);
|
||||
|
||||
expect(
|
||||
service.config.environment['BALENA_SUPERVISOR_API_KEY'],
|
||||
).to.be.equal('this is a secret');
|
||||
|
||||
(apiKeys.generateScopedKey as sinon.SinonStub).restore();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Creating service instances from docker configuration', () => {
|
Loading…
x
Reference in New Issue
Block a user