-
Notifications
You must be signed in to change notification settings - Fork 324
/
file.go
31 lines (26 loc) · 1 KB
/
file.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
// Copyright (c) 2018 IoTeX
// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no
// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent
// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache
// License 2.0 that can be found in the LICENSE file.
package testutil
import (
"io/ioutil"
"os"
"testing"
"github.com/iotexproject/iotex-core/pkg/util/fileutil"
)
// PathOfTempFile returns path of a new temporary file
func PathOfTempFile(dirName string) (string, error) {
tempFile, err := ioutil.TempFile(os.TempDir(), dirName)
if err != nil {
return "", err
}
return tempFile.Name(), tempFile.Close()
}
// CleanupPath detects the existence of test DB file and removes it if found
func CleanupPath(t *testing.T, path string) {
if fileutil.FileExists(path) && os.RemoveAll(path) != nil {
t.Error("Fail to remove testDB file")
}
}