Skip to content

Commit

Permalink
use temp file, make sure to delete it
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach committed Sep 15, 2024
1 parent c4e7b96 commit 666e231
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions go/test/endtoend/onlineddl/exec_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func CreateTempScript(t *testing.T, content string) (fileName string) {
func MysqlClientExecFile(t *testing.T, mysqlParams *mysql.ConnParams, testDataPath, testName string, fileName string) (output string) {
t.Helper()

errorFile, err := os.CreateTemp("", "onlineddl-test-")
require.NoError(t, err)
defer os.Remove(errorFile.Name())

bashPath, err := exec.LookPath("bash")
require.NoError(t, err)
mysqlPath, err := exec.LookPath("mysql")
Expand All @@ -55,14 +59,14 @@ func MysqlClientExecFile(t *testing.T, mysqlParams *mysql.ConnParams, testDataPa
if !filepath.IsAbs(fileName) {
filePath, _ = filepath.Abs(path.Join(testDataPath, testName, fileName))
}
bashCommand := fmt.Sprintf(`%s -u%s --socket=%s --database=%s -s -s < %s 2> /tmp/error.log`, mysqlPath, mysqlParams.Uname, mysqlParams.UnixSocket, mysqlParams.DbName, filePath)
bashCommand := fmt.Sprintf(`%s -u%s --socket=%s --database=%s -s -s < %s 2> %s`, mysqlPath, mysqlParams.Uname, mysqlParams.UnixSocket, mysqlParams.DbName, filePath, errorFile.Name())
cmd, err := exec.Command(
bashPath,
"-c",
bashCommand,
).Output()

errorContent, readerr := os.ReadFile("/tmp/error.log")
errorContent, readerr := os.ReadFile(errorFile.Name())
require.NoError(t, readerr)
require.NoError(t, err, "error details: %s", errorContent)
return string(cmd)
Expand Down

0 comments on commit 666e231

Please sign in to comment.