forked from ruiaylin/pgparser
/
dir.go
34 lines (30 loc) · 832 Bytes
/
dir.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2016 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package testutils
import (
"io/ioutil"
"os"
"testing"
"github.com/ruiaylin/pgparser/utils/fileutil"
)
// TempDir creates a directory and a function to clean it up at the end of the
// test.
func TempDir(t testing.TB) (string, func()) {
dir, err := ioutil.TempDir("", fileutil.EscapeFilename(t.Name()))
if err != nil {
t.Fatal(err)
}
cleanup := func() {
if err := os.RemoveAll(dir); err != nil {
t.Error(err)
}
}
return dir, cleanup
}