From 7fed866c885a1d32e605d5c45369f701273414e3 Mon Sep 17 00:00:00 2001 From: hou Date: Thu, 25 May 2023 15:12:36 +0000 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90MYSQL=E7=9A=84=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E5=92=8C=E8=87=AA=E5=8A=A8=E9=AA=8C=E8=AF=81=20?= =?UTF-8?q?=E5=B7=B2=E4=B8=8A=E4=BC=A0=E5=88=B0=E7=BB=99=E5=AE=9A=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hou --- mariadb/testcase/mysql-test.sh | 98 ++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 mariadb/testcase/mysql-test.sh diff --git a/mariadb/testcase/mysql-test.sh b/mariadb/testcase/mysql-test.sh new file mode 100644 index 0000000..653c4a1 --- /dev/null +++ b/mariadb/testcase/mysql-test.sh @@ -0,0 +1,98 @@ +#!/bin/bash +############################################################################### +# @用例ID: 20230525-154056-556766079 +# @用例名称: mysql-test +# @用例级别: 3 +# @用例标签: +# @用例类型: 功能 +############################################################################### +[ -z "$TST_TS_TOPDIR" ] && { + TST_TS_TOPDIR="$(realpath "$(dirname "$0")/..")" + export TST_TS_TOPDIR +} +source "${TST_TS_TOPDIR}/tst_common/lib/common.sh" || exit 1 +############################################################################### + +g_tmpdir="$(mktemp -d)" + +tc_setup() { + msg "this is tc_setup" + + #检查是否安装了MySQL + + if ! command -v mysql >/dev/null 2>&1; then + echo "MySQL not installed." + return 1 + else + mysql_version=$(mysql -V |awk '{print $3}' | awk -F, '{print $1}') + echo "MySQL version: $mysql_version" + fi + + # 启动MySQL + sudo service mysql start + + #检查MySQL是否成功启动 + status=$(service mysql status) + + if echo "$status" | grep -q "MySQL running";then + echo "MySQL started successfully." + return 0 + else + echo "Failed to start MySQL." + return 1 + fi +} + +do_test() { + msg "this is do_test" + + # 运行MySQL测试 + + #查找安装路径 + mysql_install_path=$(which mysql) + cd $(dirname $(which mysql)) + cd .. + cd mysql-test + ./mysql-test-run 2>&1 | tee test_output.txt + + #检查测试结果 + + if grep -q "All tests" "test_output.txt"; then + echo "All tests passed" + elif grep -q "Not all tests completed" "test_output.txt";then + echo "Some tests failed" + else + echo "Test failed!" + return 1 + fi + + assert_true [ 1 -eq 1 ] + + return 0 +} + + + +tc_teardown() { + msg "this is tc_teardown" + #关闭MySQL + sudo service mysql stop + + #等待MySQL关闭 + sleep 10 + + #检查MySQL是否关闭成功 + status=$(sudo service mysql status) + if echo "status" | grep -q "MySQL running";then + echo "Failed to stop the mysql." + else + echo "The mysql has been successfully stopped." + fi + rm -rfv "$g_tmpdir" || return 1 + return 0 +} + + +############################################################################### +tst_main "$@" +############################################################################### -- Gitee