forked from ruesandora/celestia-node-TR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_test.go
60 lines (49 loc) · 1.17 KB
/
init_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
59
60
package node
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/celestiaorg/celestia-node/libs/fslock"
)
func TestInit(t *testing.T) {
dir := t.TempDir()
nodes := []Type{Light, Bridge}
for _, node := range nodes {
require.NoError(t, Init(dir, node))
assert.True(t, IsInit(dir))
}
}
func TestInitErrForInvalidPath(t *testing.T) {
path := "/invalid_path"
nodes := []Type{Light, Bridge}
for _, node := range nodes {
require.Error(t, Init(path, node))
}
}
func TestIsInitWithBrokenConfig(t *testing.T) {
dir := t.TempDir()
f, err := os.Create(configPath(dir))
require.NoError(t, err)
defer f.Close()
//nolint:errcheck
f.Write([]byte(`
[P2P]
ListenAddresses = [/ip4/0.0.0.0/tcp/2121]
`))
assert.False(t, IsInit(dir))
}
func TestIsInitForNonExistDir(t *testing.T) {
path := "/invalid_path"
assert.False(t, IsInit(path))
}
func TestInitErrForLockedDir(t *testing.T) {
dir := t.TempDir()
flock, err := fslock.Lock(lockPath(dir))
require.NoError(t, err)
defer flock.Unlock() //nolint:errcheck
nodes := []Type{Light, Bridge}
for _, node := range nodes {
require.Error(t, Init(dir, node))
}
}