Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Commit

Permalink
Fix sporadic conflict between agile_keychain test and CLI test
Browse files Browse the repository at this point in the history
Both test suites contained tests that tried to create a vault
in /tmp/new-vault.agilekeychain

Fix this by adding a utility function for getting a per-suite
temp dir name for tests under /tmp/passcards-tests/<suite-name>
and using that.
  • Loading branch information
Robert Knight committed Aug 7, 2015
1 parent 7c523e0 commit 7994733
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 18 deletions.
22 changes: 11 additions & 11 deletions lib/agile_keychain_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ class TestCase {
itemDataPath: string;
}

var TEST_VAULTS: TestCase[] = [
const TEST_VAULTS: TestCase[] = [
{
path: 'test.agilekeychain',
password: 'logMEin',
itemDataPath: 'test.1pif'
}
];

var fs = new nodefs.FileVFS('lib/test-data');
let fs = new nodefs.FileVFS('lib/test-data');

class ItemAndContent {
item: item_store.Item;
Expand All @@ -57,7 +57,7 @@ function createEmptyVault() {
let fs = new nodefs.FileVFS('/');
let vault: agile_keychain.Vault;

return vfs_util.mktemp(fs, '/tmp', 'vault.XXX').then(path => {
return vfs_util.mktemp(fs, testLib.tempDir(), 'vault.XXX').then(path => {
return agile_keychain.Vault.createVault(fs, path, VAULT_PASS, '', VAULT_PASS_ITER);
}).then(vault_ => {
vault = vault_;
Expand All @@ -67,7 +67,7 @@ function createEmptyVault() {

function createTestVault() {
let sourcePath = path.resolve('lib/test-data');
let copyPath = '/tmp/copy.agilekeychain';
let copyPath = testLib.tempDir() + '/copy.agilekeychain';

let vault: agile_keychain.Vault;
let fs = new nodefs.FileVFS('/');
Expand Down Expand Up @@ -489,12 +489,12 @@ testLib.addAsyncTest('Encrypt/decrypt key (async)', (assert) => {
});

testLib.addAsyncTest('Create new vault', (assert) => {
var fs = new nodefs.FileVFS('/tmp');
var pass = 'test-new-vault-pass';
var hint = 'the-password-hint';
var vault: agile_keychain.Vault;
var keyIterations = 100;
var vaultDir = '/new-vault';
let fs = new nodefs.FileVFS(testLib.tempDir());
let pass = 'test-new-vault-pass';
let hint = 'the-password-hint';
let vault: agile_keychain.Vault;
let keyIterations = 100;
let vaultDir = '/new-vault';

return vfs_util.rmrf(fs, vaultDir + '.agilekeychain').then(() => {
return agile_keychain.Vault.createVault(fs, vaultDir, pass, hint, keyIterations)
Expand Down Expand Up @@ -618,7 +618,7 @@ testLib.addTest('Default item properties', (assert) => {
});

testLib.addTest('createVault() fails if directory exists', (assert) => {
var fs = new nodefs.FileVFS('/tmp');
var fs = new nodefs.FileVFS(testLib.tempDir());
var pass = 'pass-1';
var hint = 'test-new-vault-hint';
var keyIterations = 100;
Expand Down
8 changes: 5 additions & 3 deletions lib/base/streamutil_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import streamutil = require('./streamutil');
import testLib = require('../test');

testLib.addAsyncTest('read binary stream', (assert) => {
var PNG_MAGIC = [0x89, 0x50, 0x4e, 0x47];
fs.writeFileSync('/tmp/test.png', new Buffer(PNG_MAGIC));
var testFile = fs.createReadStream('/tmp/test.png');
const PNG_MAGIC = [0x89, 0x50, 0x4e, 0x47];
const TEST_PATH = `${testLib.tempDir() }/test.png`;

fs.writeFileSync(TEST_PATH, new Buffer(PNG_MAGIC));
let testFile = fs.createReadStream(TEST_PATH);
return streamutil.readAll(testFile).then((content) => {
assert.equal(content, '\x89PNG');
});
Expand Down
2 changes: 1 addition & 1 deletion lib/sync_int_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ global.IDBKeyRange = require('fake-indexeddb/lib/FDBKeyRange');

testLib.addAsyncTest('saves and syncs items', assert => {
let db = new key_value_store.IndexedDBDatabase();
let fs = new vfs_node.FileVFS('/tmp/sync-integration-test');
let fs = new vfs_node.FileVFS(`${testLib.tempDir() }/sync-integration-test`);
let keyAgent = new key_agent.SimpleKeyAgent();
let agileKeychainStore: item_store.Store;
let localStore = new local_store.Store(db, 'local', keyAgent);
Expand Down
17 changes: 17 additions & 0 deletions lib/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import assert = require('assert');
import argparse = require('argparse');
import colors = require('colors');
import fs = require('fs');
import mkdirp = require('mkdirp');
import path = require('path');
import underscore = require('underscore');
import xdiff = require('xdiff');
Expand Down Expand Up @@ -291,6 +292,22 @@ export function start(args?: string[]) {
}
}

/** Returns the path to a temporary data directory for
* use by the current test suite.
*/
export function tempDir() {
let tmpDir: string;
if (process.env.TMPDIR) {
tmpDir = process.env.TMPDIR;
} else {
tmpDir = '/tmp';
}
let testSuiteName = path.basename(process.argv[1]);
let dirPath = `${tmpDir}/passcards-tests/${testSuiteName}`;
mkdirp.sync(dirPath);
return dirPath;
}

function run(tests: TestCase[]) {
// randomize ordering of tests
tests = underscore(tests).shuffle();
Expand Down
2 changes: 1 addition & 1 deletion lib/vfs/util_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import asyncutil = require('../base/asyncutil');
var fs_extra = require('fs-extra');

testLib.addAsyncTest('mktemp', (assert) => {
const TEST_DIR = '/tmp/vfs-util-test';
const TEST_DIR = `${testLib.tempDir() }/vfs-util-test`;
const ITER_COUNT = 10;

fs_extra.emptyDirSync(TEST_DIR);
Expand Down
4 changes: 2 additions & 2 deletions lib/vfs/vfs_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class StorageEntry {
}

var createNodeFs = () => {
var TEST_DIR = '/tmp/vfs-test';
var fs = new nodefs.FileVFS(TEST_DIR);
let TEST_DIR = `${testLib.tempDir() }/vfs-test`;
let fs = new nodefs.FileVFS(TEST_DIR);
return vfs_util.rmrf(fs, '')
.then(() => {
return fs.mkpath('');
Expand Down

0 comments on commit 7994733

Please sign in to comment.