Skip to content

Commit

Permalink
feat(ci): make e2e test workflow reusable (#365)
Browse files Browse the repository at this point in the history
Related to #347
  • Loading branch information
jakedoublev authored Sep 6, 2024
1 parent 8e1390f commit d94408c
Show file tree
Hide file tree
Showing 16 changed files with 149 additions and 65 deletions.
69 changes: 7 additions & 62 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
args: --timeout=10m
unit:
name: unit tests
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
Expand All @@ -48,67 +48,12 @@ jobs:
cache: false
- name: Unit Tests with the Go CLI
run: go test ./... -short -race -cover
end-to-end:

e2e:
name: e2e tests
runs-on: ubuntu-22.04
env:
BATS_LIB_PATH: /usr/lib
TEST_TERMINAL_WIDTH: 200
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- name: Check out platform
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
with:
repository: opentdf/platform
path: platform
- name: Set up go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7
- uses: opentdf/otdfctl/e2e@feat/e2e-ci
with:
go-version-file: 'platform/service/go.mod'
check-latest: false
cache-dependency-path: |
platform/service/go.sum
platform/protocol/go/go.sum
platform/sdk/go.sum
- run: |
.github/scripts/init-temp-keys.sh
cp opentdf-dev.yaml opentdf.yaml
working-directory: platform
- name: Added Trusted Certs
run: |
sudo chmod -R 777 ./keys
sudo apt-get install -y ca-certificates
sudo cp ./keys/localhost.crt /usr/local/share/ca-certificates
sudo update-ca-certificates
working-directory: platform
- run: docker compose up -d --wait --wait-timeout 240
working-directory: platform
- run: go run ./service provision keycloak
working-directory: platform
- run: go run ./service provision fixtures
working-directory: platform
- uses: JarvusInnovations/background-action@2428e7b970a846423095c79d43f759abf979a635
name: start server in background
with:
run: >
go build -o opentdf -v service/main.go
&& .github/scripts/watch.sh opentdf.yaml ./opentdf start
wait-on: |
tcp:localhost:8080
log-output-if: true
wait-for: 90s
working-directory: platform

- name: build the CLI
run: go build .
- name: build the CLI in test mode
run: make build-test
- name: set up the config
run: cp otdfctl-example.yaml otdfctl.yaml
- name: Setup Bats and bats libs
uses: bats-core/bats-action@2.0.0
- run: tests/encrypt-decrypt.bats
- run: tests/kas-grants.bats
- run: tests/profile.bats
- run: tests/kas-registry.bats
- run: tests/namespaces.bats
platform-ref: 'main'
otdfctl-ref: ${{ github.event.pull_request.head.sha }}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ build-test:

.PHONY: test-bats
test-bats: build-test
./tests/resize_terminal.sh && bats ./tests
./e2e/resize_terminal.sh && bats ./tests

# Target for cleaning up the target directory
.PHONY: clean
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ prerequisites are met:
- The platform is running and provisioned with basic keycloak clients/users
- See the [platform README](https://github.com/opentdf/platform) for instructions

To run the tests you can either run `make test-bats` or execute specific test suites with `bats tests/<test>.bats`.
To run the tests you can either run `make test-bats` or execute specific test suites with `bats e2e/<test>.bats`.

#### Terminal Size

Expand All @@ -85,5 +85,5 @@ Terminal size when testing:

1. set to standard defaults if running `make test-bats`
2. can be set manually by mouse in terminal where tests are triggered
3. can be set by argument `./tests/resize_terminal.sh < rows height > < columns width >`
3. can be set by argument `./e2e/resize_terminal.sh < rows height > < columns width >`
4. can be set by environment variable, i.e. `export TEST_TERMINAL_WIDTH="200"` (200 is columns width)
135 changes: 135 additions & 0 deletions e2e/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: 'end-to-end'
description: 'Run end-to-end tests for the otdfctl CLI'
inputs:
# Known issue: boolean defaults are treated as strings [https://stackoverflow.com/questions/76292948/github-action-boolean-input-with-default-value]
platform-is-running:
required: false
default: 'false'
description: 'If false, spin up the platform and its resources'
platform-ref:
required: false
description: 'The ref to check out for the platform'
default: 'main'
otdfctl-ref:
required: false
description: 'The ref to check out for the otdfctl CLI'
default: 'main'

runs:
using: 'composite'
steps:
- name: Report on the run context
shell: bash
run: |
if [ ${{ inputs.platform-is-running }} == 'true' ]; then
echo "Platform is already running"
else
if [ "${{ inputs.platform-ref }}" == "" ]; then
echo "Platform will be spun up from 'main'"
else
echo "Platform will be checked out at '${{ inputs.platform-ref }}' and spun up"
fi
fi
if [ ${{ inputs.otdfctl-ref == github.event.pull_request.head.sha }} ]; then
echo "otdfctl will be tested from the PR branch"
else
echo "otdfctl will be tested from 'main' or '${{ inputs.otdfctl-ref }}'"
fi
- name: Check out otdfctl CLI
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
with:
ref: ${{ inputs.otdfctl-ref }}
path: otdfctl
# Spin up the platform IFF it's not already running in the current workflow context
- name: Check out platform
if: ${{ inputs.platform-is-running == 'false' }}
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
with:
repository: opentdf/platform
path: platform
ref: ${{ inputs.platform-ref }}
- name: Set up go (platform's go version)
id: setup-go
if: ${{ inputs.platform-is-running == 'false' }}
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7
with:
go-version-file: 'platform/service/go.mod'
check-latest: false
cache-dependency-path: |
platform/service/go.sum
platform/protocol/go/go.sum
platform/sdk/go.sum
- name: Provide the platform with keys
shell: bash
if: ${{ inputs.platform-is-running == 'false' }}
run: |
.github/scripts/init-temp-keys.sh
cp opentdf-dev.yaml opentdf.yaml
working-directory: platform
- name: Trust the generated certs
if: ${{ inputs.platform-is-running == 'false' }}
shell: bash
run: |
sudo chmod -R 777 ./keys
sudo apt-get install -y ca-certificates
sudo cp ./keys/localhost.crt /usr/local/share/ca-certificates
sudo update-ca-certificates
working-directory: platform
- name: Spin up platform's containerized resources
if: ${{ inputs.platform-is-running == 'false' }}
shell: bash
run: docker compose up -d --wait --wait-timeout 240
working-directory: platform
- name: Provision realms/clients/users into idP
if: ${{ inputs.platform-is-running == 'false' }}
shell: bash
run: go run ./service provision keycloak
working-directory: platform
- name: Provision test fixture policy
if: ${{ inputs.platform-is-running == 'false' }}
shell: bash
run: go run ./service provision fixtures
working-directory: platform
- name: Start platform server in background
if: ${{ inputs.platform-is-running == 'false' }}
uses: JarvusInnovations/background-action@2428e7b970a846423095c79d43f759abf979a635
with:
run: >
go build -o opentdf -v service/main.go
&& .github/scripts/watch.sh opentdf.yaml ./opentdf start
wait-on: |
tcp:localhost:8080
log-output-if: true
wait-for: 90s
working-directory: platform

# Build the CLI and run tests
- name: Set up go (CLI version, if needed)
if: steps.setup-go.outcome != 'success'
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7
with:
go-version-file: go.mod
- name: Build the CLI
shell: bash
run: go build .
working-directory: otdfctl
- name: Build the CLI in test mode
shell: bash
run: make build-test
working-directory: otdfctl
- name: Set up the CLI config
shell: bash
run: cp otdfctl-example.yaml otdfctl.yaml
working-directory: otdfctl
- name: Setup Bats and bats libs
uses: bats-core/bats-action@2.0.0
- name: Run Bats tests
shell: bash
working-directory: otdfctl
run: bats e2e
env:
# Define 'bats' install location in ubuntu
BATS_LIB_PATH: /usr/lib
# Terminal width for testing printed output
TEST_TERMINAL_WIDTH: 200
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions pkg/handlers/nano-tdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ func (h Handler) DecryptNanoTDF(toDecrypt []byte) (*bytes.Buffer, error) {
}
return &outBuf, nil
}

func trigger() {
return
}

0 comments on commit d94408c

Please sign in to comment.