mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-22 15:02:23 +00:00
532e75a77e
This excludes route tests or refactoring. Also, created tests for API middleware. Change-type: patch Signed-off-by: Christina Ying Wang <christina@balena.io>
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
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 '~/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();
|
|
});
|
|
});
|