-
Notifications
You must be signed in to change notification settings - Fork 57
/
init_internal_test.go
58 lines (45 loc) · 1.08 KB
/
init_internal_test.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package cmd
import (
"context"
"os"
"path/filepath"
"strings"
"testing"
"github.com/omni-network/omni/lib/netconf"
"github.com/omni-network/omni/lib/tutil"
"github.com/stretchr/testify/require"
)
//go:generate go test . -run TestInit -golden
func TestInitFiles(t *testing.T) {
t.Parallel()
dir := t.TempDir()
cfg := InitConfig{
HomeDir: dir,
Network: netconf.Simnet,
}
err := InitFiles(context.Background(), cfg)
require.NoError(t, err)
files, err := filepath.Glob(dir + "/**/*")
require.NoError(t, err)
var resp string
for _, file := range files {
resp += strings.TrimPrefix(file, dir) + "\n"
}
tutil.RequireGoldenBytes(t, []byte(resp))
}
func TestInitForce(t *testing.T) {
t.Parallel()
dir := t.TempDir()
// Create a dummy file
err := os.WriteFile(filepath.Join(dir, "dummy"), nil, 0o644)
require.NoError(t, err)
cfg := InitConfig{
HomeDir: dir,
Network: netconf.Simnet,
}
err = InitFiles(context.Background(), cfg)
require.ErrorContains(t, err, "unexpected file")
cfg.Force = true
err = InitFiles(context.Background(), cfg)
require.NoError(t, err)
}