Skip to content

Commit 8f282c5

Browse files
committed
Support tests that require USERNAME and USER_TOKEN
1 parent 3044bdd commit 8f282c5

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

.werft/build.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,18 @@ pod:
221221
value: "/mnt/secrets/github-token-gitpod-bot/token"
222222
- name: WERFT_CREDENTIAL_HELPER
223223
value: "/workspace/dev/preview/werft-credential-helper.sh"
224+
# When running the build with 'with-integration-tests' these are used
225+
# to specify what Gitpod user to use in those tests.
226+
- name: INTEGRATION_TEST_USERNAME
227+
valueFrom:
228+
secretKeyRef:
229+
name: integration-test-user
230+
key: username
231+
- name: INTEGRATION_TEST_USER_TOKEN
232+
valueFrom:
233+
secretKeyRef:
234+
name: integration-test-user
235+
key: token
224236
command:
225237
- bash
226238
- -c

test/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ If you want to run an entire test suite, the easiest is to use `./test/run.sh`:
6060
./test/run.sh webapp
6161
```
6262

63-
If you're iterating on a single test, the easiest is to use `go test` directy. See the following command (it assume you have the `kubectx` set to your preview environment):
63+
If you're iterating on a single test, the easiest is to use `go test` directy. If your integration tests depends on having having a user token avaialble, then you'll have to set USER_TOKEN manually (see run.sh on how to fetch the credentials that are used during our build)
6464

6565
```sh
6666
cd test

test/run.sh

+16
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ args+=( "-namespace=default" )
4646
args+=( "-timeout=60m" )
4747
args+=( "-p=1" )
4848

49+
if [[ "${GITPOD_REPO_ROOT:-}" != "" ]]; then
50+
echo "Running in Gitpod workspace. Fetching USERNAME adn USER_TOKEN" | werft log slice "test-setup"
51+
USERNAME="$(kubectl --context=dev -n werft get secret integration-test-user -o jsonpath='{.data.username}' | base64 -d)"
52+
USER_TOKEN="$(kubectl --context=dev -n werft get secret integration-test-user -o jsonpath='{.data.token}' | base64 -d)"
53+
export USER_TOKEN
54+
else
55+
echo "Running in Werft. Using INTEGRATION_TEST_USERNAME and INTEGRATION_TEST_USER_TOKEN for USERNAME and USER_TOKEN" | werft log slice "test-setup"
56+
USERNAME="${INTEGRATION_TEST_USERNAME}"
57+
USER_TOKEN="${INTEGRATION_TEST_USER_TOKEN}"
58+
export USERNAME
59+
export USER_TOKEN
60+
fi
61+
werft log slice "test-setup" --done
62+
63+
[[ "$USERNAME" != "" ]] && args+=( "-username=$USERNAME" )
64+
4965
for TEST_PATH in ${TEST_LIST}
5066
do
5167
TEST_NAME=$(basename "${TEST_PATH}")

0 commit comments

Comments
 (0)