OSDN Git Service

fix log (#388)
[bytom/vapor.git] / config / toml_test.go
1 package config
2
3 import (
4         "io/ioutil"
5         "os"
6         "path/filepath"
7         "testing"
8
9         "github.com/stretchr/testify/assert"
10         "github.com/stretchr/testify/require"
11 )
12
13 func ensureFiles(t *testing.T, rootDir string, files ...string) {
14         for _, f := range files {
15                 p := rootify(rootDir, f)
16                 _, err := os.Stat(p)
17                 assert.Nil(t, err, p)
18         }
19 }
20
21 func TestEnsureRoot(t *testing.T) {
22         assert, require := assert.New(t), require.New(t)
23
24         // setup temp dir for test
25         tmpDir, err := ioutil.TempDir("", "config-test")
26         require.Nil(err)
27         defer os.RemoveAll(tmpDir)
28
29         // create root dir
30         EnsureRoot(tmpDir, "mainnet")
31
32         // make sure config is set properly
33         data, err := ioutil.ReadFile(filepath.Join(tmpDir, "config.toml"))
34         require.Nil(err)
35         assert.Equal([]byte(selectNetwork("mainnet")), data)
36
37         ensureFiles(t, tmpDir, "data")
38 }