Skip to content

Commit

Permalink
test(repeater): add tests for repeater command (#439)
Browse files Browse the repository at this point in the history
closes #438
  • Loading branch information
lsndr authored and derevnjuk committed Aug 30, 2023
1 parent 1577ba8 commit 3cc3d9d
Show file tree
Hide file tree
Showing 11 changed files with 552 additions and 147 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/auto-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
strategy:
fail-fast: false
matrix:
target: [ 'lint', 'format', 'test:unit', 'test:e2e' ]
target: [ 'lint', 'format', 'test:unit' ]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -37,9 +37,5 @@ jobs:
- name: Install deps
uses: ./.github/workflows/composite/npm

- name: Compute arguments
if: matrix.target == 'test:e2e'
run: echo "JEST_ARGUMENTS=--testTimeout 4000" >> $GITHUB_ENV

- name: Execute ${{ matrix.target }} npm script
run: npm run ${{ matrix.target }} -- $JEST_ARGUMENTS
7 changes: 6 additions & 1 deletion .github/workflows/composite/npm/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ inputs:
description: 'Node.JS version'
required: false
default: "18"
cache:
description: 'Cache'
required: false
default: "npm"


runs:
using: 'composite'
Expand All @@ -21,7 +26,7 @@ runs:
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.version }}
cache: 'npm'
cache: ${{ inputs.cache }}
registry-url: ${{ inputs.registry }}
scope: ${{ inputs.scope }}

Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/composite/todoapp/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'TODO App'
description: 'Runs TODO App'

outputs:
port:
description: "Target port"
value: "9000"
cmd:
description: "Command to run the target"
value: ${{ steps.download.outputs.cmd }}

runs:
using: 'composite'
steps:
- name: Download Executable
id: download
shell: bash
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
EXECUTABLE=todoapp-linux-x64
CMD=./$EXECUTABLE
elif [ "$RUNNER_OS" == "Windows" ]; then
EXECUTABLE=todoapp-windows-x64.exe
CMD=.\\$EXECUTABLE
elif [ "$RUNNER_OS" == "macOS" ]; then
EXECUTABLE=todoapp-darwin-x64
CMD=./$EXECUTABLE
fi
wget -qO- https://github.com/NeuraLegion/go-todoapp-demo/releases/latest/download/$EXECUTABLE > ./$EXECUTABLE
chmod +x ./$EXECUTABLE
echo "cmd=$CMD" >> "$GITHUB_OUTPUT"
194 changes: 194 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
name: E2E Tests

run-name: E2E Tests (${{ inputs.version }})

on:
workflow_dispatch:
inputs:
version:
description: "Bright CLI version (e.g.: v10.3.1)"
required: true
default: v11.0.0-next.21
test-docker:
type: boolean
description: "Test Docker"
default: true
test-executables:
type: boolean
description: "Test Executables"
default: true
test-npm:
type: boolean
description: "Test NPM"
default: true
environment:
required: true
type: choice
default: staging
description: Environment
options:
- staging
- development
test_timeout:
description: "Test timeout in seconds"
default: 3600
required: true

