-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# shellcheck shell=bash | ||
# shellcheck disable=SC2034 | ||
|
||
# shellcheck shell=bash | ||
|
||
Describe "ProxySQL Configuration Script Tests" | ||
|
||
Describe "Log Function Tests" | ||
Include ../scripts/configure-proxysql.sh | ||
|
||
It "outputs a log message" | ||
When call log "INFO" "Test log message" | ||
The status should be success | ||
The stdout should include "Test log message" | ||
End | ||
|
||
It "outputs a correctly formatted log message" | ||
When call log "INFO" "Test log message" | ||
The status should be success | ||
The stdout should match pattern "*[0-9][0-9]/[0-9][0-9]/[0-9][0-9]*" | ||
End | ||
End | ||
|
||
Describe "MySQL Exec Function Tests" | ||
Include ../scripts/configure-proxysql.sh | ||
|
||
It "executes MySQL command successfully" | ||
mysql() { | ||
echo "MySQL command executed: $@" | ||
return 0 | ||
} | ||
When call mysql_exec "root" "password" "localhost" "3306" "SELECT 1" | ||
The status should be success | ||
The stdout should match pattern "MySQL command executed: * SELECT 1" | ||
End | ||
|
||
It "fails to execute MySQL command" | ||
mysql() { | ||
echo "MySQL command failed: $@">&2 | ||
return 1 | ||
} | ||
When call mysql_exec "root" "password" "localhost" "3306" "INVALID COMMAND" | ||
The status should be failure | ||
The stderr should match pattern "MySQL command failed: * INVALID COMMAND" | ||
End | ||
End | ||
|
||
Describe "Wait for MySQL Function Tests" | ||
Include ../scripts/configure-proxysql.sh | ||
setup() { | ||
# Mock the mysql_exec function to simulate MySQL responses | ||
mysql_exec() { | ||
if [ "$5" == "select 1;" ]; then | ||
echo "1" | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
} | ||
Before 'setup' | ||
|
||
It "waits for MySQL to be online" | ||
When call wait_for_mysql "root" "password" "localhost" "3306" | ||
The output should include "Waiting for host localhost to be online ..." | ||
The status should be success | ||
End | ||
|
||
# no test for this case, as it will abort | ||
# It "fails to wait for MySQL to be online" | ||
# mysql_exec() { | ||
# echo failed | ||
# return 1 | ||
# } | ||
# sleep() { | ||
# } | ||
|
||
# When call wait_for_mysql "root" "password" "localhost" "3306" | ||
# The output should include "Server localhost start failed ..." | ||
# The status should be failure | ||
# End | ||
End | ||
End |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# shellcheck shell=bash | ||
# shellcheck disable=SC2034 | ||
|
||
|
||
# validate_shell_type_and_version defined in shellspec/spec_helper.sh used to validate the expected shell type and version this script needs to run. | ||
# if ! validate_shell_type_and_version "bash" &>/dev/null; then | ||
# echo "mongodb replicaset_setup_spec.sh skip all cases because dependency bash is not installed." | ||
# exit 0 | ||
# fi | ||
|
||
Describe "ProxySQL Entry Script Tests" | ||
|
||
init() { | ||
TEST_DATA_DIR="./test_data" | ||
export FRONTEND_TLS_ENABLED="false" | ||
} | ||
BeforeAll "init" | ||
|
||
cleanup() { | ||
rm -rf $TEST_DATA_DIR | ||
} | ||
AfterAll 'cleanup' | ||
|
||
Describe "Run proxysql-entry.sh with FRONTEND_TLS_ENABLED=false" | ||
|
||
It "runs successfully" | ||
When run source ../scripts/proxysql-entry.sh | ||
The status should be failure | ||
The stdout should include "Configuring proxysql ..." | ||
The stderr should include "/scripts/proxysql/configure-proxysql.sh: No such file or directory" | ||
End | ||
End | ||
|
||
|
||
Describe "Log Function Tests" | ||
Include ../scripts/proxysql-entry.sh | ||
|
||
It "outputs a log message" | ||
When call log "INFO" "Test log message" | ||
The status should be success | ||
The stdout should include "INFO" | ||
The stdout should include "Test log message" | ||
End | ||
End | ||
|
||
End |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters