Migrate lib/legacy tests to integration tests

This also sets up a dbus container as part of the test environment. This
container exposes a socket that the sut container can use
This commit is contained in:
Felipe Lalanne 2022-08-25 13:12:53 -04:00
parent a4da25c1ef
commit 18c2f8cec9
5 changed files with 40 additions and 26 deletions

View File

@ -6,12 +6,13 @@ testfs:
# them in the local source. These can be overriden
# in the `testfs` configuration.
filesystem:
/mnt/boot/config.json:
from: test/data/testconfig.json
/mnt/boot/config.txt:
from: test/data/mnt/boot/config.txt
/mnt/boot/device-type.json:
from: test/data/mnt/boot/device-type.json
/mnt/root:
/mnt/boot/config.json:
from: test/data/testconfig.json
/mnt/boot/config.txt:
from: test/data/mnt/boot/config.txt
/mnt/boot/device-type.json:
from: test/data/mnt/boot/device-type.json
/mnt/root/etc/os-release:
from: test/data/etc/os-release
# The `keep` list defines files that already exist in the

View File

@ -9,6 +9,10 @@ services:
context: ./
command: sleep infinity
dbus:
build:
context: ./test/lib/dbus/
docker:
image: docker:dind
privileged: true
@ -28,16 +32,19 @@ services:
depends_on:
- balena-supervisor
- docker
- dbus
# Set required supervisor configuration variables here
environment:
DOCKER_HOST: tcp://docker:2375
DBUS_SYSTEM_BUS_ADDRESS: tcp:host=dbus,port=6667,family=ipv4
# Required by migrations
CONFIG_MOUNT_POINT: /mnt/boot/config.json
CONFIG_MOUNT_POINT: /mnt/root/mnt/boot/config.json
# Read by constants to setup `bootMountpoint`
BOOT_MOUNTPOINT: /mnt/boot
# Set required mounts as tmpfs or volumes here
# if specific files need to be backed up between tests,
# make sure to add them to the `testfs` configuration under
# .mochapodrc.yml
tmpfs:
- /data
- /mnt/boot
- /mnt/root

View File

@ -1,40 +1,29 @@
import { expect } from 'chai';
import { isRight } from 'fp-ts/lib/Either';
import * as sinon from 'sinon';
import * as nock from 'nock';
import { TargetState } from '~/src/types';
import * as config from '~/src/config';
import * as legacy from '~/lib/legacy';
import log from '~/lib/supervisor-console';
describe('lib/legacy', () => {
before(async () => {
// disable log output during testing
sinon.stub(log, 'debug');
sinon.stub(log, 'warn');
sinon.stub(log, 'info');
sinon.stub(log, 'event');
sinon.stub(log, 'success');
await config.initialized;
// Set the device uuid and name
// these migration methods read some data from the database
// (and other data from the API)
// which is also why they need to be defined as integration tests
// TODO: when the supervisor is a full app, we'll be able to control updates
// using contracts, meaning this legacy code can dissapear
await config.set({ uuid: 'local' });
await config.set({ name: 'my-device' });
});
after(() => {
sinon.restore();
});
describe('Converting target state v2 to v3', () => {
it('accepts a local target state with empty configuration', async () => {
const target = await legacy.fromV2TargetState({} as any, true);
const decoded = TargetState.decode(target);
if (!isRight(decoded)) {
console.log(decoded.left);
// We do it this way let the type guard be triggered
expect.fail('Resulting target state is a valid v3 target state');
}
@ -152,7 +141,6 @@ describe('lib/legacy', () => {
const decoded = TargetState.decode(target);
if (!isRight(decoded)) {
console.log(decoded.left);
// We do it this way let the type guard be triggered
expect.fail('Resulting target state is a valid v3 target state');
}
@ -228,7 +216,6 @@ describe('lib/legacy', () => {
const decoded = TargetState.decode(target);
if (!isRight(decoded)) {
console.log(decoded.left);
// We do it this way let the type guard be triggered
expect.fail('Resulting target state is a valid v3 target state');
}

10
test/lib/dbus/Dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM ubuntu:20.04
# Install Systemd
RUN apt-get update && apt-get install -y --no-install-recommends \
dbus \
&& rm -rf /var/lib/apt/lists/*
COPY dbus.conf /etc/dbus-1/session.d/
ENTRYPOINT ["dbus-run-session", "sleep", "infinity"]

9
test/lib/dbus/dbus.conf Normal file
View File

@ -0,0 +1,9 @@
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<listen>tcp:host=localhost,bind=*,port=6667,family=ipv4</listen>
<listen>unix:tmpdir=/tmp</listen>
<auth>ANONYMOUS</auth>
<allow_anonymous/>
</busconfig>