-
Notifications
You must be signed in to change notification settings - Fork 210
/
config.go
44 lines (37 loc) · 899 Bytes
/
config.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
35
36
37
38
39
40
41
42
43
44
package testutil
import (
"io/ioutil"
"os"
"path"
"testing"
"github.com/stretchr/testify/require"
tmconfig "github.com/tendermint/tendermint/config"
)
func TempDir(t *testing.T) string {
basedir, err := ioutil.TempDir("", t.Name())
require.NoError(t, err)
return basedir
}
func WithTempDir(t *testing.T, fn func(string)) {
dir := TempDir(t)
defer os.RemoveAll(dir)
fn(dir)
}
func WithTempDirEnv(t *testing.T, key string, fn func(string)) {
WithTempDir(t, func(dir string) {
// XXX: not thread/parallel-test safe
prev := os.Getenv(key)
os.Setenv(key, dir)
defer os.Setenv(key, prev)
fn(dir)
})
}
func WithAkashDir(t *testing.T, fn func(string)) {
WithTempDirEnv(t, "AKASH_DATA", fn)
}
func TMConfig(t *testing.T, basedir string) *tmconfig.Config {
cfg := tmconfig.TestConfig()
cfg.SetRoot(basedir)
os.MkdirAll(path.Dir(cfg.PrivValidatorFile()), 0755)
return cfg
}