Skip to content

Commit

Permalink
das-toolbox-125: Refactor dbms_peer and das_peer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
levisingularity committed Nov 8, 2024
1 parent 4c68c10 commit 46531a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions tests/integration/test_das_peer.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ load 'libs/docker'
setup() {
use_config "simple"

das-cli das-peer stop
das-cli dbms-adapter das-peer stop
das-cli db stop
}

Expand All @@ -18,7 +18,7 @@ setup() {
unset_config

for cmd in "${cmds[@]}"; do
run das-cli das-peer $cmd
run das-cli dbms-adapter das-peer $cmd

assert_output "[FileNotFoundError] Configuration file not found in ${das_config_file}. You can run the command \`config set\` to create a configuration file."
done
Expand All @@ -28,7 +28,7 @@ setup() {
local mongodb_container_name="$(get_config ".mongodb.container_name")"
local redis_container_name="$(get_config ".redis.container_name")"

run das-cli das-peer start
run das-cli dbms-adapter das-peer start

assert_output "$mongodb_container_name is not running
$redis_container_name is not running
Expand All @@ -54,7 +54,7 @@ Please use 'db start' to start required services before running 'das-peer start'

das-cli db start

run das-cli das-peer start
run das-cli dbms-adapter das-peer start

assert_output "$mongodb_container_name is running on port $mongodb_port
$redis_container_name is running on port $redis_port
Expand Down Expand Up @@ -86,7 +86,7 @@ DAS Peer is runnig on port $das_peer_port"
run is_service_up mongodb
assert_failure

run das-cli das-peer start
run das-cli dbms-adapter das-peer start

assert_output "$mongodb_container_name is not running
$redis_container_name is not running
Expand All @@ -111,12 +111,12 @@ Please use 'db start' to start required services before running 'das-peer start'
run is_service_up mongodb
assert_success

das-cli das-peer start
das-cli dbms-adapter das-peer start

run is_service_up das_peer
assert_success

run das-cli das-peer start
run das-cli dbms-adapter das-peer start

assert_output "$mongodb_container_name is running on port $mongodb_port
$redis_container_name is running on port $redis_port
Expand All @@ -134,14 +134,14 @@ Starting DAS Peer server...
run is_service_up mongodb
assert_success

das-cli das-peer start
das-cli dbms-adapter das-peer start

sleep 15s

run is_service_up das_peer
assert_success

run das-cli das-peer stop
run das-cli dbms-adapter das-peer stop

assert_output "Stopping DAS Peer service...
The DAS Peer service has been stopped."
Expand All @@ -161,7 +161,7 @@ The DAS Peer service has been stopped."
run is_service_up mongodb
assert_success

run das-cli das-peer stop
run das-cli dbms-adapter das-peer stop

assert_output "Stopping DAS Peer service...
The DAS Peer service named $das_peer_container_name is already stopped."
Expand Down
20 changes: 10 additions & 10 deletions tests/integration/test_dbms_peer.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ setup() {
use_config "simple"

das-cli db restart
das-cli das-peer restart
das-cli dbms-adapter das-peer restart

context_file_path="$test_fixtures_dir/dbms_context.txt"
postgres_container_name="dbms_peer_postgres"
Expand All @@ -28,44 +28,44 @@ teardown() {
@test "Trying run command with unset configuration file" {
unset_config

run das-cli dbms-peer run --client-hostname localhost --client-port 5432 --client-username postgres --client-password pass --client-database db --context $context_file_path
run das-cli dbms-adapter dbms-peer run --client-hostname localhost --client-port 5432 --client-username postgres --client-password pass --client-database db --context $context_file_path

assert_line --partial "[FileNotFoundError] Configuration file not found in ${das_config_file}. You can run the command \`config set\` to create a configuration file."
}

@test "Missing --client-hostname parameter" {
run das-cli dbms-peer run --client-port 5432 --client-username postgres --client-password pass --client-database db --context "$context_file_path"
run das-cli dbms-adapter dbms-peer run --client-port 5432 --client-username postgres --client-password pass --client-database db --context "$context_file_path"
assert_line --partial "Error: Missing option '--client-hostname'."
}

@test "Missing --client-port parameter" {
run das-cli dbms-peer run --client-hostname localhost --client-username postgres --client-password pass --client-database db --context "$context_file_path"
run das-cli dbms-adapter dbms-peer run --client-hostname localhost --client-username postgres --client-password pass --client-database db --context "$context_file_path"
assert_line --partial "Error: Missing option '--client-port'."
}

@test "Missing --client-username parameter" {
run das-cli dbms-peer run --client-hostname localhost --client-port 5432 --client-password pass --client-database db --context "$context_file_path"
run das-cli dbms-adapter dbms-peer run --client-hostname localhost --client-port 5432 --client-password pass --client-database db --context "$context_file_path"
assert_line --partial "Error: Missing option '--client-username'."
}

@test "Missing --client-password parameter" {
run das-cli dbms-peer run --client-hostname localhost --client-port 5432 --client-username postgres --client-database db --context "$context_file_path"
run das-cli dbms-adapter dbms-peer run --client-hostname localhost --client-port 5432 --client-username postgres --client-database db --context "$context_file_path"
assert_line --partial "Error: Missing option '--client-password'."
}

@test "Missing --context parameter" {
run das-cli dbms-peer run --client-hostname localhost --client-port 5432 --client-username postgres --client-password pass --client-database db
run das-cli dbms-adapter dbms-peer run --client-hostname localhost --client-port 5432 --client-username postgres --client-password pass --client-database db
assert_line --partial "Error: Missing option '--context'."
}

@test "Invalid path for --context parameter" {
local invalid_path="/path/invalid"
run das-cli dbms-peer run --client-hostname localhost --client-port 5432 --client-username postgres --client-password pass --client-database db --context "$invalid_path"
run das-cli dbms-adapter dbms-peer run --client-hostname localhost --client-port 5432 --client-username postgres --client-password pass --client-database db --context "$invalid_path"
assert_line --partial "Error: Invalid value for '--context': File '$invalid_path' does not exist."
}

@test "Directory provided instead of file for --context" {
run das-cli dbms-peer run --client-hostname localhost --client-port 5432 --client-username postgres --client-password pass --client-database db --context "$test_fixtures_dir"
run das-cli dbms-adapter dbms-peer run --client-hostname localhost --client-port 5432 --client-username postgres --client-password pass --client-database db --context "$test_fixtures_dir"
assert_line --partial "Error: Invalid value for '--context': File '$test_fixtures_dir' is a directory."
}

Expand All @@ -90,7 +90,7 @@ teardown() {
local client_database="$postgres_database"
local context="$test_fixtures_dir/dbms_context.txt"

run das-cli dbms-peer run \
run das-cli dbms-adapter dbms-peer run \
--client-hostname $client_hostname \
--client-port $client_port \
--client-username $client_username \
Expand Down

0 comments on commit 46531a2

Please sign in to comment.