jobs:
executables:
if: ${{ inputs.test-executables }}
runs-on: ${{ matrix.os }}
container: ${{ matrix.container }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
container: ubuntu:18.04
executable: bright-cli-linux-x64
node: 16
- os: ubuntu-latest
container: ubuntu:16.04
executable: bright-cli-linux-x64
node: 14
- os: ubuntu-latest
container: fedora:latest
executable: bright-cli-linux-x64
node: 18
- os: ubuntu-latest
executable: bright-cli-linux-x64
node: 18
- os: macos-latest
executable: bright-cli-macos-x64
node: 18
- os: windows-latest
executable: bright-cli-win-x64.exe
node: 18
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Install Dependencies
uses: ./.github/workflows/composite/npm
with:
version: ${{ matrix.node }}
# https://github.com/actions/setup-node/issues/286#issuecomment-878865957
cache: ''

- name: Download Executable
shell: bash
run: |
wget -qO- https://github.com/NeuraLegion/bright-cli/releases/download/${{ inputs.version }}/${{ matrix.executable }} > ./${{ matrix.executable }}
chmod +x ./${{ matrix.executable }}
- name: Download Target
id: target
uses: ./.github/workflows/composite/todoapp

- name: Run Tests
run: npm run test:e2e
env:
E2E_CLI_VERSION: ${{ inputs.version }}
E2E_CLI_CMD: ${{ runner.os != 'windows' && format('./{0}', matrix.executable) || format('.\{0}', matrix.executable) }}
E2E_RUN_ID: ${{ format('{0}-{1}-{2}-{3}', github.run_number, github.run_attempt, github.job, strategy.job-index) }}
E2E_CLUSTER: ${{ secrets[format('E2E_{0}_HOST', inputs.environment )] }}
E2E_CLUSTER_API_KEY: ${{ secrets[format('E2E_{0}_API_KEY', inputs.environment )] }}
E2E_REPEATER_TARGET_URL: ${{ format('http://localhost:{0}', steps.target.outputs.port) }}
E2E_REPEATER_TARGET_CMD: ${{ steps.target.outputs.cmd }}
E2E_test_timeout: ${{ inputs.test_timeout }}
docker:
if: ${{ inputs.test-docker }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Windows can't run linux docker images: https://github.com/actions/runner-images/issues/1143
os: [ubuntu-latest, macos-latest]
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Install Docker (MacOS)
if: ${{ startsWith(matrix.os, 'macos') }}
uses: docker-practice/actions-setup-docker@master
timeout-minutes: 12

- name: Install Dependencies
uses: ./.github/workflows/composite/npm
with:
# https://github.com/actions/setup-node/issues/286#issuecomment-878865957
cache: ''

- name: Pull Image
run: docker pull brightsec/cli:${{ inputs.version }}

- name: Download Target
id: target
uses: ./.github/workflows/composite/todoapp

- name: Run Tests
run: npm run test:e2e
env:
E2E_CLI_VERSION: ${{ inputs.version }}
E2E_CLI_CMD: docker run --add-host host.docker.internal:host-gateway --network host brightsec/cli:${{ inputs.version }}
E2E_RUN_ID: ${{ format('{0}-{1}-{2}-{3}', github.run_number, github.run_attempt, github.job, strategy.job-index) }}
E2E_CLUSTER: ${{ secrets[format('E2E_{0}_HOST', inputs.environment )] }}
E2E_CLUSTER_API_KEY: ${{ secrets[format('E2E_{0}_API_KEY', inputs.environment )] }}
E2E_REPEATER_TARGET_URL: ${{ format('http://host.docker.internal:{0}', steps.target.outputs.port) }}
E2E_REPEATER_TARGET_CMD: ${{ steps.target.outputs.cmd }}
E2E_test_timeout: ${{ inputs.test_timeout }}
npm:
if: ${{ inputs.test-npm }}
runs-on: ${{ matrix.os }}
container: ${{ matrix.container }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest]
node: [14, 16, 18]
include:
- os: ubuntu-latest
node: 14
- os: ubuntu-latest
node: 16
- os: ubuntu-latest
node: 18
- os: ubuntu-latest
container: ubuntu:16.04
node: 14
- os: ubuntu-latest
container: fedora:latest
node: 18
exclude:
# TODO: Troubleshoot
- os: windows-latest
node: 14
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Install Dependencies
uses: ./.github/workflows/composite/npm
with:
version: ${{ matrix.node }}
# https://github.com/actions/setup-node/issues/286#issuecomment-878865957
cache: ''

- name: Install CLI
run: npm i -g @brightsec/cli@${{ inputs.version }}

- name: Download Target
id: target
uses: ./.github/workflows/composite/todoapp

- name: Run Tests
run: npm run test:e2e
env:
E2E_CLI_VERSION: ${{ inputs.version }}
E2E_CLI_CMD: bright-cli
E2E_RUN_ID: ${{ format('{0}-{1}-{2}-{3}', github.run_number, github.run_attempt, github.job, strategy.job-index) }}
E2E_CLUSTER: ${{ secrets[format('E2E_{0}_HOST', inputs.environment )] }}
E2E_CLUSTER_API_KEY: ${{ secrets[format('E2E_{0}_API_KEY', inputs.environment )] }}
E2E_REPEATER_TARGET_URL: ${{ format('http://localhost:{0}', steps.target.outputs.port) }}
E2E_REPEATER_TARGET_CMD: ${{ steps.target.outputs.cmd }}
E2E_test_timeout: ${{ inputs.test_timeout }}
Loading

0 comments on commit 3cc3d9d

Please sign in to comment.