Skip to content

Commit c14dfdc

Browse files
committed
Fix ability to run integration tests in Werft
1 parent cc238b3 commit c14dfdc

File tree

8 files changed

+63
-194
lines changed

8 files changed

+63
-194
lines changed

.github/pull_request_template.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ Optional annotations to add to the werft job.
3636
* with-preview - whether to create a preview environment for this PR
3737
-->
3838
- [ ] /werft with-preview
39+
- [ ] /werft with-integration-tests=all
40+
Valid options are `all`, `workspace`, `webapp`, `ide`

.werft/build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { buildAndPublish } from "./jobs/build/build-and-publish";
88
import { validateChanges } from "./jobs/build/validate-changes";
99
import { prepare } from "./jobs/build/prepare";
1010
import { deployToPreviewEnvironment } from "./jobs/build/deploy-to-preview-environment";
11-
import { triggerIntegrationTests } from "./jobs/build/trigger-integration-tests";
11+
import { runIntegrationTests } from "./jobs/build/trigger-integration-tests";
1212
import { triggerSelfHostedPreview, triggerUpgradeTests } from "./jobs/build/self-hosted-upgrade-tests";
1313
import { jobConfig } from "./jobs/build/job-config";
1414
import { typecheckWerftJobs } from "./jobs/build/typecheck-werft-jobs";
@@ -82,5 +82,5 @@ async function run(context: any) {
8282
throw e;
8383
}
8484

85-
await triggerIntegrationTests(werft, config, context.Owner);
85+
await runIntegrationTests(werft, config, context.Owner);
8686
}

