forked from gcash/bchd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_test.go
86 lines (69 loc) · 1.87 KB
/
config_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"testing"
)
var (
rpcuserRegexp = regexp.MustCompile("(?m)^rpcuser=.+$")
rpcpassRegexp = regexp.MustCompile("(?m)^rpcpass=.+$")
)
func TestExcessiveBlockSizeUserAgentComment(t *testing.T) {
// Wipe test args.
os.Args = []string{"bchd"}
cfg, _, err := loadConfig()
if err != nil {
t.Fatal("Failed to load configuration")
}
if len(cfg.UserAgentComments) != 1 {
t.Fatal("Expected EB UserAgentComment")
}
uac := cfg.UserAgentComments[0]
uacExpected := "EB32.0"
if uac != uacExpected {
t.Fatalf("Expected UserAgentComments to contain %s but got %s", uacExpected, uac)
}
// Custom excessive block size.
os.Args = []string{"bchd", "--excessiveblocksize=64000000"}
cfg, _, err = loadConfig()
if err != nil {
t.Fatal("Failed to load configuration")
}
if len(cfg.UserAgentComments) != 1 {
t.Fatal("Expected EB UserAgentComment")
}
uac = cfg.UserAgentComments[0]
uacExpected = "EB64.0"
if uac != uacExpected {
t.Fatalf("Expected UserAgentComments to contain %s but got %s", uacExpected, uac)
}
}
func TestCreateDefaultConfigFile(t *testing.T) {
// Setup a temporary directory
tmpDir, err := ioutil.TempDir("", "bchd")
if err != nil {
t.Fatalf("Failed creating a temporary directory: %v", err)
}
testpath := filepath.Join(tmpDir, "test.conf")
// Clean-up
defer func() {
os.Remove(testpath)
os.Remove(tmpDir)
}()
err = createDefaultConfigFile(testpath)
if err != nil {
t.Fatalf("Failed to create a default config file: %v", err)
}
content, err := ioutil.ReadFile(testpath)
if err != nil {
t.Fatalf("Failed to read generated default config file: %v", err)
}
if !rpcuserRegexp.Match(content) {
t.Error("Could not find rpcuser in generated default config file.")
}
if !rpcpassRegexp.Match(content) {
t.Error("Could not find rpcpass in generated default config file.")
}
}