Skip to content

Commit

Permalink
executor: fix file exists errors in tests for select into outfile (#…
Browse files Browse the repository at this point in the history
…19717) (#19725)

Co-authored-by: Yuanjia Zhang <zhangyuanjia@pingcap.com>
  • Loading branch information
ti-srebot and qw4990 authored Sep 3, 2020
1 parent 0299a31 commit 06fbed8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions executor/select_into_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ func cmpAndRm(expected, outfile string, c *C) {
c.Assert(os.Remove(outfile), IsNil)
}

func randomSelectFilePath(testName string) string {
return filepath.Join(os.TempDir(), fmt.Sprintf("select-into-%v-%v.data", testName, time.Now().Nanosecond()))
}

func (s *testSuite1) TestSelectIntoFileExists(c *C) {
outfile := filepath.Join(os.TempDir(), fmt.Sprintf("TestSelectIntoFileExists-%v.data", time.Now().Nanosecond()))
outfile := randomSelectFilePath("TestSelectIntoFileExists")
defer func() {
c.Assert(os.Remove(outfile), IsNil)
}()
Expand All @@ -51,8 +55,7 @@ func (s *testSuite1) TestSelectIntoFileExists(c *C) {
}

func (s *testSuite1) TestSelectIntoOutfileTypes(c *C) {
tmpDir := os.TempDir()
outfile := filepath.Join(tmpDir, "select-into-outfile.data")
outfile := randomSelectFilePath("TestSelectIntoOutfileTypes")
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

Expand Down Expand Up @@ -86,8 +89,7 @@ func (s *testSuite1) TestSelectIntoOutfileTypes(c *C) {
}

func (s *testSuite1) TestSelectIntoOutfileFromTable(c *C) {
tmpDir := os.TempDir()
outfile := filepath.Join(tmpDir, "TestSelectIntoOutfileFromTable.data")
outfile := randomSelectFilePath("TestSelectIntoOutfileFromTable")
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

Expand Down Expand Up @@ -128,8 +130,7 @@ func (s *testSuite1) TestSelectIntoOutfileFromTable(c *C) {
}

func (s *testSuite1) TestSelectIntoOutfileConstant(c *C) {
tmpDir := os.TempDir()
outfile := filepath.Join(tmpDir, "TestSelectIntoOutfileConstant.data")
outfile := randomSelectFilePath("TestSelectIntoOutfileConstant")
tk := testkit.NewTestKit(c, s.store)
// On windows the outfile name looks like "C:\Users\genius\AppData\Local\Temp\select-into-outfile.data",
// fmt.Sprintf("%q") is used otherwise the string become
Expand Down

0 comments on commit 06fbed8

Please sign in to comment.