mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-21 10:01:55 +00:00
Migrate simple legacy tests to test/unit and test/integration
Change-type: patch
This commit is contained in:
parent
1185b92bb4
commit
620bcae53a
45
test/integration/lib/os-release.spec.ts
Normal file
45
test/integration/lib/os-release.spec.ts
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import { expect } from 'chai';
|
||||||
|
import { testfs, TestFs } from 'mocha-pod';
|
||||||
|
|
||||||
|
import * as osRelease from '~/lib/os-release';
|
||||||
|
|
||||||
|
describe('lib/os-release', () => {
|
||||||
|
let tfs: TestFs.Enabled;
|
||||||
|
before(async () => {
|
||||||
|
tfs = await testfs({
|
||||||
|
'/etc/os-release': testfs.from('test/data/etc/os-release-tx2'),
|
||||||
|
}).enable();
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async () => {
|
||||||
|
await tfs.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gets pretty name', async () => {
|
||||||
|
// Try to get PRETTY_NAME
|
||||||
|
await expect(osRelease.getOSVersion('/etc/os-release')).to.eventually.equal(
|
||||||
|
'balenaOS 2.45.1+rev3',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gets variant', async () => {
|
||||||
|
// Try to get VARIANT_ID
|
||||||
|
await expect(osRelease.getOSVariant('/etc/os-release')).to.eventually.equal(
|
||||||
|
'prod',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gets version', async () => {
|
||||||
|
// Try to get VERSION
|
||||||
|
await expect(osRelease.getOSSemver('/etc/os-release')).to.eventually.equal(
|
||||||
|
'2.45.1+rev3',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gets meta release version', async () => {
|
||||||
|
// Try to get META_BALENA_VERSIONS
|
||||||
|
await expect(
|
||||||
|
osRelease.getMetaOSRelease('/etc/os-release'),
|
||||||
|
).to.eventually.equal('2.45.1');
|
||||||
|
});
|
||||||
|
});
|
36
test/integration/network.spec.ts
Normal file
36
test/integration/network.spec.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import * as path from 'path';
|
||||||
|
import { promises as fs } from 'fs';
|
||||||
|
import { SinonStub } from 'sinon';
|
||||||
|
import { testfs } from 'mocha-pod';
|
||||||
|
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import Log from '~/lib/supervisor-console';
|
||||||
|
import * as network from '~/src/network';
|
||||||
|
import * as constants from '~/src/lib/constants';
|
||||||
|
|
||||||
|
describe('network', () => {
|
||||||
|
it('checks VPN connection status', async () => {
|
||||||
|
const vpnStatusPath = path.join(constants.vpnStatusPath, 'active');
|
||||||
|
|
||||||
|
// Logstub already exists as part of the test hooks
|
||||||
|
const logStub = Log.info as SinonStub;
|
||||||
|
|
||||||
|
// When VPN is inactive vpnStatusPath does not exist
|
||||||
|
await expect(
|
||||||
|
fs.access(vpnStatusPath),
|
||||||
|
'VPN active file does not exist before testing',
|
||||||
|
).to.be.rejected;
|
||||||
|
await expect(network.isVPNActive()).to.eventually.equal(false);
|
||||||
|
expect(logStub.lastCall?.lastArg).to.equal(`VPN connection is not active.`);
|
||||||
|
|
||||||
|
// Test when VPN is active
|
||||||
|
const testFs = await testfs({
|
||||||
|
[vpnStatusPath]: '',
|
||||||
|
}).enable();
|
||||||
|
await expect(network.isVPNActive()).to.eventually.equal(true);
|
||||||
|
expect(logStub.lastCall?.lastArg).to.equal(`VPN connection is active.`);
|
||||||
|
|
||||||
|
// Restore file system
|
||||||
|
await testFs.restore();
|
||||||
|
});
|
||||||
|
});
|
@ -1,9 +0,0 @@
|
|||||||
import { expect } from 'chai';
|
|
||||||
import * as constants from '~/lib/constants';
|
|
||||||
|
|
||||||
describe('constants', function () {
|
|
||||||
it('has the correct configJsonPathOnHost', () =>
|
|
||||||
expect(constants.configJsonPathOnHost).to.equal('/config.json'));
|
|
||||||
it('has the correct rootMountPoint', () =>
|
|
||||||
expect(constants.rootMountPoint).to.equal('./test/data'));
|
|
||||||
});
|
|
@ -9,6 +9,8 @@ import * as constants from '~/src/lib/constants';
|
|||||||
import { docker } from '~/lib/docker-utils';
|
import { docker } from '~/lib/docker-utils';
|
||||||
import { Supervisor } from '~/src/supervisor';
|
import { Supervisor } from '~/src/supervisor';
|
||||||
|
|
||||||
|
// TODO: remove this when we can test proper supervisor startup during
|
||||||
|
// integration tests
|
||||||
describe('Startup', () => {
|
describe('Startup', () => {
|
||||||
let startStub: SinonStub;
|
let startStub: SinonStub;
|
||||||
let vpnStatusPathStub: SinonStub;
|
let vpnStatusPathStub: SinonStub;
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
import { expect } from 'chai';
|
|
||||||
|
|
||||||
import * as osRelease from '~/lib/os-release';
|
|
||||||
|
|
||||||
const OS_RELEASE_PATH = 'test/data/etc/os-release-tx2';
|
|
||||||
|
|
||||||
describe('OS Release Information', () => {
|
|
||||||
it('gets pretty name', async () => {
|
|
||||||
// Try to get PRETTY_NAME
|
|
||||||
await expect(osRelease.getOSVersion(OS_RELEASE_PATH)).to.eventually.equal(
|
|
||||||
'balenaOS 2.45.1+rev3',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('gets variant', async () => {
|
|
||||||
// Try to get VARIANT_ID
|
|
||||||
await expect(osRelease.getOSVariant(OS_RELEASE_PATH)).to.eventually.equal(
|
|
||||||
'prod',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('gets version', async () => {
|
|
||||||
// Try to get VERSION
|
|
||||||
await expect(osRelease.getOSSemver(OS_RELEASE_PATH)).to.eventually.equal(
|
|
||||||
'2.45.1+rev3',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('gets meta release version', async () => {
|
|
||||||
// Try to get META_BALENA_VERSIONS
|
|
||||||
await expect(
|
|
||||||
osRelease.getMetaOSRelease(OS_RELEASE_PATH),
|
|
||||||
).to.eventually.equal('2.45.1');
|
|
||||||
});
|
|
||||||
});
|
|
@ -6,7 +6,7 @@ const PortMapPublic = PortMap as any as new (
|
|||||||
portStrOrObj: string | PortRange,
|
portStrOrObj: string | PortRange,
|
||||||
) => PortMap;
|
) => PortMap;
|
||||||
|
|
||||||
describe('Ports', function () {
|
describe('compose/ports', function () {
|
||||||
describe('Port string parsing', function () {
|
describe('Port string parsing', function () {
|
||||||
it('should correctly parse a port string without a range', function () {
|
it('should correctly parse a port string without a range', function () {
|
||||||
expect(new PortMapPublic('80')).to.deep.equal(
|
expect(new PortMapPublic('80')).to.deep.equal(
|
@ -1,7 +1,7 @@
|
|||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import * as ComposeUtils from '~/src/compose/utils';
|
import * as ComposeUtils from '~/src/compose/utils';
|
||||||
|
|
||||||
describe('Composition utilities', () =>
|
describe('compose/utils', () =>
|
||||||
it('Should correctly camel case the configuration', function () {
|
it('Should correctly camel case the configuration', function () {
|
||||||
const config = {
|
const config = {
|
||||||
networks: ['test', 'test2'],
|
networks: ['test', 'test2'],
|
@ -1,7 +1,7 @@
|
|||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import * as conversion from '~/lib/conversions';
|
import * as conversion from '~/lib/conversions';
|
||||||
|
|
||||||
describe('conversions', function () {
|
describe('lib/conversions', function () {
|
||||||
describe('envArrayToObject', function () {
|
describe('envArrayToObject', function () {
|
||||||
it('should convert an env array to an object', () =>
|
it('should convert an env array to an object', () =>
|
||||||
expect(
|
expect(
|
@ -4,7 +4,7 @@ import { expect } from 'chai';
|
|||||||
import constants = require('~/lib/constants');
|
import constants = require('~/lib/constants');
|
||||||
import { spawnJournalctl } from '~/lib/journald';
|
import { spawnJournalctl } from '~/lib/journald';
|
||||||
|
|
||||||
describe('journald', () => {
|
describe('lib/journald', () => {
|
||||||
let spawn: SinonStub;
|
let spawn: SinonStub;
|
||||||
|
|
||||||
beforeEach((done) => {
|
beforeEach((done) => {
|
||||||
@ -17,6 +17,8 @@ describe('journald', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO: this test is not really that useful as it basically is just testing
|
||||||
|
// the internal implementation of the method
|
||||||
it('spawnJournalctl calls spawn child process with expected args', () => {
|
it('spawnJournalctl calls spawn child process with expected args', () => {
|
||||||
spawnJournalctl({
|
spawnJournalctl({
|
||||||
all: true,
|
all: true,
|
@ -1,9 +1,7 @@
|
|||||||
import { promises as fs } from 'fs';
|
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import { stub, spy } from 'sinon';
|
import { stub } from 'sinon';
|
||||||
|
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import Log from '~/lib/supervisor-console';
|
|
||||||
import * as network from '~/src/network';
|
import * as network from '~/src/network';
|
||||||
|
|
||||||
describe('network', () => {
|
describe('network', () => {
|
||||||
@ -92,23 +90,4 @@ describe('network', () => {
|
|||||||
'2605:9080:1103:3011:2dbe:35e3:1b5a:b99',
|
'2605:9080:1103:3011:2dbe:35e3:1b5a:b99',
|
||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checks VPN connection status', async () => {
|
|
||||||
const statStub = stub(fs, 'lstat');
|
|
||||||
const logStub = spy(Log, 'info');
|
|
||||||
|
|
||||||
// Test when VPN is inactive
|
|
||||||
statStub.rejects(); // Reject so we can't stat the vpn active file
|
|
||||||
await expect(network.isVPNActive()).to.eventually.equal(false);
|
|
||||||
expect(logStub.lastCall?.lastArg).to.equal(`VPN connection is not active.`);
|
|
||||||
|
|
||||||
// Test when VPN is active
|
|
||||||
statStub.resolves(); // Resolve so we can stat the vpn active file
|
|
||||||
await expect(network.isVPNActive()).to.eventually.equal(true);
|
|
||||||
expect(logStub.lastCall?.lastArg).to.equal(`VPN connection is active.`);
|
|
||||||
|
|
||||||
// Restore stubs
|
|
||||||
statStub.restore();
|
|
||||||
logStub.restore();
|
|
||||||
});
|
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user