Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration testing refactor stage 1 #82

Merged
merged 5 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 2 additions & 29 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -325,33 +325,6 @@ integration:nix:
# Runs on tag pipeline where the tag is a prerelease or release version
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/

.integration:docker-disabled:
stage: integration
needs:
- integration:builds
- job: integration:deployment
optional: true
services:
- docker:20.10.16-dind
variables:
DOCKER_TLS_CERTDIR: "/certs"
FF_NETWORK_PER_BUILD: "true"
PK_TEST_PLATFORM: "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)";
PK_TEST_COMMAND="docker run \$DOCKER_OPTIONS $image_and_tag" npm run test;
'
rules:
# Runs on staging commits and ignores version commits
- if: $CI_COMMIT_BRANCH == 'staging' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/
# Runs on tag pipeline where the tag is a prerelease or release version
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/

integration:docker:
stage: integration
needs:
Expand All @@ -363,15 +336,15 @@ integration:docker:
variables:
DOCKER_TLS_CERTDIR: "/certs"
FF_NETWORK_PER_BUILD: "true"
PK_TEST_PLATFORM: "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)";
docker run $image_and_tag;
docker tag "$image_and_tag" "polykey-cli:testtarget";
npm run test tests/integration/docker;
'
rules:
# Runs on staging commits and ignores version commits
Expand Down
2 changes: 0 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ const globals = {
failedConnectionTimeout: 50000,
// Timeouts rely on setTimeout which takes 32 bit numbers
maxTimeout: Math.pow(2, 31) - 1,
testCmd: process.env.PK_TEST_COMMAND,
testPlatform: process.env.PK_TEST_PLATFORM,
tmpDir: path.resolve(process.env.PK_TEST_TMPDIR ?? os.tmpdir()),
};

