summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-03-14 17:25:56 +0100
committerOskar Nyberg <oskar@mullvad.net>2021-03-15 16:01:20 +0100
commitf9c783ffd9076a8cca06f5320a464080dabe5fab (patch)
tree6d62d416482fd6ff7f9b2b62f268f66b0da85343
parentfd1e6e6ed95c88997583bd13a5b9f7d61afd118a (diff)
downloadmullvadvpn-f9c783ffd9076a8cca06f5320a464080dabe5fab.tar.xz
mullvadvpn-f9c783ffd9076a8cca06f5320a464080dabe5fab.zip
Add normalization of paths in logging tests
-rw-r--r--gui/test/logging.spec.ts30
1 files changed, 18 insertions, 12 deletions
diff --git a/gui/test/logging.spec.ts b/gui/test/logging.spec.ts
index 7d4edf386f..92f1a92e1f 100644
--- a/gui/test/logging.spec.ts
+++ b/gui/test/logging.spec.ts
@@ -2,14 +2,15 @@ import { expect, spy } from 'chai';
import fs from 'fs';
import sinon from 'sinon';
import { it, describe, before, beforeEach, after } from 'mocha';
+import path from 'path';
import { Logger } from '../src/shared/logging';
import { backupLogFile, rotateOrDeleteFile } from '../src/main/logging';
import { LogLevel } from '../src/shared/logging-types';
-const aPath = 'log-directory/a.log';
-const oldAPath = 'log-directory/a.old.log';
-const bPath = 'log-directory/b.log';
-const oldBPath = 'log-directory/b.old.log';
+const aPath = path.normalize('log-directory/a.log');
+const oldAPath = path.normalize('log-directory/a.old.log');
+const bPath = path.normalize('log-directory/b.log');
+const oldBPath = path.normalize('log-directory/b.old.log');
const initialFileState = {
[aPath]: 'a',
@@ -24,23 +25,28 @@ describe('Logging', () => {
before(() => {
sandbox = sinon.createSandbox();
- sandbox.stub(fs, 'accessSync').callsFake((path) => {
- if (files[path as string] === undefined) {
+ sandbox.stub(fs, 'accessSync').callsFake((filePath) => {
+ const normalizedPath = path.normalize(filePath as string);
+ if (files[normalizedPath] === undefined) {
throw Error('File not found');
}
});
sandbox.stub(fs, 'renameSync').callsFake((oldPath, newPath) => {
- files[newPath as string] = files[oldPath as string];
- fs.unlinkSync(oldPath);
+ const normalizedOldPath = path.normalize(oldPath as string);
+ const normalizedNewPath = path.normalize(newPath as string);
+ files[normalizedNewPath] = files[normalizedOldPath];
+ fs.unlinkSync(normalizedOldPath);
});
- sandbox.stub(fs, 'unlinkSync').callsFake((path) => {
- delete files[path as string];
+ sandbox.stub(fs, 'unlinkSync').callsFake((filePath) => {
+ const normalizedPath = path.normalize(filePath as string);
+ delete files[normalizedPath];
});
- sandbox.stub(fs, 'readFileSync').callsFake((path) => {
- return files[path as string] ?? '';
+ sandbox.stub(fs, 'readFileSync').callsFake((filePath) => {
+ const normalizedPath = path.normalize(filePath as string);
+ return files[normalizedPath] ?? '';
});
});