.werft/jobs/build/job-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface JobConfig {
2323
storage: string;
2424
version: string;
2525
withContrib: boolean;
26-
withIntegrationTests: boolean;
26+
withIntegrationTests?: string;
2727
withUpgradeTests: boolean;
2828
withSelfHostedPreview: boolean;
2929
withObservability: boolean;
@@ -78,7 +78,7 @@ export function jobConfig(werft: Werft, context: any): JobConfig {
7878
const withContrib = "with-contrib" in buildConfig || mainBuild;
7979
const withPreview = "with-preview" in buildConfig && !mainBuild;
8080
const storage = buildConfig["storage"] || "";
81-
const withIntegrationTests = "with-integration-tests" in buildConfig && !mainBuild;
81+
const withIntegrationTests = "with-integration-tests" in buildConfig ? buildConfig["with-integration-tests"] || "all" : null;
8282
const withUpgradeTests = "with-upgrade-tests" in buildConfig && !mainBuild;
8383
const fromVersion = withUpgradeTests ? buildConfig["from-version"] : "";
8484
const replicatedChannel = buildConfig["channel"];
Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,34 @@
11
import { exec } from "../../util/shell";
22
import { Werft } from "../../util/werft";
33
import { JobConfig } from "./job-config";
4+
import { PREVIEW_K3S_KUBECONFIG_PATH } from "./const";
45

56
const phases = {
6-
TRIGGER_INTEGRATION_TESTS: "trigger integration tests",
7+
RUN_INTEGRATION_TESTS: "Run integration tests",
78
};
89

910
/**
1011
* Trigger integration tests
1112
*/
12-
export async function triggerIntegrationTests(werft: Werft, config: JobConfig, username: string) {
13-
werft.phase(phases.TRIGGER_INTEGRATION_TESTS, "Trigger integration tests");
13+
export async function runIntegrationTests(werft: Werft, config: JobConfig, username: string) {
14+
werft.phase(phases.RUN_INTEGRATION_TESTS, "Run integration tests");
1415

1516
if (!config.withIntegrationTests) {
1617
// If we're skipping integration tests we wont trigger the job, which in turn won't create the
1718
// ci/werft/run-integration-tests Github Check. As ci/werft/run-integration-tests is a required
1819
// check this means you can't merge your PR without override checks.
19-
werft.log(phases.TRIGGER_INTEGRATION_TESTS, "Skipped integration tests");
20-
werft.done(phases.TRIGGER_INTEGRATION_TESTS);
20+
werft.log(phases.RUN_INTEGRATION_TESTS, "Skipped integration tests");
21+
werft.done(phases.RUN_INTEGRATION_TESTS);
2122
return;
2223
}
2324

2425
try {
25-
const imageVersion = exec(
26-
`docker run --rm eu.gcr.io/gitpod-core-dev/build/versions:${config.version} cat /versions.yaml | yq r - 'components.integrationTest.version'`,
27-
{ silent: true },
28-
).stdout.trim();
29-
30-
exec(`git config --global user.name "${username}"`);
31-
const annotations = [
32-
`version="${imageVersion}"`,
33-
`namespace="${config.previewEnvironment.namespace}"`,
34-
`username="${username}"`,
35-
`updateGitHubStatus="gitpod-io/gitpod"`,
36-
]
37-
.map((annotation) => `-a ${annotation}`)
38-
.join(" ");
39-
exec(`werft run --remote-job-path .werft/run-integration-tests.yaml ${annotations} github`, {
40-
slice: phases.TRIGGER_INTEGRATION_TESTS,
41-
}).trim();
42-
43-
werft.done(phases.TRIGGER_INTEGRATION_TESTS);
26+
exec(`KUBECONFIG="${PREVIEW_K3S_KUBECONFIG_PATH}" GOOGLE_APPLICATION_CREDENTIALS=/home/gitpod/.config/gcloud/legacy_credentials/[email protected]/adc.json /workspace/test/run.sh ${config.withIntegrationTests}`)
27+
werft.done(phases.RUN_INTEGRATION_TESTS);
4428
} catch (err) {
4529
if (!config.mainBuild) {
46-
werft.fail(phases.TRIGGER_INTEGRATION_TESTS, err);
30+
werft.fail(phases.RUN_INTEGRATION_TESTS, err);
4731
}
48-
exec("exit 0");
32+
throw err
4933
}
5034
}

.werft/run-integration-tests.yaml

Lines changed: 0 additions & 87 deletions
This file was deleted.

test/README.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,22 @@ Such tests are for example:
2121

2222
### Automatically at Gitpod
2323

24-
There is a [werft job](../.werft/run-integration-tests.yaml) that runs the integration tests against `core-dev` preview environments.
24+
You can opt-in to run the integrations tests as part of the build job. that runs the integration tests against preview environments.
2525

2626
> For tests that require an existing user the framework tries to automatically select one from the DB.
2727
> - On preview envs make sure to create one before running tests against it!
2828
> - If it's important to use a certain user (with fixed settings, for example) pass the additional `username` parameter.
2929
3030
Example command:
31-
```
32-
werft run github -j .werft/run-integration-tests.yaml -a namespace=staging-gpl-2658-int-tests -a version=gpl-2658-int-tests.57 -f
31+
32+
```sh
33+
werft run github -a with-preview=true -a with-integration-tests=true -f
3334
```
3435

3536
### Manually
3637

3738
You may want to run tests to assert whether a Gitpod installation is successfully integrated.
3839

39-
#### Using a pod
40-
41-
Best for when you want to validate an environment.
42-
43-
1. Update image name in `integration.yaml` for job `integration-job` to latest built by werft.
44-
2. Optionally add your username in that job argument or any other additional params.
45-
2. Apply yaml file that will add all necessary permissions and create a job that will run tests.
46-
* [`kubectl apply -f ./integration.yaml`](./integration.yaml)
47-
3. Check logs to inspect test results like so `kubectl logs -f jobs/integration-job`.
48-
4. Tear down the integration user and job when testing is done.
49-
* [`kubectl delete -f ./integration.yaml`](./integration.yaml)
50-
5140
#### Go test
5241

5342
This is best for when you're actively developing Gitpod.

test/integration.yaml

Lines changed: 0 additions & 62 deletions
This file was deleted.

test/run.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
THIS_DIR="$(dirname "$0")"
6+
7+
FAILURE_COUNT=0
8+
9+
#TODO: parse args here and add to TEST_LIST based on teams passed in
10+
#TODO: Also update docs with examples
11+
12+
if [[ "${TEST_LIST-}" == "" ]]; then
13+
TEST_LIST="$THIS_DIR/tests/components/* $THIS_DIR/tests/ide/* $THIS_DIR/tests/workspace"
14+
fi
15+
16+
args=()
17+
args+=( "-kubeconfig=${KUBECONFIG:-/home/gitpod/.kube/config}" )
18+
args+=( "-namespace=default" )
19+
[[ "${USERNAME:-}" != "" ]] && args+=( "-username=$USERNAME" )
20+
args+=( "-timeout=60m" )
21+
args+=( "-p=1" )
22+
23+
for TEST_PATH in ${TEST_LIST}
24+
do
25+
TEST_NAME=$(basename "${TEST_PATH}")
26+
echo "running integration for ${TEST_NAME}" | werft log slice "test-${TEST_NAME}"
27+
28+
cd "${TEST_PATH}"
29+
set +e
30+
go test -v ./... "${args[@]}" 2>&1 | tee "${TEST_NAME}.log" | werft log slice "test-${TEST_NAME}"
31+
RC=${PIPESTATUS[0]}
32+
set -e
33+
cd -
34+
35+
if [ "${RC}" -ne "0" ]; then
36+
FAILURE_COUNT=$((FAILURE_COUNT+1))
37+
werft log slice "test-${TEST_NAME}" --fail "${RC}"
38+
else
39+
werft log slice "test-${TEST_NAME}" --done
40+
fi
41+
done
42+
43+
exit $FAILURE_COUNT

0 commit comments

Comments
 (0)