From 0315016d9589a1a75f45cf867ac33d1ac6def625 Mon Sep 17 00:00:00 2001 From: Rohit T P Date: Thu, 2 May 2024 22:59:23 +0530 Subject: [PATCH] chore: created GitHub actions to run tests --- .github/workflows/bats-test.yml | 55 +++++++++++++++++++ .../setup-script/tests/configure/monitor.bats | 8 ++- .../setup-script/tests/configure/restart.bats | 8 ++- .../setup-script/tests/configure/scale.bats | 8 ++- .../setup-script/tests/configure/start.bats | 8 ++- .../setup-script/tests/configure/stop.bats | 8 ++- .../setup-script/tests/configure/upgrade.bats | 8 ++- .../setup-script/tests/install/default.bats | 12 ++-- .../setup-script/tests/install/ip.bats | 8 ++- .../setup-script/tests/install/redis.bats | 8 ++- .../setup-script/tests/install/scale.bats | 8 ++- .../setup-script/tests/install/ssl.bats | 8 ++- .../tests/install/watchtower.bats | 8 ++- 13 files changed, 129 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/bats-test.yml diff --git a/.github/workflows/bats-test.yml b/.github/workflows/bats-test.yml new file mode 100644 index 0000000000..49e26b6e6b --- /dev/null +++ b/.github/workflows/bats-test.yml @@ -0,0 +1,55 @@ +name: Run BATS Tests + +on: + push: + paths: + - 'docker-compose/setup-script/noco.sh' + workflow_dispatch: + +jobs: + prepare: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install jq + run: | + sudo apt-get update + sudo apt-get install -y jq + + - name: Prepare matrix for test files + id: set-matrix + run: | + BATS_FILES=$(find docker-compose/setup-script/tests -name '*.bats') + MATRIX_JSON=$(echo $BATS_FILES | jq -Rsc 'split("\n") | map(select(. != ""))') + echo "matrix=$MATRIX_JSON" >> $GITHUB_ENV + + test: + needs: prepare + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + test: ${{fromJson(env.matrix)}} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install BATS + run: | + sudo apt-get update + sudo apt-get install -y bats expect + + - name: Get working directory + run: | + WORKING_DIR="$(pwd)/docker-compose/setup-script/tests" + echo "WORKING_DIR=$WORKING_DIR" >> $GITHUB_ENV + + - name: Run BATS test + run: bats ${{ matrix.test }} + env: + WORKING_DIR: ${{ env.WORKING_DIR }} + SKIP_TARE_DOWN: true diff --git a/docker-compose/setup-script/tests/configure/monitor.bats b/docker-compose/setup-script/tests/configure/monitor.bats index 50efa5e45a..ae20a2d85f 100755 --- a/docker-compose/setup-script/tests/configure/monitor.bats +++ b/docker-compose/setup-script/tests/configure/monitor.bats @@ -11,8 +11,12 @@ setup() { } teardown() { - cd "${WORKING_DIR}/configure" || exit 1 - ./setup.sh + if [ -n "$SKIP_TEARDOWN" ]; then + return + fi + + cd "${WORKING_DIR}/install" || exit 1 + ./setup.sh } @test "Properly runs monitor script" { diff --git a/docker-compose/setup-script/tests/configure/restart.bats b/docker-compose/setup-script/tests/configure/restart.bats index 4eaa3b1eb5..2f92868882 100755 --- a/docker-compose/setup-script/tests/configure/restart.bats +++ b/docker-compose/setup-script/tests/configure/restart.bats @@ -11,8 +11,12 @@ setup() { } teardown() { - cd "${WORKING_DIR}/configure" || exit 1 - ./setup.sh + if [ -n "$SKIP_TEARDOWN" ]; then + return + fi + + cd "${WORKING_DIR}/install" || exit 1 + ./setup.sh } @test "Check all containers are restarted" { diff --git a/docker-compose/setup-script/tests/configure/scale.bats b/docker-compose/setup-script/tests/configure/scale.bats index ccb8832c93..b2bbadd45d 100755 --- a/docker-compose/setup-script/tests/configure/scale.bats +++ b/docker-compose/setup-script/tests/configure/scale.bats @@ -11,8 +11,12 @@ setup() { } teardown() { - cd "${WORKING_DIR}/configure" || exit 1 - ./setup.sh + if [ -n "$SKIP_TEARDOWN" ]; then + return + fi + + cd "${WORKING_DIR}/install" || exit 1 + ./setup.sh } @test "Check NocoDB is scaled to 3 instances" { diff --git a/docker-compose/setup-script/tests/configure/start.bats b/docker-compose/setup-script/tests/configure/start.bats index 18be31a96f..b438e516eb 100755 --- a/docker-compose/setup-script/tests/configure/start.bats +++ b/docker-compose/setup-script/tests/configure/start.bats @@ -11,8 +11,12 @@ setup() { } teardown() { - cd "${WORKING_DIR}/configure" || exit 1 - ./setup.sh + if [ -n "$SKIP_TEARDOWN" ]; then + return + fi + + cd "${WORKING_DIR}/install" || exit 1 + ./setup.sh } @test "Check all containers are up" { diff --git a/docker-compose/setup-script/tests/configure/stop.bats b/docker-compose/setup-script/tests/configure/stop.bats index e9b39c3b21..47f202dfa4 100755 --- a/docker-compose/setup-script/tests/configure/stop.bats +++ b/docker-compose/setup-script/tests/configure/stop.bats @@ -11,8 +11,12 @@ setup() { } teardown() { - cd "${WORKING_DIR}/configure" || exit 1 - ./setup.sh + if [ -n "$SKIP_TEARDOWN" ]; then + return + fi + + cd "${WORKING_DIR}/install" || exit 1 + ./setup.sh } @test "Check all containers are down" { diff --git a/docker-compose/setup-script/tests/configure/upgrade.bats b/docker-compose/setup-script/tests/configure/upgrade.bats index 4e791ad12e..b0e9f6275a 100755 --- a/docker-compose/setup-script/tests/configure/upgrade.bats +++ b/docker-compose/setup-script/tests/configure/upgrade.bats @@ -11,8 +11,12 @@ setup() { } teardown() { - cd "${WORKING_DIR}/configure" || exit 1 - ./setup.sh + if [ -n "$SKIP_TEARDOWN" ]; then + return + fi + + cd "${WORKING_DIR}/install" || exit 1 + ./setup.sh } @test "Check all containers are upgraded" { diff --git a/docker-compose/setup-script/tests/install/default.bats b/docker-compose/setup-script/tests/install/default.bats index 2a4f887563..ef6e758d23 100755 --- a/docker-compose/setup-script/tests/install/default.bats +++ b/docker-compose/setup-script/tests/install/default.bats @@ -6,13 +6,17 @@ export NOCO_HOME setup() { - cd "${WORKING_DIR}/install" || exit 1 - ./setup.sh + cd "${WORKING_DIR}/install" || exit 1 + ./setup.sh } teardown() { - cd "${WORKING_DIR}/install" || exit 1 - ./setup.sh + if [ -n "$SKIP_TEARDOWN" ]; then + return + fi + + cd "${WORKING_DIR}/install" || exit 1 + ./setup.sh } @test "Check installation with all default options" { diff --git a/docker-compose/setup-script/tests/install/ip.bats b/docker-compose/setup-script/tests/install/ip.bats index 1ab698b9be..e3fbc1b547 100755 --- a/docker-compose/setup-script/tests/install/ip.bats +++ b/docker-compose/setup-script/tests/install/ip.bats @@ -11,8 +11,12 @@ setup() { } teardown() { - cd "${WORKING_DIR}/install" || exit 1 - ./setup.sh + if [ -n "$SKIP_TEARDOWN" ]; then + return + fi + + cd "${WORKING_DIR}/install" || exit 1 + ./setup.sh } @test "Check installation with custom ip" { diff --git a/docker-compose/setup-script/tests/install/redis.bats b/docker-compose/setup-script/tests/install/redis.bats index 4abc1d01c5..fba5db9add 100755 --- a/docker-compose/setup-script/tests/install/redis.bats +++ b/docker-compose/setup-script/tests/install/redis.bats @@ -11,8 +11,12 @@ setup() { } teardown() { - cd "${WORKING_DIR}/install" || exit 1 - ./setup.sh + if [ -n "$SKIP_TEARDOWN" ]; then + return + fi + + cd "${WORKING_DIR}/install" || exit 1 + ./setup.sh } @test "Check Redis is enabled when specified" { diff --git a/docker-compose/setup-script/tests/install/scale.bats b/docker-compose/setup-script/tests/install/scale.bats index 2c0523fe94..73d3e325e5 100755 --- a/docker-compose/setup-script/tests/install/scale.bats +++ b/docker-compose/setup-script/tests/install/scale.bats @@ -11,8 +11,12 @@ setup() { } teardown() { - cd "${WORKING_DIR}/install" || exit 1 - ./setup.sh + if [ -n "$SKIP_TEARDOWN" ]; then + return + fi + + cd "${WORKING_DIR}/install" || exit 1 + ./setup.sh } @test "Check if two instances of NoCoDB can be run" { diff --git a/docker-compose/setup-script/tests/install/ssl.bats b/docker-compose/setup-script/tests/install/ssl.bats index 1d44344072..705120b7af 100644 --- a/docker-compose/setup-script/tests/install/ssl.bats +++ b/docker-compose/setup-script/tests/install/ssl.bats @@ -10,8 +10,12 @@ setup() { } teardown() { - cd "${WORKING_DIR}/install" || exit 1 - ./setup.sh + if [ -n "$SKIP_TEARDOWN" ]; then + return + fi + + cd "${WORKING_DIR}/install" || exit 1 + ./setup.sh } @test "Should create SSL certificates" { diff --git a/docker-compose/setup-script/tests/install/watchtower.bats b/docker-compose/setup-script/tests/install/watchtower.bats index 68f9cd651c..32c988809c 100755 --- a/docker-compose/setup-script/tests/install/watchtower.bats +++ b/docker-compose/setup-script/tests/install/watchtower.bats @@ -9,8 +9,12 @@ setup() { } teardown() { - cd "${WORKING_DIR}/install" || exit 1 - ./setup.sh + if [ -n "$SKIP_TEARDOWN" ]; then + return + fi + + cd "${WORKING_DIR}/install" || exit 1 + ./setup.sh } @test "Check WatchTower is enabled when specified" {