diff --git a/test/legacy/39-compose-commit.spec.ts b/test/integration/compose/commit.spec.ts similarity index 100% rename from test/legacy/39-compose-commit.spec.ts rename to test/integration/compose/commit.spec.ts diff --git a/test/integration/lib/os-release.spec.ts b/test/integration/lib/os-release.spec.ts new file mode 100644 index 00000000..c9f85322 --- /dev/null +++ b/test/integration/lib/os-release.spec.ts @@ -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'); + }); +}); diff --git a/test/integration/network.spec.ts b/test/integration/network.spec.ts new file mode 100644 index 00000000..19718ec5 --- /dev/null +++ b/test/integration/network.spec.ts @@ -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(); + }); +}); diff --git a/test/legacy/01-constants.spec.ts b/test/legacy/01-constants.spec.ts deleted file mode 100644 index 2a51fe0b..00000000 --- a/test/legacy/01-constants.spec.ts +++ /dev/null @@ -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')); -}); diff --git a/test/legacy/18-startup.spec.ts b/test/legacy/18-startup.spec.ts index 28de7119..1b87759a 100644 --- a/test/legacy/18-startup.spec.ts +++ b/test/legacy/18-startup.spec.ts @@ -9,6 +9,8 @@ import * as constants from '~/src/lib/constants'; import { docker } from '~/lib/docker-utils'; import { Supervisor } from '~/src/supervisor'; +// TODO: remove this when we can test proper supervisor startup during +// integration tests describe('Startup', () => { let startStub: SinonStub; let vpnStatusPathStub: SinonStub; diff --git a/test/legacy/35-os-release.spec.ts b/test/legacy/35-os-release.spec.ts deleted file mode 100644 index 47a48d29..00000000 --- a/test/legacy/35-os-release.spec.ts +++ /dev/null @@ -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'); - }); -}); diff --git a/test/legacy/15-ports.spec.ts b/test/unit/compose/ports.spec.ts similarity index 99% rename from test/legacy/15-ports.spec.ts rename to test/unit/compose/ports.spec.ts index 2b6a2ee5..02430d5c 100644 --- a/test/legacy/15-ports.spec.ts +++ b/test/unit/compose/ports.spec.ts @@ -6,7 +6,7 @@ const PortMapPublic = PortMap as any as new ( portStrOrObj: string | PortRange, ) => PortMap; -describe('Ports', function () { +describe('compose/ports', function () { describe('Port string parsing', function () { it('should correctly parse a port string without a range', function () { expect(new PortMapPublic('80')).to.deep.equal( diff --git a/test/legacy/19-compose-utils.spec.ts b/test/unit/compose/utils.spec.ts similarity index 88% rename from test/legacy/19-compose-utils.spec.ts rename to test/unit/compose/utils.spec.ts index a43ae015..aacab9ca 100644 --- a/test/legacy/19-compose-utils.spec.ts +++ b/test/unit/compose/utils.spec.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; import * as ComposeUtils from '~/src/compose/utils'; -describe('Composition utilities', () => +describe('compose/utils', () => it('Should correctly camel case the configuration', function () { const config = { networks: ['test', 'test2'], diff --git a/test/legacy/29-append-directive.spec.ts b/test/unit/config/append-directive.spec.ts similarity index 100% rename from test/legacy/29-append-directive.spec.ts rename to test/unit/config/append-directive.spec.ts diff --git a/test/legacy/30-fdt-directive.spec.ts b/test/unit/config/fdt-directive.spec.ts similarity index 100% rename from test/legacy/30-fdt-directive.spec.ts rename to test/unit/config/fdt-directive.spec.ts diff --git a/test/legacy/14-conversions.spec.ts b/test/unit/lib/conversions.spec.ts similarity index 97% rename from test/legacy/14-conversions.spec.ts rename to test/unit/lib/conversions.spec.ts index c55e5012..40255d45 100644 --- a/test/legacy/14-conversions.spec.ts +++ b/test/unit/lib/conversions.spec.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; import * as conversion from '~/lib/conversions'; -describe('conversions', function () { +describe('lib/conversions', function () { describe('envArrayToObject', function () { it('should convert an env array to an object', () => expect( diff --git a/test/legacy/25-journald.spec.ts b/test/unit/lib/journald.spec.ts similarity index 88% rename from test/legacy/25-journald.spec.ts rename to test/unit/lib/journald.spec.ts index 3517c629..3e261e14 100644 --- a/test/legacy/25-journald.spec.ts +++ b/test/unit/lib/journald.spec.ts @@ -4,7 +4,7 @@ import { expect } from 'chai'; import constants = require('~/lib/constants'); import { spawnJournalctl } from '~/lib/journald'; -describe('journald', () => { +describe('lib/journald', () => { let spawn: SinonStub; beforeEach((done) => { @@ -17,6 +17,8 @@ describe('journald', () => { 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', () => { spawnJournalctl({ all: true, diff --git a/test/legacy/09-network.spec.ts b/test/unit/network.spec.ts similarity index 71% rename from test/legacy/09-network.spec.ts rename to test/unit/network.spec.ts index 8a859cc7..4ff87d95 100644 --- a/test/legacy/09-network.spec.ts +++ b/test/unit/network.spec.ts @@ -1,9 +1,7 @@ -import { promises as fs } from 'fs'; import * as os from 'os'; -import { stub, spy } from 'sinon'; +import { stub } from 'sinon'; import { expect } from 'chai'; -import Log from '~/lib/supervisor-console'; import * as network from '~/src/network'; describe('network', () => { @@ -92,23 +90,4 @@ describe('network', () => { '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(); - }); });