From 2365164b9285119d6d40616525dee0fcb5314d08 Mon Sep 17 00:00:00 2001 From: Rohit T P Date: Thu, 2 May 2024 11:28:10 +0000 Subject: [PATCH 01/16] tests: created tests for redis --- .../setup-script/tests/expects/redis.sh | 31 +++++++++++++++++++ docker-compose/setup-script/tests/redis.bats | 28 +++++++++++++++++ docker-compose/setup-script/tests/setup.sh | 12 +++++++ 3 files changed, 71 insertions(+) create mode 100755 docker-compose/setup-script/tests/expects/redis.sh create mode 100644 docker-compose/setup-script/tests/redis.bats create mode 100755 docker-compose/setup-script/tests/setup.sh diff --git a/docker-compose/setup-script/tests/expects/redis.sh b/docker-compose/setup-script/tests/expects/redis.sh new file mode 100755 index 0000000000..652f990068 --- /dev/null +++ b/docker-compose/setup-script/tests/expects/redis.sh @@ -0,0 +1,31 @@ +#!/usr/bin/expect -f + +# Configure timeout for each expect command +set timeout 10 + +# Start your main script +spawn bash ../noco.sh + +# Respond to script prompts +expect "Enter the IP address or domain name for the NocoDB instance (default: localhost):" +send "\r" + +expect "Show Advanced Options*" +send "Y\r" + +expect "Choose Community or Enterprise Edition*" +send "\r" + +expect "Do you want to enabled Redis for caching*" +send "Y\r" + +expect "Do you want to enabled Watchtower for automatic updates*" +send "\r" + +expect "How many instances of NocoDB do you want to run*" +send "\r" + +expect "Do you want to start the management menu*" +send "N\r" + +expect eof diff --git a/docker-compose/setup-script/tests/redis.bats b/docker-compose/setup-script/tests/redis.bats new file mode 100644 index 0000000000..6984d4e96a --- /dev/null +++ b/docker-compose/setup-script/tests/redis.bats @@ -0,0 +1,28 @@ +#!/usr/bin/env bats + +NOCO_HOME="${HOME}/.nocodb" +export NOCO_HOME + +WORKING_DIR="$(pwd)" + +setup() { + cd "${WORKING_DIR}" + ./setup.sh +} + +teardown() { + cd "${WORKING_DIR}" + ./setup.sh +} + +@test "Check Redis is enabled when specified" { + ./expects/redis.sh + + cd "${NOCO_HOME}" + + # Check Docker Compose file to verify Redis configuration + grep -q 'redis' docker-compose.yml + + # Verify Redis container is running + docker compose ps | grep -q 'redis' +} diff --git a/docker-compose/setup-script/tests/setup.sh b/docker-compose/setup-script/tests/setup.sh new file mode 100755 index 0000000000..e3a24ce010 --- /dev/null +++ b/docker-compose/setup-script/tests/setup.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if [ -z "$NOCO_HOME" ]; then + NOCO_HOME="${HOME}/.nocodb" +fi + +if [ -d "$NOCO_HOME" ]; then + cd $NOCO_HOME + docker compose down +fi + +rm -rf $NOCO_HOME From b11c92902ea4f3449bfda1c0164469197cf49a19 Mon Sep 17 00:00:00 2001 From: Rohit T P Date: Thu, 2 May 2024 11:38:59 +0000 Subject: [PATCH 02/16] lint: fix lint errors --- docker-compose/setup-script/noco.sh | 31 ++++++++++---------- docker-compose/setup-script/tests/redis.bats | 4 +-- docker-compose/setup-script/tests/setup.sh | 4 +-- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/docker-compose/setup-script/noco.sh b/docker-compose/setup-script/noco.sh index 9cbf69ebfe..9dedca16eb 100755 --- a/docker-compose/setup-script/noco.sh +++ b/docker-compose/setup-script/noco.sh @@ -140,7 +140,7 @@ show_menu() { clear check_if_docker_is_running echo "" - echo $MSG + echo "$MSG" echo -e "\t\t${BOLD}Service Management Menu${NC}" echo -e " ${GREEN}1. Start Service" echo -e " ${ORANGE}2. Stop Service" @@ -167,19 +167,19 @@ stop_service() { show_logs_sub_menu() { clear echo "Select a replica for $1:" - for i in $(seq 1 $2); do + for i in $(seq 1 "$2"); do echo "$i. $1 replica $i" done echo "A. All" echo "0. Back to Logs Menu" echo "Enter replica number: " - read replica_choice + read -r replica_choice if [[ "$replica_choice" =~ ^[0-9]+$ ]] && [ "$replica_choice" -gt 0 ] && [ "$replica_choice" -le "$2" ]; then container_id=$($DOCKER_COMMAND compose ps | grep "$1-$replica_choice" | cut -d " " -f 1) $DOCKER_COMMAND logs -f "$container_id" elif [ "$replica_choice" == "A" ] || [ "$replica_choice" == "a" ]; then - $DOCKER_COMMAND compose logs -f $1 + $DOCKER_COMMAND compose logs -f "$1" elif [ "$replica_choice" == "0" ]; then show_logs else @@ -205,7 +205,7 @@ show_logs() { # For each service, count the number of running instances for service in "${services[@]}"; do # Count the number of lines that have the service name, which corresponds to the number of replicas - replicas=$($DOCKER_COMMAND compose ps $service | grep "$service" | wc -l) + replicas=$($DOCKER_COMMAND compose ps "$service" | grep -c "$service") service_replicas["$count"]=$replicas count=$((count + 1)) done @@ -220,7 +220,7 @@ show_logs() { echo "A. All" echo "0. Back to main menu" echo "Enter your choice: " - read log_choice + read -r log_choice echo if [[ "$log_choice" =~ ^[0-9]+$ ]] && [ "$log_choice" -gt 0 ] && [ "$log_choice" -lt "$count" ]; then @@ -268,14 +268,14 @@ scale_service() { current_scale=$($DOCKER_COMMAND compose ps -q nocodb | wc -l) echo -e "\nCurrent number of instances: $current_scale" echo "How many instances of NocoDB do you want to run (Maximum: ${num_cores}) ? (default: 1): " - scale_num=$(read_number_range 1 $num_cores) + scale_num=$(read_number_range 1 "$num_cores") - if [ $scale_num -eq $current_scale ]; then + if [ "$scale_num" -eq "$current_scale" ]; then echo "Number of instances is already set to $scale_num. Returning to main menu." return fi - $DOCKER_COMMAND compose up -d --scale nocodb=$scale_num + $DOCKER_COMMAND compose up -d --scale nocodb="$scale_num" } # Function for basic monitoring @@ -292,7 +292,7 @@ management_menu() { show_menu echo "Enter your choice: " - read choice + read -r choice case $choice in 1) start_service && MSG="NocoDB Started" ;; 2) stop_service && MSG="NocoDB Stopped" ;; @@ -344,7 +344,8 @@ if [ "$NOCO_FOUND" = true ]; then read -r REINSTALL if [ -f "$NOCO_HOME/.COMPOSE_PROJECT_NAME" ]; then - export COMPOSE_PROJECT_NAME=$(cat "$NOCO_HOME/.COMPOSE_PROJECT_NAME") + COMPOSE_PROJECT_NAME=$(cat "$NOCO_HOME/.COMPOSE_PROJECT_NAME") + export COMPOSE_PROJECT_NAME fi if [ "$REINSTALL" != "Y" ] && [ "$REINSTALL" != "y" ]; then @@ -355,7 +356,7 @@ if [ "$NOCO_FOUND" = true ]; then $DOCKER_COMMAND compose down unset COMPOSE_PROJECT_NAME - cd /tmp + cd /tmp || exit 1 rm -rf "$NOCO_HOME" mkdir -p "$NOCO_HOME" @@ -375,7 +376,7 @@ REQUIRED_PORTS=(80 443) echo "** Performing nocodb system check and setup. This step may require sudo permissions" -# pre install wget if not found +# pre-install wget if not found if ! command_exists wget; then echo "wget is not installed. Setting up for installation..." install_package wget @@ -398,7 +399,7 @@ done # f. Port mapping check echo " | Checking port accessibility..." for port in "${REQUIRED_PORTS[@]}"; do - if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null; then + if lsof -Pi :"$port" -sTCP:LISTEN -t >/dev/null; then echo " | WARNING: Port $port is in use. Please make sure it is free." >&2 else echo " | Port $port is free." @@ -458,7 +459,7 @@ fi if [ -n "$EDITION" ] && { [ "$EDITION" = "EE" ] || [ "$EDITION" = "ee" ]; }; then echo "Enter the NocoDB license key: " - read LICENSE_KEY + read -r LICENSE_KEY if [ -z "$LICENSE_KEY" ]; then echo "License key is required for Enterprise Edition installation" exit 1 diff --git a/docker-compose/setup-script/tests/redis.bats b/docker-compose/setup-script/tests/redis.bats index 6984d4e96a..c6a723803c 100644 --- a/docker-compose/setup-script/tests/redis.bats +++ b/docker-compose/setup-script/tests/redis.bats @@ -6,12 +6,12 @@ export NOCO_HOME WORKING_DIR="$(pwd)" setup() { - cd "${WORKING_DIR}" + cd "${WORKING_DIR}" || exit 1 ./setup.sh } teardown() { - cd "${WORKING_DIR}" + cd "${WORKING_DIR}" || exit 1 ./setup.sh } diff --git a/docker-compose/setup-script/tests/setup.sh b/docker-compose/setup-script/tests/setup.sh index e3a24ce010..2397e20809 100755 --- a/docker-compose/setup-script/tests/setup.sh +++ b/docker-compose/setup-script/tests/setup.sh @@ -5,8 +5,8 @@ if [ -z "$NOCO_HOME" ]; then fi if [ -d "$NOCO_HOME" ]; then - cd $NOCO_HOME + cd "$NOCO_HOME" || exit docker compose down fi -rm -rf $NOCO_HOME +rm -rf "$NOCO_HOME" From c8a0387ca2220b6b333a681ac6deb1758f13eada Mon Sep 17 00:00:00 2001 From: Rohit T P Date: Thu, 2 May 2024 12:05:05 +0000 Subject: [PATCH 03/16] test: test for watchtower and scaling --- .../tests/expects/{ => install}/redis.sh | 2 +- .../tests/expects/install/scale.sh | 31 +++++++++++++++++++ .../tests/expects/install/watchtower.sh | 31 +++++++++++++++++++ .../tests/{ => install}/redis.bats | 6 ++-- .../setup-script/tests/install/scale.bats | 31 +++++++++++++++++++ .../tests/install/watchtower.bats | 28 +++++++++++++++++ 6 files changed, 125 insertions(+), 4 deletions(-) rename docker-compose/setup-script/tests/expects/{ => install}/redis.sh (96%) create mode 100755 docker-compose/setup-script/tests/expects/install/scale.sh create mode 100755 docker-compose/setup-script/tests/expects/install/watchtower.sh rename docker-compose/setup-script/tests/{ => install}/redis.bats (87%) create mode 100644 docker-compose/setup-script/tests/install/scale.bats create mode 100644 docker-compose/setup-script/tests/install/watchtower.bats diff --git a/docker-compose/setup-script/tests/expects/redis.sh b/docker-compose/setup-script/tests/expects/install/redis.sh similarity index 96% rename from docker-compose/setup-script/tests/expects/redis.sh rename to docker-compose/setup-script/tests/expects/install/redis.sh index 652f990068..5f87ce533a 100755 --- a/docker-compose/setup-script/tests/expects/redis.sh +++ b/docker-compose/setup-script/tests/expects/install/redis.sh @@ -4,7 +4,7 @@ set timeout 10 # Start your main script -spawn bash ../noco.sh +spawn bash ../../noco.sh # Respond to script prompts expect "Enter the IP address or domain name for the NocoDB instance (default: localhost):" diff --git a/docker-compose/setup-script/tests/expects/install/scale.sh b/docker-compose/setup-script/tests/expects/install/scale.sh new file mode 100755 index 0000000000..3d75a3b350 --- /dev/null +++ b/docker-compose/setup-script/tests/expects/install/scale.sh @@ -0,0 +1,31 @@ +#!/usr/bin/expect -f + +# Configure timeout for each expect command +set timeout 10 + +# Start your main script +spawn bash ../../noco.sh + +# Respond to script prompts +expect "Enter the IP address or domain name for the NocoDB instance (default: localhost):" +send "\r" + +expect "Show Advanced Options*" +send "Y\r" + +expect "Choose Community or Enterprise Edition*" +send "\r" + +expect "Do you want to enabled Redis for caching*" +send "Y\r" + +expect "Do you want to enabled Watchtower for automatic updates*" +send "\r" + +expect "How many instances of NocoDB do you want to run*" +send "2\r" + +expect "Do you want to start the management menu*" +send "N\r" + +expect eof diff --git a/docker-compose/setup-script/tests/expects/install/watchtower.sh b/docker-compose/setup-script/tests/expects/install/watchtower.sh new file mode 100755 index 0000000000..8fc835b93e --- /dev/null +++ b/docker-compose/setup-script/tests/expects/install/watchtower.sh @@ -0,0 +1,31 @@ +#!/usr/bin/expect -f + +# Configure timeout for each expect command +set timeout 10 + +# Start your main script +spawn bash ../../noco.sh + +# Respond to script prompts +expect "Enter the IP address or domain name for the NocoDB instance (default: localhost):" +send "\r" + +expect "Show Advanced Options*" +send "Y\r" + +expect "Choose Community or Enterprise Edition*" +send "\r" + +expect "Do you want to enabled Redis for caching*" +send "\r" + +expect "Do you want to enabled Watchtower for automatic updates*" +send "Y\r" + +expect "How many instances of NocoDB do you want to run*" +send "\r" + +expect "Do you want to start the management menu*" +send "N\r" + +expect eof diff --git a/docker-compose/setup-script/tests/redis.bats b/docker-compose/setup-script/tests/install/redis.bats similarity index 87% rename from docker-compose/setup-script/tests/redis.bats rename to docker-compose/setup-script/tests/install/redis.bats index c6a723803c..f81c81549b 100644 --- a/docker-compose/setup-script/tests/redis.bats +++ b/docker-compose/setup-script/tests/install/redis.bats @@ -7,16 +7,16 @@ WORKING_DIR="$(pwd)" setup() { cd "${WORKING_DIR}" || exit 1 - ./setup.sh + ../setup.sh } teardown() { cd "${WORKING_DIR}" || exit 1 - ./setup.sh + ../setup.sh } @test "Check Redis is enabled when specified" { - ./expects/redis.sh + ../expects/install/redis.sh cd "${NOCO_HOME}" diff --git a/docker-compose/setup-script/tests/install/scale.bats b/docker-compose/setup-script/tests/install/scale.bats new file mode 100644 index 0000000000..a4f1daea2d --- /dev/null +++ b/docker-compose/setup-script/tests/install/scale.bats @@ -0,0 +1,31 @@ +#!/usr/bin/env bats + +NOCO_HOME="${HOME}/.nocodb" +export NOCO_HOME + +WORKING_DIR="$(pwd)" + +setup() { + cd "${WORKING_DIR}" || exit 1 + ../setup.sh +} + +teardown() { + cd "${WORKING_DIR}" || exit 1 + ../setup.sh +} + +@test "Check if two instances of NoCoDB can be run" { + # Mock nproc to return 4 + nproc() { + echo 4 + } + + ../expects/install/scale.sh + + cd "${NOCO_HOME}" + + # Get scale from docker compose ps + scale=$(docker compose ps | grep nocodb | awk '{print $1}') + [ "$scale" -eq 2 ] +} diff --git a/docker-compose/setup-script/tests/install/watchtower.bats b/docker-compose/setup-script/tests/install/watchtower.bats new file mode 100644 index 0000000000..7449237b7e --- /dev/null +++ b/docker-compose/setup-script/tests/install/watchtower.bats @@ -0,0 +1,28 @@ +#!/usr/bin/env bats + +NOCO_HOME="${HOME}/.nocodb" +export NOCO_HOME + +WORKING_DIR="$(pwd)" + +setup() { + cd "${WORKING_DIR}" || exit 1 + ../setup.sh +} + +teardown() { + cd "${WORKING_DIR}" || exit 1 + ../setup.sh +} + +@test "Check WatchTower is enabled when specified" { + ../expects/install/watchtower.sh + + cd "${NOCO_HOME}" + + # Check Docker Compose file to verify WatchTower configuration + grep -q 'watchtower' docker-compose.yml + + # Verify WatchTower container is running + docker compose ps | grep -q 'watchtower' +} From 635ab81d01dfe54c07fb485e8c8e061f2871a5b8 Mon Sep 17 00:00:00 2001 From: Rohit T P Date: Thu, 2 May 2024 12:10:07 +0000 Subject: [PATCH 04/16] test: test for default case and for custom ip --- .../tests/expects/install/default.sh | 19 +++++++++++ .../setup-script/tests/expects/install/ip.sh | 20 ++++++++++++ .../setup-script/tests/install/default.bats | 32 +++++++++++++++++++ .../setup-script/tests/install/ip.bats | 32 +++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100755 docker-compose/setup-script/tests/expects/install/default.sh create mode 100755 docker-compose/setup-script/tests/expects/install/ip.sh create mode 100644 docker-compose/setup-script/tests/install/default.bats create mode 100644 docker-compose/setup-script/tests/install/ip.bats diff --git a/docker-compose/setup-script/tests/expects/install/default.sh b/docker-compose/setup-script/tests/expects/install/default.sh new file mode 100755 index 0000000000..9dc978704e --- /dev/null +++ b/docker-compose/setup-script/tests/expects/install/default.sh @@ -0,0 +1,19 @@ +#!/usr/bin/expect -f + +# Configure timeout for each expect command +set timeout 10 + +# Start your main script +spawn bash ../../noco.sh + +# Respond to script prompts +expect "Enter the IP address or domain name for the NocoDB instance (default: localhost):" +send "\r" + +expect "Show Advanced Options*" +send "\r" + +expect "Do you want to start the management menu*" +send "N\r" + +expect eof diff --git a/docker-compose/setup-script/tests/expects/install/ip.sh b/docker-compose/setup-script/tests/expects/install/ip.sh new file mode 100755 index 0000000000..ab767dfcb6 --- /dev/null +++ b/docker-compose/setup-script/tests/expects/install/ip.sh @@ -0,0 +1,20 @@ +#!/usr/bin/expect -f +# shellcheck shell=bash + +# Configure timeout for each expect command +set timeout 10 + +# Start your main script +spawn bash ../../noco.sh + +# Respond to script prompts +expect "Enter the IP address or domain name for the NocoDB instance (default: localhost):" +send "192.168.1.10\r" + +expect "Show Advanced Options*" +send "\r" + +expect "Do you want to start the management menu*" +send "N\r" + +expect eof diff --git a/docker-compose/setup-script/tests/install/default.bats b/docker-compose/setup-script/tests/install/default.bats new file mode 100644 index 0000000000..1e3c5f4e82 --- /dev/null +++ b/docker-compose/setup-script/tests/install/default.bats @@ -0,0 +1,32 @@ +#!/usr/bin/env bats + +NOCO_HOME="${HOME}/.nocodb" +export NOCO_HOME + +WORKING_DIR="$(pwd)" + +setup() { + cd "${WORKING_DIR}" || exit 1 + ../setup.sh +} + +teardown() { + cd "${WORKING_DIR}" || exit 1 + ../setup.sh +} + +@test "Check Redis, WatchTower and NocoDB are up" { + ../expects/install/default.sh + + cd "${NOCO_HOME}" + + # Check Docker Compose file to verify configuration + grep -q 'redis' docker-compose.yml + grep -q 'watchtower' docker-compose.yml + grep -q 'nocodb' docker-compose.yml + + # Verify container is running + docker compose ps | grep -q 'redis' + docker compose ps | grep -q 'watchtower' + docker compose ps | grep -q 'nocodb' +} diff --git a/docker-compose/setup-script/tests/install/ip.bats b/docker-compose/setup-script/tests/install/ip.bats new file mode 100644 index 0000000000..88f06890ca --- /dev/null +++ b/docker-compose/setup-script/tests/install/ip.bats @@ -0,0 +1,32 @@ +#!/usr/bin/env bats + +NOCO_HOME="${HOME}/.nocodb" +export NOCO_HOME + +WORKING_DIR="$(pwd)" + +setup() { + cd "${WORKING_DIR}" || exit 1 + ../setup.sh +} + +teardown() { + cd "${WORKING_DIR}" || exit 1 + ../setup.sh +} + +@test "Check Redis, WatchTower and NocoDB are up with custom ip" { + ../expects/install/ip.sh + + cd "${NOCO_HOME}" + + # Check Docker Compose file to verify configuration + grep -q 'redis' docker-compose.yml + grep -q 'watchtower' docker-compose.yml + grep -q 'nocodb' docker-compose.yml + + # Verify container is running + docker compose ps | grep -q 'redis' + docker compose ps | grep -q 'watchtower' + docker compose ps | grep -q 'nocodb' +} From f18655e9c1a08ee15f400c8b26730005a1e3ce7e Mon Sep 17 00:00:00 2001 From: Rohit T P Date: Thu, 2 May 2024 12:24:27 +0000 Subject: [PATCH 05/16] test: test for configure/start --- .../setup-script/tests/configure/setup.sh | 18 +++++++++++++ .../setup-script/tests/configure/start.bats | 27 +++++++++++++++++++ .../tests/expects/configure/start.sh | 18 +++++++++++++ .../setup-script/tests/install/default.bats | 4 +-- .../setup-script/tests/install/ip.bats | 4 +-- .../setup-script/tests/install/redis.bats | 4 +-- .../setup-script/tests/install/scale.bats | 4 +-- .../setup-script/tests/{ => install}/setup.sh | 0 .../tests/install/watchtower.bats | 4 +-- 9 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 docker-compose/setup-script/tests/configure/setup.sh create mode 100644 docker-compose/setup-script/tests/configure/start.bats create mode 100644 docker-compose/setup-script/tests/expects/configure/start.sh rename docker-compose/setup-script/tests/{ => install}/setup.sh (100%) diff --git a/docker-compose/setup-script/tests/configure/setup.sh b/docker-compose/setup-script/tests/configure/setup.sh new file mode 100644 index 0000000000..4763483ff7 --- /dev/null +++ b/docker-compose/setup-script/tests/configure/setup.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +if [ -z "$NOCO_HOME" ]; then + NOCO_HOME="${HOME}/.nocodb" +fi + +if [ -d "$NOCO_HOME" ]; then + cd "$NOCO_HOME" || exit + docker compose down +fi + +cd /tmp || exit +rm -rf "$NOCO_HOME" + +../noco.sh <<< $'\n\nN\n' + +cd "$NOCO_HOME" || exit +docker compose down \ No newline at end of file diff --git a/docker-compose/setup-script/tests/configure/start.bats b/docker-compose/setup-script/tests/configure/start.bats new file mode 100644 index 0000000000..ea903e004f --- /dev/null +++ b/docker-compose/setup-script/tests/configure/start.bats @@ -0,0 +1,27 @@ +#!/usr/bin/env bats + +NOCO_HOME="${HOME}/.nocodb" +export NOCO_HOME + +WORKING_DIR="$(pwd)" + +setup() { + cd "${WORKING_DIR}" || exit 1 + setup.sh +} + +teardown() { + cd "${WORKING_DIR}" || exit 1 + setup.sh +} + +@test "Check Redis, WatchTower and NocoDB are up" { + ../expects/configure/start.sh + + cd "${NOCO_HOME}" || exit 1 + + # Verify container is running + docker compose ps | grep -q 'redis' + docker compose ps | grep -q 'watchtower' + docker compose ps | grep -q 'nocodb' +} diff --git a/docker-compose/setup-script/tests/expects/configure/start.sh b/docker-compose/setup-script/tests/expects/configure/start.sh new file mode 100644 index 0000000000..7e52e1a7ae --- /dev/null +++ b/docker-compose/setup-script/tests/expects/configure/start.sh @@ -0,0 +1,18 @@ +#!/usr/bin/expect -f + +# Configure timeout for each expect command +set timeout 10 + +# Start your main script +spawn bash ../../noco.sh + +expect "Do you want to reinstall NocoDB*" +send "N\r" + +expect "Enter your choice: " +send "1\r" + +expect "Enter your choice: " +send "0\r" + +expect EOF \ No newline at end of file diff --git a/docker-compose/setup-script/tests/install/default.bats b/docker-compose/setup-script/tests/install/default.bats index 1e3c5f4e82..a0e2c6cb78 100644 --- a/docker-compose/setup-script/tests/install/default.bats +++ b/docker-compose/setup-script/tests/install/default.bats @@ -7,12 +7,12 @@ WORKING_DIR="$(pwd)" setup() { cd "${WORKING_DIR}" || exit 1 - ../setup.sh + setup.sh } teardown() { cd "${WORKING_DIR}" || exit 1 - ../setup.sh + setup.sh } @test "Check Redis, WatchTower and NocoDB are up" { diff --git a/docker-compose/setup-script/tests/install/ip.bats b/docker-compose/setup-script/tests/install/ip.bats index 88f06890ca..41214a3c6d 100644 --- a/docker-compose/setup-script/tests/install/ip.bats +++ b/docker-compose/setup-script/tests/install/ip.bats @@ -7,12 +7,12 @@ WORKING_DIR="$(pwd)" setup() { cd "${WORKING_DIR}" || exit 1 - ../setup.sh + setup.sh } teardown() { cd "${WORKING_DIR}" || exit 1 - ../setup.sh + setup.sh } @test "Check Redis, WatchTower and NocoDB are up with custom ip" { diff --git a/docker-compose/setup-script/tests/install/redis.bats b/docker-compose/setup-script/tests/install/redis.bats index f81c81549b..c91e196bfb 100644 --- a/docker-compose/setup-script/tests/install/redis.bats +++ b/docker-compose/setup-script/tests/install/redis.bats @@ -7,12 +7,12 @@ WORKING_DIR="$(pwd)" setup() { cd "${WORKING_DIR}" || exit 1 - ../setup.sh + setup.sh } teardown() { cd "${WORKING_DIR}" || exit 1 - ../setup.sh + 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 a4f1daea2d..c343bff930 100644 --- a/docker-compose/setup-script/tests/install/scale.bats +++ b/docker-compose/setup-script/tests/install/scale.bats @@ -7,12 +7,12 @@ WORKING_DIR="$(pwd)" setup() { cd "${WORKING_DIR}" || exit 1 - ../setup.sh + setup.sh } teardown() { cd "${WORKING_DIR}" || exit 1 - ../setup.sh + setup.sh } @test "Check if two instances of NoCoDB can be run" { diff --git a/docker-compose/setup-script/tests/setup.sh b/docker-compose/setup-script/tests/install/setup.sh similarity index 100% rename from docker-compose/setup-script/tests/setup.sh rename to docker-compose/setup-script/tests/install/setup.sh diff --git a/docker-compose/setup-script/tests/install/watchtower.bats b/docker-compose/setup-script/tests/install/watchtower.bats index 7449237b7e..3dd107ca7c 100644 --- a/docker-compose/setup-script/tests/install/watchtower.bats +++ b/docker-compose/setup-script/tests/install/watchtower.bats @@ -7,12 +7,12 @@ WORKING_DIR="$(pwd)" setup() { cd "${WORKING_DIR}" || exit 1 - ../setup.sh + setup.sh } teardown() { cd "${WORKING_DIR}" || exit 1 - ../setup.sh + setup.sh } @test "Check WatchTower is enabled when specified" { From 0e9c96ab026928a5297b4e3a123c5125c6bb11b5 Mon Sep 17 00:00:00 2001 From: Rohit T P Date: Thu, 2 May 2024 12:45:40 +0000 Subject: [PATCH 06/16] fix: path error --- docker-compose/setup-script/tests/configure/setup.sh | 12 ++++++++---- .../setup-script/tests/configure/start.bats | 4 ++-- .../setup-script/tests/install/default.bats | 4 ++-- docker-compose/setup-script/tests/install/ip.bats | 4 ++-- docker-compose/setup-script/tests/install/redis.bats | 4 ++-- docker-compose/setup-script/tests/install/scale.bats | 4 ++-- .../setup-script/tests/install/watchtower.bats | 4 ++-- 7 files changed, 20 insertions(+), 16 deletions(-) mode change 100644 => 100755 docker-compose/setup-script/tests/configure/setup.sh mode change 100644 => 100755 docker-compose/setup-script/tests/configure/start.bats mode change 100644 => 100755 docker-compose/setup-script/tests/install/default.bats mode change 100644 => 100755 docker-compose/setup-script/tests/install/ip.bats mode change 100644 => 100755 docker-compose/setup-script/tests/install/redis.bats mode change 100644 => 100755 docker-compose/setup-script/tests/install/scale.bats mode change 100644 => 100755 docker-compose/setup-script/tests/install/watchtower.bats diff --git a/docker-compose/setup-script/tests/configure/setup.sh b/docker-compose/setup-script/tests/configure/setup.sh old mode 100644 new mode 100755 index 4763483ff7..ef17b873b7 --- a/docker-compose/setup-script/tests/configure/setup.sh +++ b/docker-compose/setup-script/tests/configure/setup.sh @@ -1,5 +1,7 @@ #!/bin/bash +WORKING_DIR=$(dirname "$0") + if [ -z "$NOCO_HOME" ]; then NOCO_HOME="${HOME}/.nocodb" fi @@ -9,10 +11,12 @@ if [ -d "$NOCO_HOME" ]; then docker compose down fi -cd /tmp || exit +cd "$WORKING_DIR" || exit rm -rf "$NOCO_HOME" -../noco.sh <<< $'\n\nN\n' +if [ "$1" = "setup" ]; then + ../../noco.sh <<< $'\n\nN\n' -cd "$NOCO_HOME" || exit -docker compose down \ No newline at end of file + cd "$NOCO_HOME" || exit + docker compose down +fi \ No newline at end of file diff --git a/docker-compose/setup-script/tests/configure/start.bats b/docker-compose/setup-script/tests/configure/start.bats old mode 100644 new mode 100755 index ea903e004f..66d3736ea3 --- a/docker-compose/setup-script/tests/configure/start.bats +++ b/docker-compose/setup-script/tests/configure/start.bats @@ -7,12 +7,12 @@ WORKING_DIR="$(pwd)" setup() { cd "${WORKING_DIR}" || exit 1 - setup.sh + ./setup.sh "setup" } teardown() { cd "${WORKING_DIR}" || exit 1 - setup.sh + ./setup.sh } @test "Check Redis, WatchTower and NocoDB are up" { diff --git a/docker-compose/setup-script/tests/install/default.bats b/docker-compose/setup-script/tests/install/default.bats old mode 100644 new mode 100755 index a0e2c6cb78..8edb902326 --- a/docker-compose/setup-script/tests/install/default.bats +++ b/docker-compose/setup-script/tests/install/default.bats @@ -7,12 +7,12 @@ WORKING_DIR="$(pwd)" setup() { cd "${WORKING_DIR}" || exit 1 - setup.sh + ./setup.sh } teardown() { cd "${WORKING_DIR}" || exit 1 - setup.sh + ./setup.sh } @test "Check Redis, WatchTower and NocoDB are up" { diff --git a/docker-compose/setup-script/tests/install/ip.bats b/docker-compose/setup-script/tests/install/ip.bats old mode 100644 new mode 100755 index 41214a3c6d..37be0cf4ec --- a/docker-compose/setup-script/tests/install/ip.bats +++ b/docker-compose/setup-script/tests/install/ip.bats @@ -7,12 +7,12 @@ WORKING_DIR="$(pwd)" setup() { cd "${WORKING_DIR}" || exit 1 - setup.sh + ./setup.sh } teardown() { cd "${WORKING_DIR}" || exit 1 - setup.sh + ./setup.sh } @test "Check Redis, WatchTower and NocoDB are up with custom ip" { diff --git a/docker-compose/setup-script/tests/install/redis.bats b/docker-compose/setup-script/tests/install/redis.bats old mode 100644 new mode 100755 index c91e196bfb..4c1ed94030 --- a/docker-compose/setup-script/tests/install/redis.bats +++ b/docker-compose/setup-script/tests/install/redis.bats @@ -7,12 +7,12 @@ WORKING_DIR="$(pwd)" setup() { cd "${WORKING_DIR}" || exit 1 - setup.sh + ./setup.sh } teardown() { cd "${WORKING_DIR}" || exit 1 - setup.sh + ./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 old mode 100644 new mode 100755 index c343bff930..3adb94e95a --- a/docker-compose/setup-script/tests/install/scale.bats +++ b/docker-compose/setup-script/tests/install/scale.bats @@ -7,12 +7,12 @@ WORKING_DIR="$(pwd)" setup() { cd "${WORKING_DIR}" || exit 1 - setup.sh + ./setup.sh } teardown() { cd "${WORKING_DIR}" || exit 1 - setup.sh + ./setup.sh } @test "Check if two instances of NoCoDB can be run" { diff --git a/docker-compose/setup-script/tests/install/watchtower.bats b/docker-compose/setup-script/tests/install/watchtower.bats old mode 100644 new mode 100755 index 3dd107ca7c..b66a1936eb --- a/docker-compose/setup-script/tests/install/watchtower.bats +++ b/docker-compose/setup-script/tests/install/watchtower.bats @@ -7,12 +7,12 @@ WORKING_DIR="$(pwd)" setup() { cd "${WORKING_DIR}" || exit 1 - setup.sh + ./setup.sh } teardown() { cd "${WORKING_DIR}" || exit 1 - setup.sh + ./setup.sh } @test "Check WatchTower is enabled when specified" { From 6610f3021394ab9f2d419c0ce374c8f870dceb2b Mon Sep 17 00:00:00 2001 From: Rohit T P Date: Thu, 2 May 2024 12:46:03 +0000 Subject: [PATCH 07/16] test: test for configure/stop --- .../setup-script/tests/configure/stop.bats | 27 +++++++++++++++++++ .../tests/expects/configure/start.sh | 0 .../tests/expects/configure/stop.sh | 18 +++++++++++++ 3 files changed, 45 insertions(+) create mode 100755 docker-compose/setup-script/tests/configure/stop.bats mode change 100644 => 100755 docker-compose/setup-script/tests/expects/configure/start.sh create mode 100644 docker-compose/setup-script/tests/expects/configure/stop.sh diff --git a/docker-compose/setup-script/tests/configure/stop.bats b/docker-compose/setup-script/tests/configure/stop.bats new file mode 100755 index 0000000000..3b4f05959d --- /dev/null +++ b/docker-compose/setup-script/tests/configure/stop.bats @@ -0,0 +1,27 @@ +#!/usr/bin/env bats + +NOCO_HOME="${HOME}/.nocodb" +export NOCO_HOME + +WORKING_DIR="$(pwd)" + +setup() { + cd "${WORKING_DIR}" || exit 1 + ./setup.sh +} + +teardown() { + cd "${WORKING_DIR}" || exit 1 + ./setup.sh +} + +@test "Check Redis, WatchTower and NocoDB are down" { + ../expects/configure/stop.sh + + cd "${NOCO_HOME}" || exit 1 + + # Verify container is not running + docker compose ps | grep -q 'redis' && fail "Redis is running" + docker compose ps | grep -q 'watchtower' && fail "WatchTower is running" + docker compose ps | grep -q 'nocodb' && fail "NocoDB is running" +} diff --git a/docker-compose/setup-script/tests/expects/configure/start.sh b/docker-compose/setup-script/tests/expects/configure/start.sh old mode 100644 new mode 100755 diff --git a/docker-compose/setup-script/tests/expects/configure/stop.sh b/docker-compose/setup-script/tests/expects/configure/stop.sh new file mode 100644 index 0000000000..830dc438bc --- /dev/null +++ b/docker-compose/setup-script/tests/expects/configure/stop.sh @@ -0,0 +1,18 @@ +#!/usr/bin/expect -f + +# Configure timeout for each expect command +set timeout 10 + +# Start your main script +spawn bash ../../noco.sh + +expect "Do you want to reinstall NocoDB*" +send "N\r" + +expect "Enter your choice: " +send "2\r" + +expect "Enter your choice: " +send "0\r" + +expect EOF \ No newline at end of file From f179ecf3257cf199855fc77123e1de6ee8ff66e0 Mon Sep 17 00:00:00 2001 From: Rohit T P Date: Thu, 2 May 2024 12:54:27 +0000 Subject: [PATCH 08/16] test: test for restart and upgrade --- .../setup-script/tests/configure/restart.bats | 27 +++++++++++++++++++ .../setup-script/tests/configure/upgrade.bats | 27 +++++++++++++++++++ .../tests/expects/configure/restart.sh | 18 +++++++++++++ .../tests/expects/configure/upgrade.sh | 18 +++++++++++++ 4 files changed, 90 insertions(+) create mode 100755 docker-compose/setup-script/tests/configure/restart.bats create mode 100755 docker-compose/setup-script/tests/configure/upgrade.bats create mode 100755 docker-compose/setup-script/tests/expects/configure/restart.sh create mode 100755 docker-compose/setup-script/tests/expects/configure/upgrade.sh diff --git a/docker-compose/setup-script/tests/configure/restart.bats b/docker-compose/setup-script/tests/configure/restart.bats new file mode 100755 index 0000000000..b2c2d53777 --- /dev/null +++ b/docker-compose/setup-script/tests/configure/restart.bats @@ -0,0 +1,27 @@ +#!/usr/bin/env bats + +NOCO_HOME="${HOME}/.nocodb" +export NOCO_HOME + +WORKING_DIR="$(pwd)" + +setup() { + cd "${WORKING_DIR}" || exit 1 + ./setup.sh "setup" +} + +teardown() { + cd "${WORKING_DIR}" || exit 1 + ./setup.sh +} + +@test "Check Redis, WatchTower and NocoDB are restarted" { + ../expects/configure/restart.sh + + cd "${NOCO_HOME}" || exit 1 + + # Verify container is running + docker compose ps | grep -q 'redis' + docker compose ps | grep -q 'watchtower' + docker compose ps | grep -q 'nocodb' +} diff --git a/docker-compose/setup-script/tests/configure/upgrade.bats b/docker-compose/setup-script/tests/configure/upgrade.bats new file mode 100755 index 0000000000..10b04b3dfb --- /dev/null +++ b/docker-compose/setup-script/tests/configure/upgrade.bats @@ -0,0 +1,27 @@ +#!/usr/bin/env bats + +NOCO_HOME="${HOME}/.nocodb" +export NOCO_HOME + +WORKING_DIR="$(pwd)" + +setup() { + cd "${WORKING_DIR}" || exit 1 + ./setup.sh "setup" +} + +teardown() { + cd "${WORKING_DIR}" || exit 1 + ./setup.sh +} + +@test "Check Redis, WatchTower and NocoDB are upgraded" { + ../expects/configure/upgrade.sh + + cd "${NOCO_HOME}" || exit 1 + + # Verify container is running + docker compose ps | grep -q 'redis' + docker compose ps | grep -q 'watchtower' + docker compose ps | grep -q 'nocodb' +} diff --git a/docker-compose/setup-script/tests/expects/configure/restart.sh b/docker-compose/setup-script/tests/expects/configure/restart.sh new file mode 100755 index 0000000000..22c358bc59 --- /dev/null +++ b/docker-compose/setup-script/tests/expects/configure/restart.sh @@ -0,0 +1,18 @@ +#!/usr/bin/expect -f + +# Configure timeout for each expect command +set timeout 10 + +# Start your main script +spawn bash ../../noco.sh + +expect "Do you want to reinstall NocoDB*" +send "N\r" + +expect "Enter your choice: " +send "4\r" + +expect "Enter your choice: " +send "0\r" + +expect EOF \ No newline at end of file diff --git a/docker-compose/setup-script/tests/expects/configure/upgrade.sh b/docker-compose/setup-script/tests/expects/configure/upgrade.sh new file mode 100755 index 0000000000..d45ccda9f1 --- /dev/null +++ b/docker-compose/setup-script/tests/expects/configure/upgrade.sh @@ -0,0 +1,18 @@ +#!/usr/bin/expect -f + +# Configure timeout for each expect command +set timeout 10 + +# Start your main script +spawn bash ../../noco.sh + +expect "Do you want to reinstall NocoDB*" +send "N\r" + +expect "Enter your choice: " +send "5\r" + +expect "Enter your choice: " +send "0\r" + +expect EOF \ No newline at end of file From 8882e0dfe446d3f8769e929301ae6f22a4700e1e Mon Sep 17 00:00:00 2001 From: Rohit T P Date: Thu, 2 May 2024 13:01:18 +0000 Subject: [PATCH 09/16] test: test for scaling --- .../setup-script/tests/configure/scale.bats | 25 +++++++++++++++++++ .../tests/expects/configure/scale.sh | 21 ++++++++++++++++ .../setup-script/tests/install/scale.bats | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100755 docker-compose/setup-script/tests/configure/scale.bats create mode 100755 docker-compose/setup-script/tests/expects/configure/scale.sh diff --git a/docker-compose/setup-script/tests/configure/scale.bats b/docker-compose/setup-script/tests/configure/scale.bats new file mode 100755 index 0000000000..89da5a308f --- /dev/null +++ b/docker-compose/setup-script/tests/configure/scale.bats @@ -0,0 +1,25 @@ +#!/usr/bin/env bats + +NOCO_HOME="${HOME}/.nocodb" +export NOCO_HOME + +WORKING_DIR="$(pwd)" + +setup() { + cd "${WORKING_DIR}" || exit 1 + ./setup.sh "setup" +} + +teardown() { + cd "${WORKING_DIR}" || exit 1 + ./setup.sh +} + +@test "Check NocoDB is scaled to 3 instances" { + ../expects/configure/scale.sh + + cd "${NOCO_HOME}" || exit 1 + + result=$(docker-compose ps | grep -c "nocodb/nocodb") + [ "${result}" -eq 3 ] +} diff --git a/docker-compose/setup-script/tests/expects/configure/scale.sh b/docker-compose/setup-script/tests/expects/configure/scale.sh new file mode 100755 index 0000000000..d51b9221da --- /dev/null +++ b/docker-compose/setup-script/tests/expects/configure/scale.sh @@ -0,0 +1,21 @@ +#!/usr/bin/expect -f + +# Configure timeout for each expect command +set timeout 10 + +# Start your main script +spawn bash ../../noco.sh + +expect "Do you want to reinstall NocoDB*" +send "N\r" + +expect "Enter your choice: " +send "6\r" + +expect "How many instances of NocoDB do you want to run*" +send "3\r" + +expect "Enter your choice: " +send "0\r" + +expect EOF \ No newline at end of file diff --git a/docker-compose/setup-script/tests/install/scale.bats b/docker-compose/setup-script/tests/install/scale.bats index 3adb94e95a..e64a7bf16f 100755 --- a/docker-compose/setup-script/tests/install/scale.bats +++ b/docker-compose/setup-script/tests/install/scale.bats @@ -26,6 +26,6 @@ teardown() { cd "${NOCO_HOME}" # Get scale from docker compose ps - scale=$(docker compose ps | grep nocodb | awk '{print $1}') + scale=$(docker compose ps | grep -c "nocodb/nocodb") [ "$scale" -eq 2 ] } From f139003e2f60f8088384c2b1f976734e80eb8e58 Mon Sep 17 00:00:00 2001 From: Rohit T P Date: Thu, 2 May 2024 13:05:10 +0000 Subject: [PATCH 10/16] test: test for monitoring --- .../setup-script/tests/configure/monitor.bats | 27 +++++++++++++++++++ .../tests/expects/configure/monitor.sh | 20 ++++++++++++++ 2 files changed, 47 insertions(+) create mode 100755 docker-compose/setup-script/tests/configure/monitor.bats create mode 100755 docker-compose/setup-script/tests/expects/configure/monitor.sh diff --git a/docker-compose/setup-script/tests/configure/monitor.bats b/docker-compose/setup-script/tests/configure/monitor.bats new file mode 100755 index 0000000000..8a1c1df327 --- /dev/null +++ b/docker-compose/setup-script/tests/configure/monitor.bats @@ -0,0 +1,27 @@ +#!/usr/bin/env bats + +NOCO_HOME="${HOME}/.nocodb" +export NOCO_HOME + +WORKING_DIR="$(pwd)" + +setup() { + cd "${WORKING_DIR}" || exit 1 + ./setup.sh "setup" +} + +teardown() { + cd "${WORKING_DIR}" || exit 1 + ./setup.sh +} + +@test "Properly runs monitor script" { + ../expects/configure/restart.sh + + cd "${NOCO_HOME}" || exit 1 + + # Verify container is running + docker compose ps | grep -q 'redis' + docker compose ps | grep -q 'watchtower' + docker compose ps | grep -q 'nocodb' +} diff --git a/docker-compose/setup-script/tests/expects/configure/monitor.sh b/docker-compose/setup-script/tests/expects/configure/monitor.sh new file mode 100755 index 0000000000..710672a175 --- /dev/null +++ b/docker-compose/setup-script/tests/expects/configure/monitor.sh @@ -0,0 +1,20 @@ +#!/usr/bin/expect -f + +# Configure timeout for each expect command +set timeout 10 + +# Start your main script +spawn bash ../../noco.sh + +expect "Do you want to reinstall NocoDB*" +send "N\r" + +expect "Enter your choice: " +send "7\r" + +send \x03 + +expect "Enter your choice: " +send "0\r" + +expect EOF \ No newline at end of file From f03bf62b6c6adcceaad1497bde3adfee48217e6a Mon Sep 17 00:00:00 2001 From: Rohit T P Date: Thu, 2 May 2024 14:50:39 +0000 Subject: [PATCH 11/16] test: test for ssl --- .../setup-script/tests/configure/scale.bats | 4 +++ .../setup-script/tests/expects/install/ssl.sh | 36 +++++++++++++++++++ .../setup-script/tests/install/ssl.bats | 21 +++++++++++ 3 files changed, 61 insertions(+) create mode 100755 docker-compose/setup-script/tests/expects/install/ssl.sh create mode 100644 docker-compose/setup-script/tests/install/ssl.bats diff --git a/docker-compose/setup-script/tests/configure/scale.bats b/docker-compose/setup-script/tests/configure/scale.bats index 89da5a308f..d4b8c672cc 100755 --- a/docker-compose/setup-script/tests/configure/scale.bats +++ b/docker-compose/setup-script/tests/configure/scale.bats @@ -16,6 +16,10 @@ teardown() { } @test "Check NocoDB is scaled to 3 instances" { + nproc() { + echo 4 + } + ../expects/configure/scale.sh cd "${NOCO_HOME}" || exit 1 diff --git a/docker-compose/setup-script/tests/expects/install/ssl.sh b/docker-compose/setup-script/tests/expects/install/ssl.sh new file mode 100755 index 0000000000..f8b4769701 --- /dev/null +++ b/docker-compose/setup-script/tests/expects/install/ssl.sh @@ -0,0 +1,36 @@ +#!/usr/bin/expect -f + +# Configure timeout for each expect command +set timeout 10 + +set random_number [lindex $argv 0] + +# Start your main script +spawn bash ../../noco.sh + +# Respond to script prompts +expect "Enter the IP address or domain name for the NocoDB instance (default: localhost):" +send "${random_number}.ssl.nocodb.dev\r" + +expect "Show Advanced Options*" +send "y\r" + +expect "Do you want to configure SSL*" +send "y\r" + +expect "Choose Community or Enterprise Edition*" +send "\r" + +expect "Do you want to enabled Redis for caching*" +send "Y\r" + +expect "Do you want to enabled Watchtower for automatic updates*" +send "\r" + +expect "How many instances of NocoDB do you want to run*" +send "\r" + +expect "Do you want to start the management menu*" +send "N\r" + +expect eof diff --git a/docker-compose/setup-script/tests/install/ssl.bats b/docker-compose/setup-script/tests/install/ssl.bats new file mode 100644 index 0000000000..d82f222d71 --- /dev/null +++ b/docker-compose/setup-script/tests/install/ssl.bats @@ -0,0 +1,21 @@ +#!/usr/bin/env bats + +WORKING_DIR="$(pwd)" + +RANDOM_NUMBER=$RANDOM + +setup() { + cd "${WORKING_DIR}" || exit 1 + ./setup.sh +} + +teardown() { + cd "${WORKING_DIR}" || exit 1 + ./setup.sh +} + +@test "Should create SSL certificates" { + ../expects/install/ssl.sh "$RANDOM_NUMBER" + + curl -ksS --head "https://${RANDOM_NUMBER}.ssl.nocodb.dev" > /dev/null +} From d9a9d4b9908f578cd495b41ff12c849f2c0e429f Mon Sep 17 00:00:00 2001 From: Rohit T P Date: Thu, 2 May 2024 15:16:14 +0000 Subject: [PATCH 12/16] fix: working directory fix --- docker-compose/setup-script/tests/configure/monitor.bats | 6 +++--- docker-compose/setup-script/tests/configure/restart.bats | 6 +++--- docker-compose/setup-script/tests/configure/scale.bats | 6 +++--- docker-compose/setup-script/tests/configure/setup.sh | 2 +- docker-compose/setup-script/tests/configure/start.bats | 6 +++--- docker-compose/setup-script/tests/configure/stop.bats | 6 +++--- docker-compose/setup-script/tests/configure/upgrade.bats | 6 +++--- docker-compose/setup-script/tests/install/default.bats | 6 +++--- docker-compose/setup-script/tests/install/ip.bats | 6 +++--- docker-compose/setup-script/tests/install/redis.bats | 6 +++--- docker-compose/setup-script/tests/install/scale.bats | 6 +++--- docker-compose/setup-script/tests/install/setup.sh | 5 +++++ docker-compose/setup-script/tests/install/ssl.bats | 6 +++--- docker-compose/setup-script/tests/install/watchtower.bats | 6 ++---- 14 files changed, 41 insertions(+), 38 deletions(-) diff --git a/docker-compose/setup-script/tests/configure/monitor.bats b/docker-compose/setup-script/tests/configure/monitor.bats index 8a1c1df327..50efa5e45a 100755 --- a/docker-compose/setup-script/tests/configure/monitor.bats +++ b/docker-compose/setup-script/tests/configure/monitor.bats @@ -3,15 +3,15 @@ NOCO_HOME="${HOME}/.nocodb" export NOCO_HOME -WORKING_DIR="$(pwd)" + setup() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/configure" || exit 1 ./setup.sh "setup" } teardown() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/configure" || exit 1 ./setup.sh } diff --git a/docker-compose/setup-script/tests/configure/restart.bats b/docker-compose/setup-script/tests/configure/restart.bats index b2c2d53777..eb388a0193 100755 --- a/docker-compose/setup-script/tests/configure/restart.bats +++ b/docker-compose/setup-script/tests/configure/restart.bats @@ -3,15 +3,15 @@ NOCO_HOME="${HOME}/.nocodb" export NOCO_HOME -WORKING_DIR="$(pwd)" + setup() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/configure" || exit 1 ./setup.sh "setup" } teardown() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/configure" || exit 1 ./setup.sh } diff --git a/docker-compose/setup-script/tests/configure/scale.bats b/docker-compose/setup-script/tests/configure/scale.bats index d4b8c672cc..7b84d3c262 100755 --- a/docker-compose/setup-script/tests/configure/scale.bats +++ b/docker-compose/setup-script/tests/configure/scale.bats @@ -3,15 +3,15 @@ NOCO_HOME="${HOME}/.nocodb" export NOCO_HOME -WORKING_DIR="$(pwd)" + setup() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/configure" || exit 1 ./setup.sh "setup" } teardown() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/configure" || exit 1 ./setup.sh } diff --git a/docker-compose/setup-script/tests/configure/setup.sh b/docker-compose/setup-script/tests/configure/setup.sh index ef17b873b7..57b782fbb8 100755 --- a/docker-compose/setup-script/tests/configure/setup.sh +++ b/docker-compose/setup-script/tests/configure/setup.sh @@ -19,4 +19,4 @@ if [ "$1" = "setup" ]; then cd "$NOCO_HOME" || exit docker compose down -fi \ No newline at end of file +fi diff --git a/docker-compose/setup-script/tests/configure/start.bats b/docker-compose/setup-script/tests/configure/start.bats index 66d3736ea3..39595d1dc8 100755 --- a/docker-compose/setup-script/tests/configure/start.bats +++ b/docker-compose/setup-script/tests/configure/start.bats @@ -3,15 +3,15 @@ NOCO_HOME="${HOME}/.nocodb" export NOCO_HOME -WORKING_DIR="$(pwd)" + setup() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/configure" || exit 1 ./setup.sh "setup" } teardown() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/configure" || exit 1 ./setup.sh } diff --git a/docker-compose/setup-script/tests/configure/stop.bats b/docker-compose/setup-script/tests/configure/stop.bats index 3b4f05959d..d28d15333f 100755 --- a/docker-compose/setup-script/tests/configure/stop.bats +++ b/docker-compose/setup-script/tests/configure/stop.bats @@ -3,15 +3,15 @@ NOCO_HOME="${HOME}/.nocodb" export NOCO_HOME -WORKING_DIR="$(pwd)" + setup() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/configure" || exit 1 ./setup.sh } teardown() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/configure" || exit 1 ./setup.sh } diff --git a/docker-compose/setup-script/tests/configure/upgrade.bats b/docker-compose/setup-script/tests/configure/upgrade.bats index 10b04b3dfb..ad45726808 100755 --- a/docker-compose/setup-script/tests/configure/upgrade.bats +++ b/docker-compose/setup-script/tests/configure/upgrade.bats @@ -3,15 +3,15 @@ NOCO_HOME="${HOME}/.nocodb" export NOCO_HOME -WORKING_DIR="$(pwd)" + setup() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/configure" || exit 1 ./setup.sh "setup" } teardown() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/configure" || exit 1 ./setup.sh } diff --git a/docker-compose/setup-script/tests/install/default.bats b/docker-compose/setup-script/tests/install/default.bats index 8edb902326..3417b71b3c 100755 --- a/docker-compose/setup-script/tests/install/default.bats +++ b/docker-compose/setup-script/tests/install/default.bats @@ -3,15 +3,15 @@ NOCO_HOME="${HOME}/.nocodb" export NOCO_HOME -WORKING_DIR="$(pwd)" + setup() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/install" || exit 1 ./setup.sh } teardown() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/install" || exit 1 ./setup.sh } diff --git a/docker-compose/setup-script/tests/install/ip.bats b/docker-compose/setup-script/tests/install/ip.bats index 37be0cf4ec..95c5c5ab4f 100755 --- a/docker-compose/setup-script/tests/install/ip.bats +++ b/docker-compose/setup-script/tests/install/ip.bats @@ -3,15 +3,15 @@ NOCO_HOME="${HOME}/.nocodb" export NOCO_HOME -WORKING_DIR="$(pwd)" + setup() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/install" || exit 1 ./setup.sh } teardown() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/install" || exit 1 ./setup.sh } diff --git a/docker-compose/setup-script/tests/install/redis.bats b/docker-compose/setup-script/tests/install/redis.bats index 4c1ed94030..4abc1d01c5 100755 --- a/docker-compose/setup-script/tests/install/redis.bats +++ b/docker-compose/setup-script/tests/install/redis.bats @@ -3,15 +3,15 @@ NOCO_HOME="${HOME}/.nocodb" export NOCO_HOME -WORKING_DIR="$(pwd)" + setup() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/install" || exit 1 ./setup.sh } teardown() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/install" || exit 1 ./setup.sh } diff --git a/docker-compose/setup-script/tests/install/scale.bats b/docker-compose/setup-script/tests/install/scale.bats index e64a7bf16f..7076e8176c 100755 --- a/docker-compose/setup-script/tests/install/scale.bats +++ b/docker-compose/setup-script/tests/install/scale.bats @@ -3,15 +3,15 @@ NOCO_HOME="${HOME}/.nocodb" export NOCO_HOME -WORKING_DIR="$(pwd)" + setup() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/install" || exit 1 ./setup.sh } teardown() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/install" || exit 1 ./setup.sh } diff --git a/docker-compose/setup-script/tests/install/setup.sh b/docker-compose/setup-script/tests/install/setup.sh index 2397e20809..8cedb9e1d9 100755 --- a/docker-compose/setup-script/tests/install/setup.sh +++ b/docker-compose/setup-script/tests/install/setup.sh @@ -10,3 +10,8 @@ if [ -d "$NOCO_HOME" ]; then fi rm -rf "$NOCO_HOME" + +clear() +{ + echo "clear mocked" +} diff --git a/docker-compose/setup-script/tests/install/ssl.bats b/docker-compose/setup-script/tests/install/ssl.bats index d82f222d71..62d57be1af 100644 --- a/docker-compose/setup-script/tests/install/ssl.bats +++ b/docker-compose/setup-script/tests/install/ssl.bats @@ -1,16 +1,16 @@ #!/usr/bin/env bats -WORKING_DIR="$(pwd)" + RANDOM_NUMBER=$RANDOM setup() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/install" || exit 1 ./setup.sh } teardown() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/install" || exit 1 ./setup.sh } diff --git a/docker-compose/setup-script/tests/install/watchtower.bats b/docker-compose/setup-script/tests/install/watchtower.bats index b66a1936eb..68f9cd651c 100755 --- a/docker-compose/setup-script/tests/install/watchtower.bats +++ b/docker-compose/setup-script/tests/install/watchtower.bats @@ -3,15 +3,13 @@ NOCO_HOME="${HOME}/.nocodb" export NOCO_HOME -WORKING_DIR="$(pwd)" - setup() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/install" || exit 1 ./setup.sh } teardown() { - cd "${WORKING_DIR}" || exit 1 + cd "${WORKING_DIR}/install" || exit 1 ./setup.sh } From dc8d6da4b97815370c320f9a79937baf21fd1ee4 Mon Sep 17 00:00:00 2001 From: Rohit T P Date: Thu, 2 May 2024 15:37:34 +0000 Subject: [PATCH 13/16] test: add mocks --- docker-compose/setup-script/tests/configure/stop.bats | 6 +++--- .../setup-script/tests/expects/configure/monitor.sh | 2 ++ .../setup-script/tests/expects/configure/restart.sh | 2 ++ .../setup-script/tests/expects/configure/scale.sh | 2 ++ .../setup-script/tests/expects/configure/start.sh | 2 ++ docker-compose/setup-script/tests/expects/configure/stop.sh | 2 ++ .../setup-script/tests/expects/configure/upgrade.sh | 2 ++ .../setup-script/tests/expects/install/default.sh | 2 ++ docker-compose/setup-script/tests/expects/install/ip.sh | 2 ++ docker-compose/setup-script/tests/expects/install/redis.sh | 2 ++ docker-compose/setup-script/tests/expects/install/scale.sh | 2 ++ docker-compose/setup-script/tests/expects/install/ssl.sh | 2 ++ .../setup-script/tests/expects/install/watchtower.sh | 2 ++ docker-compose/setup-script/tests/mocks/clear | 3 +++ docker-compose/setup-script/tests/mocks/nproc | 3 +++ 15 files changed, 33 insertions(+), 3 deletions(-) mode change 100644 => 100755 docker-compose/setup-script/tests/expects/configure/stop.sh create mode 100755 docker-compose/setup-script/tests/mocks/clear create mode 100755 docker-compose/setup-script/tests/mocks/nproc diff --git a/docker-compose/setup-script/tests/configure/stop.bats b/docker-compose/setup-script/tests/configure/stop.bats index d28d15333f..ea28380f18 100755 --- a/docker-compose/setup-script/tests/configure/stop.bats +++ b/docker-compose/setup-script/tests/configure/stop.bats @@ -21,7 +21,7 @@ teardown() { cd "${NOCO_HOME}" || exit 1 # Verify container is not running - docker compose ps | grep -q 'redis' && fail "Redis is running" - docker compose ps | grep -q 'watchtower' && fail "WatchTower is running" - docker compose ps | grep -q 'nocodb' && fail "NocoDB is running" + docker compose ps | grep -q 'redis' && exit 1 + docker compose ps | grep -q 'watchtower' && exit 1 + docker compose ps | grep -q 'nocodb' && exit 1 } diff --git a/docker-compose/setup-script/tests/expects/configure/monitor.sh b/docker-compose/setup-script/tests/expects/configure/monitor.sh index 710672a175..ba7479de81 100755 --- a/docker-compose/setup-script/tests/expects/configure/monitor.sh +++ b/docker-compose/setup-script/tests/expects/configure/monitor.sh @@ -4,6 +4,8 @@ set timeout 10 # Start your main script +set env(PATH) "$env(WORKING_DIR)/mocks:$env(PATH)" + spawn bash ../../noco.sh expect "Do you want to reinstall NocoDB*" diff --git a/docker-compose/setup-script/tests/expects/configure/restart.sh b/docker-compose/setup-script/tests/expects/configure/restart.sh index 22c358bc59..7abddf658c 100755 --- a/docker-compose/setup-script/tests/expects/configure/restart.sh +++ b/docker-compose/setup-script/tests/expects/configure/restart.sh @@ -4,6 +4,8 @@ set timeout 10 # Start your main script +set env(PATH) "$env(WORKING_DIR)/mocks:$env(PATH)" + spawn bash ../../noco.sh expect "Do you want to reinstall NocoDB*" diff --git a/docker-compose/setup-script/tests/expects/configure/scale.sh b/docker-compose/setup-script/tests/expects/configure/scale.sh index d51b9221da..2f3196ade7 100755 --- a/docker-compose/setup-script/tests/expects/configure/scale.sh +++ b/docker-compose/setup-script/tests/expects/configure/scale.sh @@ -4,6 +4,8 @@ set timeout 10 # Start your main script +set env(PATH) "$env(WORKING_DIR)/mocks:$env(PATH)" + spawn bash ../../noco.sh expect "Do you want to reinstall NocoDB*" diff --git a/docker-compose/setup-script/tests/expects/configure/start.sh b/docker-compose/setup-script/tests/expects/configure/start.sh index 7e52e1a7ae..ed8796c965 100755 --- a/docker-compose/setup-script/tests/expects/configure/start.sh +++ b/docker-compose/setup-script/tests/expects/configure/start.sh @@ -4,6 +4,8 @@ set timeout 10 # Start your main script +set env(PATH) "$env(WORKING_DIR)/mocks:$env(PATH)" + spawn bash ../../noco.sh expect "Do you want to reinstall NocoDB*" diff --git a/docker-compose/setup-script/tests/expects/configure/stop.sh b/docker-compose/setup-script/tests/expects/configure/stop.sh old mode 100644 new mode 100755 index 830dc438bc..78ef89592a --- a/docker-compose/setup-script/tests/expects/configure/stop.sh +++ b/docker-compose/setup-script/tests/expects/configure/stop.sh @@ -4,6 +4,8 @@ set timeout 10 # Start your main script +set env(PATH) "$env(WORKING_DIR)/mocks:$env(PATH)" + spawn bash ../../noco.sh expect "Do you want to reinstall NocoDB*" diff --git a/docker-compose/setup-script/tests/expects/configure/upgrade.sh b/docker-compose/setup-script/tests/expects/configure/upgrade.sh index d45ccda9f1..c03edb366d 100755 --- a/docker-compose/setup-script/tests/expects/configure/upgrade.sh +++ b/docker-compose/setup-script/tests/expects/configure/upgrade.sh @@ -4,6 +4,8 @@ set timeout 10 # Start your main script +set env(PATH) "$env(WORKING_DIR)/mocks:$env(PATH)" + spawn bash ../../noco.sh expect "Do you want to reinstall NocoDB*" diff --git a/docker-compose/setup-script/tests/expects/install/default.sh b/docker-compose/setup-script/tests/expects/install/default.sh index 9dc978704e..fa4fb58d3a 100755 --- a/docker-compose/setup-script/tests/expects/install/default.sh +++ b/docker-compose/setup-script/tests/expects/install/default.sh @@ -4,6 +4,8 @@ set timeout 10 # Start your main script +set env(PATH) "$env(WORKING_DIR)/mocks:$env(PATH)" + spawn bash ../../noco.sh # Respond to script prompts diff --git a/docker-compose/setup-script/tests/expects/install/ip.sh b/docker-compose/setup-script/tests/expects/install/ip.sh index ab767dfcb6..957a677efe 100755 --- a/docker-compose/setup-script/tests/expects/install/ip.sh +++ b/docker-compose/setup-script/tests/expects/install/ip.sh @@ -5,6 +5,8 @@ set timeout 10 # Start your main script +set env(PATH) "$env(WORKING_DIR)/mocks:$env(PATH)" + spawn bash ../../noco.sh # Respond to script prompts diff --git a/docker-compose/setup-script/tests/expects/install/redis.sh b/docker-compose/setup-script/tests/expects/install/redis.sh index 5f87ce533a..c3420a3007 100755 --- a/docker-compose/setup-script/tests/expects/install/redis.sh +++ b/docker-compose/setup-script/tests/expects/install/redis.sh @@ -4,6 +4,8 @@ set timeout 10 # Start your main script +set env(PATH) "$env(WORKING_DIR)/mocks:$env(PATH)" + spawn bash ../../noco.sh # Respond to script prompts diff --git a/docker-compose/setup-script/tests/expects/install/scale.sh b/docker-compose/setup-script/tests/expects/install/scale.sh index 3d75a3b350..584fb87cf7 100755 --- a/docker-compose/setup-script/tests/expects/install/scale.sh +++ b/docker-compose/setup-script/tests/expects/install/scale.sh @@ -4,6 +4,8 @@ set timeout 10 # Start your main script +set env(PATH) "$env(WORKING_DIR)/mocks:$env(PATH)" + spawn bash ../../noco.sh # Respond to script prompts diff --git a/docker-compose/setup-script/tests/expects/install/ssl.sh b/docker-compose/setup-script/tests/expects/install/ssl.sh index f8b4769701..229896067d 100755 --- a/docker-compose/setup-script/tests/expects/install/ssl.sh +++ b/docker-compose/setup-script/tests/expects/install/ssl.sh @@ -6,6 +6,8 @@ set timeout 10 set random_number [lindex $argv 0] # Start your main script +set env(PATH) "$env(WORKING_DIR)/mocks:$env(PATH)" + spawn bash ../../noco.sh # Respond to script prompts diff --git a/docker-compose/setup-script/tests/expects/install/watchtower.sh b/docker-compose/setup-script/tests/expects/install/watchtower.sh index 8fc835b93e..eeb4f6e493 100755 --- a/docker-compose/setup-script/tests/expects/install/watchtower.sh +++ b/docker-compose/setup-script/tests/expects/install/watchtower.sh @@ -4,6 +4,8 @@ set timeout 10 # Start your main script +set env(PATH) "$env(WORKING_DIR)/mocks:$env(PATH)" + spawn bash ../../noco.sh # Respond to script prompts diff --git a/docker-compose/setup-script/tests/mocks/clear b/docker-compose/setup-script/tests/mocks/clear new file mode 100755 index 0000000000..e08f792e8f --- /dev/null +++ b/docker-compose/setup-script/tests/mocks/clear @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "--- Clear Mock ---" \ No newline at end of file diff --git a/docker-compose/setup-script/tests/mocks/nproc b/docker-compose/setup-script/tests/mocks/nproc new file mode 100755 index 0000000000..1d83c4a9b0 --- /dev/null +++ b/docker-compose/setup-script/tests/mocks/nproc @@ -0,0 +1,3 @@ +#!/bin/bash + +echo 4 \ No newline at end of file From 1bacb13caada9c39856d43c1eb60f1763b4bb7d1 Mon Sep 17 00:00:00 2001 From: Rohit T P Date: Thu, 2 May 2024 15:49:34 +0000 Subject: [PATCH 14/16] refactor: renamed tests --- docker-compose/setup-script/tests/configure/restart.bats | 2 +- docker-compose/setup-script/tests/configure/scale.bats | 2 +- docker-compose/setup-script/tests/configure/setup.sh | 4 +--- docker-compose/setup-script/tests/configure/start.bats | 2 +- docker-compose/setup-script/tests/configure/stop.bats | 2 +- docker-compose/setup-script/tests/configure/upgrade.bats | 2 +- docker-compose/setup-script/tests/install/default.bats | 2 +- docker-compose/setup-script/tests/install/ip.bats | 2 +- docker-compose/setup-script/tests/install/scale.bats | 5 ----- docker-compose/setup-script/tests/install/setup.sh | 5 ----- 10 files changed, 8 insertions(+), 20 deletions(-) diff --git a/docker-compose/setup-script/tests/configure/restart.bats b/docker-compose/setup-script/tests/configure/restart.bats index eb388a0193..4eaa3b1eb5 100755 --- a/docker-compose/setup-script/tests/configure/restart.bats +++ b/docker-compose/setup-script/tests/configure/restart.bats @@ -15,7 +15,7 @@ teardown() { ./setup.sh } -@test "Check Redis, WatchTower and NocoDB are restarted" { +@test "Check all containers are restarted" { ../expects/configure/restart.sh cd "${NOCO_HOME}" || exit 1 diff --git a/docker-compose/setup-script/tests/configure/scale.bats b/docker-compose/setup-script/tests/configure/scale.bats index 7b84d3c262..ccb8832c93 100755 --- a/docker-compose/setup-script/tests/configure/scale.bats +++ b/docker-compose/setup-script/tests/configure/scale.bats @@ -24,6 +24,6 @@ teardown() { cd "${NOCO_HOME}" || exit 1 - result=$(docker-compose ps | grep -c "nocodb/nocodb") + result=$(docker compose ps | grep -c "nocodb/nocodb") [ "${result}" -eq 3 ] } diff --git a/docker-compose/setup-script/tests/configure/setup.sh b/docker-compose/setup-script/tests/configure/setup.sh index 57b782fbb8..346d769262 100755 --- a/docker-compose/setup-script/tests/configure/setup.sh +++ b/docker-compose/setup-script/tests/configure/setup.sh @@ -1,7 +1,5 @@ #!/bin/bash -WORKING_DIR=$(dirname "$0") - if [ -z "$NOCO_HOME" ]; then NOCO_HOME="${HOME}/.nocodb" fi @@ -15,7 +13,7 @@ cd "$WORKING_DIR" || exit rm -rf "$NOCO_HOME" if [ "$1" = "setup" ]; then - ../../noco.sh <<< $'\n\nN\n' +../noco.sh <<< $'\n\nN\n' cd "$NOCO_HOME" || exit docker compose down diff --git a/docker-compose/setup-script/tests/configure/start.bats b/docker-compose/setup-script/tests/configure/start.bats index 39595d1dc8..18be31a96f 100755 --- a/docker-compose/setup-script/tests/configure/start.bats +++ b/docker-compose/setup-script/tests/configure/start.bats @@ -15,7 +15,7 @@ teardown() { ./setup.sh } -@test "Check Redis, WatchTower and NocoDB are up" { +@test "Check all containers are up" { ../expects/configure/start.sh cd "${NOCO_HOME}" || exit 1 diff --git a/docker-compose/setup-script/tests/configure/stop.bats b/docker-compose/setup-script/tests/configure/stop.bats index ea28380f18..f075c23058 100755 --- a/docker-compose/setup-script/tests/configure/stop.bats +++ b/docker-compose/setup-script/tests/configure/stop.bats @@ -15,7 +15,7 @@ teardown() { ./setup.sh } -@test "Check Redis, WatchTower and NocoDB are down" { +@test "Check all containers are down" { ../expects/configure/stop.sh cd "${NOCO_HOME}" || exit 1 diff --git a/docker-compose/setup-script/tests/configure/upgrade.bats b/docker-compose/setup-script/tests/configure/upgrade.bats index ad45726808..4e791ad12e 100755 --- a/docker-compose/setup-script/tests/configure/upgrade.bats +++ b/docker-compose/setup-script/tests/configure/upgrade.bats @@ -15,7 +15,7 @@ teardown() { ./setup.sh } -@test "Check Redis, WatchTower and NocoDB are upgraded" { +@test "Check all containers are upgraded" { ../expects/configure/upgrade.sh cd "${NOCO_HOME}" || exit 1 diff --git a/docker-compose/setup-script/tests/install/default.bats b/docker-compose/setup-script/tests/install/default.bats index 3417b71b3c..2a4f887563 100755 --- a/docker-compose/setup-script/tests/install/default.bats +++ b/docker-compose/setup-script/tests/install/default.bats @@ -15,7 +15,7 @@ teardown() { ./setup.sh } -@test "Check Redis, WatchTower and NocoDB are up" { +@test "Check installation with all default options" { ../expects/install/default.sh cd "${NOCO_HOME}" diff --git a/docker-compose/setup-script/tests/install/ip.bats b/docker-compose/setup-script/tests/install/ip.bats index 95c5c5ab4f..1ab698b9be 100755 --- a/docker-compose/setup-script/tests/install/ip.bats +++ b/docker-compose/setup-script/tests/install/ip.bats @@ -15,7 +15,7 @@ teardown() { ./setup.sh } -@test "Check Redis, WatchTower and NocoDB are up with custom ip" { +@test "Check installation with custom ip" { ../expects/install/ip.sh cd "${NOCO_HOME}" diff --git a/docker-compose/setup-script/tests/install/scale.bats b/docker-compose/setup-script/tests/install/scale.bats index 7076e8176c..2c0523fe94 100755 --- a/docker-compose/setup-script/tests/install/scale.bats +++ b/docker-compose/setup-script/tests/install/scale.bats @@ -16,11 +16,6 @@ teardown() { } @test "Check if two instances of NoCoDB can be run" { - # Mock nproc to return 4 - nproc() { - echo 4 - } - ../expects/install/scale.sh cd "${NOCO_HOME}" diff --git a/docker-compose/setup-script/tests/install/setup.sh b/docker-compose/setup-script/tests/install/setup.sh index 8cedb9e1d9..2397e20809 100755 --- a/docker-compose/setup-script/tests/install/setup.sh +++ b/docker-compose/setup-script/tests/install/setup.sh @@ -10,8 +10,3 @@ if [ -d "$NOCO_HOME" ]; then fi rm -rf "$NOCO_HOME" - -clear() -{ - echo "clear mocked" -} From 1e12f0b49b8a2fe6d50c28a517591d9698ba4000 Mon Sep 17 00:00:00 2001 From: Rohit T P Date: Thu, 2 May 2024 16:36:10 +0000 Subject: [PATCH 15/16] chore: added skip for ssl --- docker-compose/setup-script/tests/configure/setup.sh | 5 +---- docker-compose/setup-script/tests/configure/stop.bats | 7 +++---- docker-compose/setup-script/tests/install/ssl.bats | 5 +++++ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/docker-compose/setup-script/tests/configure/setup.sh b/docker-compose/setup-script/tests/configure/setup.sh index 346d769262..3eee2485b5 100755 --- a/docker-compose/setup-script/tests/configure/setup.sh +++ b/docker-compose/setup-script/tests/configure/setup.sh @@ -13,8 +13,5 @@ cd "$WORKING_DIR" || exit rm -rf "$NOCO_HOME" if [ "$1" = "setup" ]; then -../noco.sh <<< $'\n\nN\n' - - cd "$NOCO_HOME" || exit - docker compose down + ../noco.sh <<< $'\n\nN\n' fi diff --git a/docker-compose/setup-script/tests/configure/stop.bats b/docker-compose/setup-script/tests/configure/stop.bats index f075c23058..e9b39c3b21 100755 --- a/docker-compose/setup-script/tests/configure/stop.bats +++ b/docker-compose/setup-script/tests/configure/stop.bats @@ -7,7 +7,7 @@ export NOCO_HOME setup() { cd "${WORKING_DIR}/configure" || exit 1 - ./setup.sh + ./setup.sh setup } teardown() { @@ -21,7 +21,6 @@ teardown() { cd "${NOCO_HOME}" || exit 1 # Verify container is not running - docker compose ps | grep -q 'redis' && exit 1 - docker compose ps | grep -q 'watchtower' && exit 1 - docker compose ps | grep -q 'nocodb' && exit 1 + count=$(docker compose ps -q | wc -l) + [ "$count" -eq 0 ] } diff --git a/docker-compose/setup-script/tests/install/ssl.bats b/docker-compose/setup-script/tests/install/ssl.bats index 62d57be1af..1d44344072 100644 --- a/docker-compose/setup-script/tests/install/ssl.bats +++ b/docker-compose/setup-script/tests/install/ssl.bats @@ -15,6 +15,11 @@ teardown() { } @test "Should create SSL certificates" { + if [ -z "$TEST_SSL" ] + then + skip "Skipping SSL tests" + fi + ../expects/install/ssl.sh "$RANDOM_NUMBER" curl -ksS --head "https://${RANDOM_NUMBER}.ssl.nocodb.dev" > /dev/null From 0315016d9589a1a75f45cf867ac33d1ac6def625 Mon Sep 17 00:00:00 2001 From: Rohit T P Date: Thu, 2 May 2024 22:59:23 +0530 Subject: [PATCH 16/16] 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" {