diff --git a/coreutils/testcase/mysql-test.sh b/coreutils/testcase/mysql-test.sh new file mode 100644 index 0000000000000000000000000000000000000000..36ca572881f39a4f492b7d1c5367ea442f4db15d --- /dev/null +++ b/coreutils/testcase/mysql-test.sh @@ -0,0 +1,98 @@ +#!/bin/bash +############################################################################### +# @用例ID: 20230525-101210-083410876 +# @用例名称: 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." + return 1 + fi + rm -rfv "$g_tmpdir" || return 1 + return 0 +} + + +############################################################################### +tst_main "$@" +###############################################################################