Expand Down
4 changes: 4 additions & 0 deletions scripts/check-test-generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ for test_dir in tests/**/*/; do
if [[ "$test_dir" =~ discovery ]]; then
continue
fi
# Ignore integration domain for now
if [[ "$test_dir" =~ integration ]]; then
continue
fi
test_files=("$test_dir"*.test.ts)
if [ ${#test_files[@]} -eq 0 ]; then
continue
Expand Down
63 changes: 28 additions & 35 deletions tests/agent/lock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,19 @@ describe('lock', () => {
afterEach(async () => {
await agentClose();
});
testUtils.testIf(
testUtils.isTestPlatformEmpty || testUtils.isTestPlatformDocker,
)('lock deletes the session token', async () => {
test('lock deletes the session token', async () => {
await testUtils.pkExec(['agent', 'unlock'], {
env: {
PK_NODE_PATH: agentDir,
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 All @@ -47,34 +43,31 @@ describe('lock', () => {
expect(await session.readToken()).toBeUndefined();
await session.stop();
});
testUtils.testIf(testUtils.isTestPlatformEmpty)(
'lock ensures re-authentication is required',
async () => {
const password = agentPassword;
prompts.mockClear();
prompts.mockImplementation(async (_opts: any) => {
return { password };
});
await testUtils.pkStdio(['agent', 'unlock'], {
env: {
PK_NODE_PATH: agentDir,
PK_PASSWORD: agentPassword,
},
cwd: agentDir,
});
// Session token is deleted
await testUtils.pkStdio(['agent', 'lock'], {
env: { PK_NODE_PATH: agentDir },
cwd: agentDir,
});
// Will prompt to reauthenticate
await testUtils.pkStdio(['agent', 'status'], {
env: { PK_NODE_PATH: agentDir },
cwd: agentDir,
});
// Prompted for password 1 time
expect(prompts.mock.calls.length).toBe(1);
prompts.mockClear();
},
);
test('lock ensures re-authentication is required', async () => {
const password = agentPassword;
prompts.mockClear();
prompts.mockImplementation(async (_opts: any) => {
return { password };
});
await testUtils.pkStdio(['agent', 'unlock'], {
env: {
PK_NODE_PATH: agentDir,
PK_PASSWORD: agentPassword,
},
cwd: agentDir,
});
// Session token is deleted
await testUtils.pkStdio(['agent', 'lock'], {
env: { PK_NODE_PATH: agentDir },
cwd: agentDir,
});
// Will prompt to reauthenticate
await testUtils.pkStdio(['agent', 'status'], {
env: { PK_NODE_PATH: agentDir },
cwd: agentDir,
});
// Prompted for password 1 time
expect(prompts.mock.calls.length).toBe(1);
prompts.mockClear();
});
});
68 changes: 28 additions & 40 deletions tests/agent/lockall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,17 @@ describe('lockall', () => {
afterEach(async () => {
await agentClose();
});
testUtils.testIf(
testUtils.isTestPlatformEmpty || testUtils.isTestPlatformDocker,
)('lockall deletes the session token', async () => {
test('lockall deletes the session token', async () => {
await testUtils.pkExec(['agent', 'unlock'], {
env: {
PK_NODE_PATH: agentDir,
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 All @@ -51,45 +47,39 @@ describe('lockall', () => {
expect(await session.readToken()).toBeUndefined();
await session.stop();
});
testUtils.testIf(testUtils.isTestPlatformEmpty)(
'lockall ensures re-authentication is required',
async () => {
const password = agentPassword;
await testUtils.pkStdio(['agent', 'unlock'], {
env: {
PK_NODE_PATH: agentDir,
PK_PASSWORD: agentPassword,
},
cwd: agentDir,
});
await testUtils.pkStdio(['agent', 'lockall'], {
env: { PK_NODE_PATH: agentDir },
cwd: agentDir,
});
// Token is deleted, re-authentication is required
prompts.mockClear();
prompts.mockImplementation(async (_opts: any) => {
return { password };
});
await testUtils.pkStdio(['agent', 'status'], {
env: { PK_NODE_PATH: agentDir },
cwd: agentDir,
});
// Prompted for password 1 time
expect(prompts.mock.calls.length).toBe(1);
prompts.mockClear();
},
);
testUtils.testIf(
testUtils.isTestPlatformEmpty || testUtils.isTestPlatformDocker,
)('lockall causes old session tokens to fail', async () => {
test('lockall ensures re-authentication is required', async () => {
const password = agentPassword;
await testUtils.pkStdio(['agent', 'unlock'], {
env: {
PK_NODE_PATH: agentDir,
PK_PASSWORD: agentPassword,
},
cwd: agentDir,
});
await testUtils.pkStdio(['agent', 'lockall'], {
env: { PK_NODE_PATH: agentDir },
cwd: agentDir,
});
// Token is deleted, re-authentication is required
prompts.mockClear();
prompts.mockImplementation(async (_opts: any) => {
return { password };
});
await testUtils.pkStdio(['agent', 'status'], {
env: { PK_NODE_PATH: agentDir },
cwd: agentDir,
});
// Prompted for password 1 time
expect(prompts.mock.calls.length).toBe(1);
prompts.mockClear();
});
test('lockall causes old session tokens to fail', async () => {
await testUtils.pkExec(['agent', 'unlock'], {
env: {
PK_NODE_PATH: agentDir,
PK_PASSWORD: agentPassword,
},
cwd: agentDir,
command: globalThis.testCmd,
});
const session = await Session.createSession({
sessionTokenPath: path.join(agentDir, config.paths.tokenBase),
Expand All @@ -104,7 +94,6 @@ describe('lockall', () => {
PK_PASSWORD: agentPassword,
},
cwd: agentDir,
command: globalThis.testCmd,
});
// Old token is invalid
const { exitCode, stderr } = await testUtils.pkExec(
Expand All @@ -115,7 +104,6 @@ describe('lockall', () => {
PK_TOKEN: token,
},
cwd: agentDir,
command: globalThis.testCmd,
},
);
testUtils.expectProcessError(exitCode, stderr, [
Expand Down
Loading