forked from gravitational/teleport
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Playwright E2E tests boilerplates (gravitational#29286)
* Add end-to-end tests with Playwright This commit introduces end-to-end tests with Docker Compose to improve code quality and provide a more robust testing environment. This involves adding a GitHub workflow for manually triggering the test suite, Makefile commands for running, the tests, and configurations. This addition will enable easier testing and provide a platform for future test development. * Cleanup * Only allow manual CI trigger * Ignore e2e tests in Jest configuration Added 'testPathIgnorePatterns' field to the Jest configuration in order to ignore end-to-end tests when running unit tests. * Address code review comments * Update e2e test environment for multi-architecture support Modified the end-to-end test setup scripts and docker files to support both Linux and MacOS architectures. The build process now detects the system architecture and downloads the appropriate version of `mkcert`. Also, there is a control flow to build binaries only if they don't exist and the build files are now mounted from the build directory instead of being copied. These changes aim to make the e2e tests more robust and adaptable to different development environments. * Update Makefile and teleport.yaml for testing improvements Continued refinement of testing process by updating the Makefile and teleport.yaml. Changes to the Makefile include additional phony targets, modification of build-binaries, and a new 'all' target which runs key steps in sequence. The teleport.yaml file was updated to version v3. * Fix makefile on MacOS * Add Readme
- Loading branch information
Showing
15 changed files
with
474 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: E2E Tests | ||
run-name: E2E Tests | ||
on: | ||
# Only allow manual triggers | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: Build binaries | ||
if: ${{ !startsWith(github.head_ref, 'dependabot/') }} | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: read | ||
|
||
container: | ||
image: ghcr.io/gravitational/teleport-buildbox-centos7:teleport14 | ||
env: | ||
GOCACHE: /tmp/gocache | ||
|
||
steps: | ||
- name: Checkout Teleport | ||
uses: actions/checkout@v3 | ||
|
||
- name: Prepare workspace | ||
uses: ./.github/actions/prepare-workspace | ||
|
||
- name: Run make | ||
run: | | ||
make binaries | ||
- name: Upload binaries | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: build | ||
path: ${{ github.workspace }}/build/ | ||
retention-days: 1 | ||
|
||
test: | ||
name: E2E Tests | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/download-artifact@master | ||
with: | ||
name: build | ||
path: ${{ github.workspace }}/build/ | ||
|
||
- name: Chmod binaries | ||
run: | | ||
chmod +x build/teleport | ||
chmod +x build/tctl | ||
chmod +x build/tsh | ||
- name: Build Images | ||
run: | | ||
make -C e2e build | ||
- name: Run Tests | ||
run: | | ||
make test-e2e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/playwright/.cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
SYSTEM_ARCH=$(shell go env GOARCH) | ||
OS=$(shell go env GOOS) | ||
|
||
.PHONY: test clean stop build all build-binaries | ||
test: | ||
# Build binaries if they don't exist | ||
test -f "../build/teleport" || make build-binaries | ||
docker compose up --abort-on-container-exit --exit-code-from e2e | ||
|
||
clean: | ||
docker volume rm e2e_teleport-config e2e_teleport-data | ||
|
||
stop: | ||
docker compose down | ||
|
||
build: | ||
docker compose build --build-arg BUILDARCH=$(SYSTEM_ARCH) | ||
docker compose create | ||
|
||
build-binaries: | ||
# Use Docker to build binaries on MacOS as the testsuite runs in a Linux container | ||
ifeq ($(OS),darwin) | ||
ARCH=$(SYSTEM_ARCH) make -C ../build.assets/ build-binaries | ||
else ifeq ($(OS),linux) | ||
make -C ../ full | ||
else | ||
@echo "Unsupported OS: $(OS)" | ||
@exit 1 | ||
endif | ||
|
||
all: | ||
make stop | ||
make clean || true # ignore if no volumes exist | ||
make build | ||
make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
## Teleport E2E Tests | ||
|
||
This directory contains end-to-end tests for Teleport. These tests are | ||
designed to be run against a live cluster. They are written in TS and use | ||
[Playwright](https://playwright.dev/) to interact with the browser. | ||
Docker compose is used to spin up a cluster for testing and to run the tests. | ||
|
||
### Running the tests | ||
```bash | ||
# Make all removes the existing docker volumes to ensure a clean state | ||
# and rebuild the containers | ||
make all | ||
``` | ||
or | ||
|
||
```bash | ||
# Only run tests | ||
make test | ||
``` | ||
|
||
### MacOS building notes | ||
|
||
Before running the tests on MacOS in Docker, you need to build Linux compatible binaries. | ||
Binaries are build using our Docker images inside `build.assets` directory. You can also | ||
build them manually using `make build-binaries` command. | ||
|
||
### Running tests for development | ||
|
||
Docker compose setup is designed to run tests in CI and create the same environment | ||
locally, so debugging potential issues is easier. E2E tests make changes to the cluster, | ||
so the order of the tests is important. To run tests for development, you can use | ||
`yarn test` command to run the test against the existing cluster. | ||
`yarn codegen` starts the Playwright codegen tool that allows to record the test | ||
and generate the code for it. This improves the development speed as most code can be generated. | ||
|
||
### Common issues | ||
|
||
`Cannot run macOS (Mach-O) executable in Docker: Exec format error` | ||
|
||
This error means that you are trying to run MacOS binary on Linux. You need to build | ||
Linux compatible binaries to run them in Docker. You can rebuild them using `make build-binaries` | ||
or just remove existing binaries in `../build` as they will be rebuilt automatically. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM ubuntu:22.04 | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y \ | ||
curl \ | ||
ca-certificates \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
ARG BUILDARCH | ||
RUN curl -JLO "https://dl.filippo.io/mkcert/latest?for=linux/${BUILDARCH}" && \ | ||
chmod +x mkcert-v*-linux-${BUILDARCH} && \ | ||
cp mkcert-v*-linux-${BUILDARCH} /usr/local/bin/mkcert | ||
|
||
RUN mkdir -p /etc/teleport/certs && \ | ||
mkcert -install && \ | ||
mkcert -cert-file /etc/teleport/certs/tls.crt -key-file /etc/teleport/certs/tls.key localhost \ | ||
"*.localhost" "teleport" && \ | ||
cp $(mkcert -CAROOT)/rootCA.pem /etc/teleport/certs/ | ||
|
||
CMD ["/usr/local/bin/teleport", "start", "-c", "/etc/teleport/teleport.yaml", "--bootstrap", "/etc/teleport/state.yaml"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Copyright 2023 Gravitational, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
set -e | ||
|
||
# Add generated certificates to system CA. | ||
cp /etc/teleport/certs/rootCA.pem /usr/local/share/ca-certificates/teleport.crt | ||
update-ca-certificates | ||
|
||
yarn install | ||
|
||
# Wait for the Teleport to be up and initialized. | ||
sleep 5 | ||
|
||
npx playwright install chromium | ||
npx playwright test --workers 1 --repeat-each 1 --timeout 15000 --project=chromium |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
kind: user | ||
metadata: | ||
id: 1689831509413322785 | ||
name: bob | ||
spec: | ||
created_by: | ||
time: "2023-07-20T05:38:29.4127778Z" | ||
user: | ||
name: a0fc0c8b-adaa-4a58-b604-10388415fa0b.teleport-e2e | ||
expires: "0001-01-01T00:00:00Z" | ||
local_auth: | ||
password_hash: JDJhJDEwJHcwSzJwd0svY0Y4Qkcwa0taN1gxcWUxdVU3dzNtd1oyUzQ2UE82U2xhaVZqaVRrYk5HUXA2 # password is "secret" | ||
roles: | ||
- access | ||
- editor | ||
status: | ||
is_locked: false | ||
lock_expires: "0001-01-01T00:00:00Z" | ||
locked_time: "0001-01-01T00:00:00Z" | ||
recovery_attempt_lock_expires: "0001-01-01T00:00:00Z" | ||
traits: | ||
aws_role_arns: null | ||
azure_identities: null | ||
db_names: null | ||
db_roles: null | ||
db_users: null | ||
gcp_service_accounts: null | ||
kubernetes_groups: null | ||
kubernetes_users: null | ||
logins: | ||
- root | ||
windows_logins: null | ||
version: v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
version: v3 | ||
teleport: | ||
nodename: teleport-e2e | ||
auth_token: foo | ||
data_dir: /var/lib/teleport | ||
log: | ||
output: stderr | ||
severity: TRACE | ||
format: | ||
output: text | ||
auth_server: teleport:3025 | ||
|
||
auth_service: | ||
enabled: "yes" | ||
listen_addr: 0.0.0.0:3025 | ||
proxy_listener_mode: multiplex | ||
|
||
tokens: | ||
- "node,auth,proxy,db,trusted_cluster:foo" | ||
authentication: | ||
type: local | ||
second_factor: off | ||
|
||
ssh_service: | ||
enabled: "yes" | ||
public_addr: teleport:3022 | ||
|
||
labels: | ||
env: example | ||
|
||
proxy_service: | ||
enabled: "yes" | ||
public_addr: teleport:3080 | ||
acme: {} | ||
|
||
web_listen_addr: 0.0.0.0:3080 | ||
|
||
https_keypairs: | ||
- key_file: /etc/teleport/certs/tls.key | ||
cert_file: /etc/teleport/certs/tls.crt | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
version: '3.8' | ||
|
||
services: | ||
teleport: | ||
image: teleport-e2e:latest | ||
hostname: teleport | ||
build: | ||
context: .. | ||
dockerfile: ./e2e/config/Dockerfile | ||
volumes: | ||
- teleport-config:/etc/teleport | ||
- ./config/teleport.yaml:/etc/teleport/teleport.yaml | ||
- ./config/state.yaml:/etc/teleport/state.yaml | ||
- teleport-data:/var/lib/teleport | ||
- ../build/teleport:/usr/local/bin/teleport | ||
ports: | ||
- "3080:3080" | ||
|
||
e2e: | ||
image: mcr.microsoft.com/playwright:v1.36.0-jammy | ||
entrypoint: | ||
- bash | ||
- -c | ||
volumes: | ||
- .:/e2e | ||
- teleport-config:/etc/teleport | ||
- teleport-data:/var/lib/teleport | ||
environment: | ||
- CI=1 | ||
working_dir: /e2e | ||
command: | ||
- /e2e/config/run-tests.sh | ||
|
||
volumes: | ||
teleport-config: {} | ||
teleport-data: {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "teleport-e2e", | ||
"version": "1.0.0", | ||
"description": "Teleport E2E tests", | ||
"repository": "https://github.com/gravitational/teleport", | ||
"license": "Apache-2.0", | ||
"private": true, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@playwright/test": "^1.35.1", | ||
"typescript": "^5.1.6" | ||
}, | ||
"scripts": { | ||
"codegen": "playwright codegen https://localhost:3080", | ||
"test": "playwright test" | ||
} | ||
} |
Oops, something went wrong.