Skip to content

Commit

Permalink
das-toolbox-125: Stop container after test is finished
Browse files Browse the repository at this point in the history
  • Loading branch information
levisingularity committed Nov 8, 2024
1 parent 407b6b1 commit 5d12f56
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
35 changes: 35 additions & 0 deletions scripts/stop_postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

function show_help {
echo "Usage: ./stop_postgres.sh [options]"
echo ""
echo "Options:"
echo " -n, --name Container name"
echo " -h, --help Show this help message"
exit 1
}

function main() {
while [[ "$#" -gt 0 ]]; do
case $1 in
-n|--name) POSTGRES_CONTAINER_NAME="$2"; shift ;;
-h|--help) show_help ;;
*) echo "Unknown option: $1"; show_help ;;
esac
shift
done

if [[ -z "$POSTGRES_CONTAINER_NAME" ]]; then
echo "Error: All required parameters must be provided."
show_help
fi

if [ "$(docker ps -q -f name=$POSTGRES_CONTAINER_NAME)" ]; then
docker rm -f "$POSTGRES_CONTAINER_NAME"
echo "Container $POSTGRES_CONTAINER_NAME stopped successfully!"
else
echo "Container $POSTGRES_CONTAINER_NAME is not running..."
fi
}

main "$@"
18 changes: 11 additions & 7 deletions tests/integration/test_dbms_peer.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ setup() {
das-cli das-peer restart

context_file_path="$test_fixtures_dir/dbms_context.txt"
postgres_container_name="dbms_peer_postgres"
postgres_password="postgres"
postgres_username="postgres"
postgres_database="integration_db"
postgres_port="5432"
postgres_initdb="$test_fixtures_dir/sql/db-adapter.sql"
}

teardown() {
"$(dirname "${BATS_TEST_DIRNAME}")/../scripts/stop_postgres.sh" \
-n $postgres_container_name
}

@test "Trying run command with unset configuration file" {
Expand Down Expand Up @@ -59,13 +70,6 @@ setup() {
}

@test "Should run DBMS Peer successfuly" {
local postgres_container_name="dbms_peer_postgres"
local postgres_password="postgres"
local postgres_username="postgres"
local postgres_database="integration_db"
local postgres_port="5432"
local postgres_initdb="$test_fixtures_dir/sql/db-adapter.sql"

"$(dirname "${BATS_TEST_DIRNAME}")/../scripts/start_postgres.sh" \
-n $postgres_container_name \
-p $postgres_password \
Expand Down

0 comments on commit 5d12f56

Please sign in to comment.