Skip to content

Commit

Permalink
ci: fixing docker tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tegefaulkes committed Sep 26, 2022
1 parent 18cd6bb commit 724fd12
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ integration:docker:
PK_TEST_TMPDIR: "${CI_PROJECT_DIR}/tmp/test"
script:
- docker info
- mkdir $PK_TEST_TMPDIR
- >
nix-shell --arg ci true --run $'
image_and_tag="$(docker load --input ./builds/*docker* | cut -d\' \' -f3)";
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const globals = {
maxTimeout: Math.pow(2, 31) - 1,
testCmd: process.env.PK_TEST_COMMAND,
testPlatform: process.env.PK_TEST_PLATFORM,
tmpDir: process.env.PK_TEST_TMPDIR ?? os.tmpdir(),
tmpDir: path.resolve(process.env.PK_TEST_TMPDIR ?? os.tmpdir()),
};

// The `globalSetup` and `globalTeardown` cannot access the `globals`
Expand Down
2 changes: 2 additions & 0 deletions tests/bin/agent/lock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ describe('lock', () => {
PK_PASSWORD: agentPassword,
},
cwd: agentDir,
command: globalThis.testCmd,
});
const { exitCode } = await testUtils.pkExec(['agent', 'lock'], {
env: {
PK_NODE_PATH: agentDir,
},
cwd: agentDir,
command: globalThis.testCmd,
});
expect(exitCode).toBe(0);
const session = await Session.createSession({
Expand Down
5 changes: 5 additions & 0 deletions tests/bin/agent/lockall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ describe('lockall', () => {
PK_PASSWORD: agentPassword,
},
cwd: agentDir,
command: globalThis.testCmd,
});
const { exitCode } = await testUtils.pkExec(['agent', 'lockall'], {
env: { PK_NODE_PATH: agentDir },
cwd: agentDir,
command: globalThis.testCmd,
});
expect(exitCode).toBe(0);
const session = await Session.createSession({
Expand Down Expand Up @@ -92,6 +94,7 @@ describe('lockall', () => {
PK_PASSWORD: agentPassword,
},
cwd: agentDir,
command: globalThis.testCmd,
});
const session = await Session.createSession({
sessionTokenPath: path.join(agentDir, config.defaults.tokenBase),
Expand All @@ -106,6 +109,7 @@ describe('lockall', () => {
PK_PASSWORD: agentPassword,
},
cwd: agentDir,
command: globalThis.testCmd,
});
// Old token is invalid
const { exitCode, stderr } = await testUtils.pkExec(
Expand All @@ -116,6 +120,7 @@ describe('lockall', () => {
PK_TOKEN: token,
},
cwd: agentDir,
command: globalThis.testCmd,
},
);
testUtils.expectProcessError(exitCode, stderr, [
Expand Down
17 changes: 17 additions & 0 deletions tests/bin/agent/start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('start', () => {
PK_PASSWORD: password,
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger,
);
Expand Down Expand Up @@ -136,6 +137,7 @@ describe('start', () => {
PK_NODE_PATH: path.join(dataDir, 'polykey'),
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger,
);
Expand Down Expand Up @@ -235,6 +237,7 @@ describe('start', () => {
PK_PASSWORD: password,
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger.getChild('agentProcess1'),
),
Expand All @@ -260,6 +263,7 @@ describe('start', () => {
PK_PASSWORD: password,
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger.getChild('agentProcess2'),
),
Expand Down Expand Up @@ -333,6 +337,7 @@ describe('start', () => {
PK_PASSWORD: password,
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger.getChild('agentProcess'),
),
Expand All @@ -352,6 +357,7 @@ describe('start', () => {
PK_PASSWORD: password,
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger.getChild('bootstrapProcess'),
),
Expand Down Expand Up @@ -421,6 +427,7 @@ describe('start', () => {
PK_PASSWORD: password,
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger,
);
Expand Down Expand Up @@ -450,6 +457,7 @@ describe('start', () => {
PK_PASSWORD: password,
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger,
);
Expand Down Expand Up @@ -497,6 +505,7 @@ describe('start', () => {
PK_PASSWORD: password,
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger.getChild('agentProcess1'),
);
Expand Down Expand Up @@ -540,6 +549,7 @@ describe('start', () => {
PK_PASSWORD: password,
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger.getChild('agentProcess2'),
);
Expand Down Expand Up @@ -624,6 +634,7 @@ describe('start', () => {
PK_PASSWORD: password1,
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger.getChild('agentProcess1'),
);
Expand Down Expand Up @@ -662,6 +673,7 @@ describe('start', () => {
PK_PASSWORD: password2,
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger.getChild('agentProcess2'),
);
Expand All @@ -680,6 +692,7 @@ describe('start', () => {
PK_PASSWORD: password2,
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger.getChild('agentProcess3'),
);
Expand Down Expand Up @@ -716,6 +729,7 @@ describe('start', () => {
PK_RECOVERY_CODE: recoveryCode,
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger.getChild('agentProcess4'),
);
Expand Down Expand Up @@ -773,6 +787,7 @@ describe('start', () => {
PK_PASSWORD: password,
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger.getChild('agentProcess'),
);
Expand Down Expand Up @@ -816,6 +831,7 @@ describe('start', () => {
PK_ROOT_KEY: privateKeyPem,
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger,
);
Expand Down Expand Up @@ -869,6 +885,7 @@ describe('start', () => {
PK_PASSWORD: password,
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger,
);
Expand Down
7 changes: 7 additions & 0 deletions tests/bin/agent/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('status', () => {
PK_ROOT_KEY: globalRootKeyPems[0],
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger,
);
Expand All @@ -72,6 +73,7 @@ describe('status', () => {
PK_PASSWORD: password,
},
cwd: dataDir,
command: globalThis.testCmd,
},
));
expect(exitCode).toBe(0);
Expand All @@ -93,6 +95,7 @@ describe('status', () => {
PK_PASSWORD: password,
},
cwd: dataDir,
command: globalThis.testCmd,
},
));
expect(exitCode).toBe(0);
Expand All @@ -110,6 +113,7 @@ describe('status', () => {
PK_PASSWORD: password,
},
cwd: dataDir,
command: globalThis.testCmd,
},
));
expect(exitCode).toBe(0);
Expand All @@ -126,6 +130,7 @@ describe('status', () => {
['agent', 'status', '--format', 'json'],
{
env: { PK_NODE_PATH: path.join(dataDir, 'polykey') },
command: globalThis.testCmd,
},
);
expect(exitCode).toBe(0);
Expand Down Expand Up @@ -164,6 +169,7 @@ describe('status', () => {
PK_PASSWORD: agentPassword,
},
cwd: agentDir,
command: globalThis.testCmd,
},
);
expect(exitCode).toBe(0);
Expand Down Expand Up @@ -217,6 +223,7 @@ describe('status', () => {
{
env: {},
cwd: dataDir,
command: globalThis.testCmd,
},
);
expect(exitCode).toBe(0);
Expand Down
10 changes: 10 additions & 0 deletions tests/bin/agent/stop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe('stop', () => {
PK_ROOT_KEY: globalRootKeyPems[0],
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger,
);
Expand All @@ -67,6 +68,7 @@ describe('stop', () => {
PK_PASSWORD: password,
},
cwd: dataDir,
command: globalThis.testCmd,
});
await status.waitFor('DEAD');
await sleep(5000);
Expand Down Expand Up @@ -110,6 +112,7 @@ describe('stop', () => {
PK_ROOT_KEY: globalRootKeyPems[0],
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger,
);
Expand All @@ -121,12 +124,14 @@ describe('stop', () => {
PK_NODE_PATH: path.join(dataDir, 'polykey'),
},
cwd: dataDir,
command: globalThis.testCmd,
}),
testUtils.pkExec(['agent', 'stop', '--password-file', passwordPath], {
env: {
PK_NODE_PATH: path.join(dataDir, 'polykey'),
},
cwd: dataDir,
command: globalThis.testCmd,
}),
]);
// Cannot await for STOPPING
Expand All @@ -140,6 +145,7 @@ describe('stop', () => {
PK_PASSWORD: password,
},
cwd: dataDir,
command: globalThis.testCmd,
},
);
await status.waitFor('DEAD');
Expand All @@ -150,6 +156,7 @@ describe('stop', () => {
PK_NODE_PATH: path.join(dataDir, 'polykey'),
},
cwd: dataDir,
command: globalThis.testCmd,
},
);
// If the GRPC server gets closed after the GRPC connection is established
Expand Down Expand Up @@ -256,6 +263,7 @@ describe('stop', () => {
PK_ROOT_KEY: globalRootKeyPems[0],
},
cwd: dataDir,
command: globalThis.testCmd,
},
logger,
);
Expand All @@ -278,6 +286,7 @@ describe('stop', () => {
PK_PASSWORD: 'wrong password',
},
cwd: dataDir,
command: globalThis.testCmd,
},
);
testUtils.expectProcessError(exitCode, stderr, [
Expand All @@ -291,6 +300,7 @@ describe('stop', () => {
PK_PASSWORD: password,
},
cwd: dataDir,
command: globalThis.testCmd,
});
await status.waitFor('DEAD');
agentProcess.kill();
Expand Down
3 changes: 3 additions & 0 deletions tests/bin/agent/unlock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('unlock', () => {
PK_PASSWORD: agentPassword,
},
cwd: agentDir,
command: globalThis.testCmd,
}));
expect(exitCode).toBe(0);
// Run command without password
Expand All @@ -49,6 +50,7 @@ describe('unlock', () => {
PK_NODE_PATH: agentDir,
},
cwd: agentDir,
command: globalThis.testCmd,
},
));
expect(exitCode).toBe(0);
Expand All @@ -62,6 +64,7 @@ describe('unlock', () => {
PK_TOKEN: await session.readToken(),
},
cwd: agentDir,
command: globalThis.testCmd,
},
));
expect(exitCode).toBe(0);
Expand Down
Loading

0 comments on commit 724fd12

Please sign in to comment.