-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
48 lines (40 loc) · 1.02 KB
/
client_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
// refer to: https://github.com/btcsuite/btcd/blob/master/rpcclient/infrastructure.go
package bbrpc
import (
"fmt"
"strings"
"testing"
)
func TestNewClient(t *testing.T) {
killBigBangServer, err := RunBigBangServer(&RunBigBangOptions{
NewTmpDir: true,
Args: DefaultDebugBBArgs(),
})
tShouldNil(t, err)
defer killBigBangServer()
tests := []func(){
func() { //正常获取版本
client, err := NewClient(DefaultDebugConnConfig())
tShouldNil(t, err)
defer client.Shutdown()
ver, err := client.Version()
tShouldNil(t, err)
tShouldTrue(t, strings.Contains(ver, "."))
tShouldTrue(t, strings.Contains(ver, "v"))
},
func() { //错误的密码
opts := DefaultDebugConnConfig()
opts.Pass = "bad_pass"
c, err := NewClient(opts)
tShouldNil(t, err)
defer c.Shutdown()
_, err = c.Version()
tShouldTrue(t, err != nil)
tShouldTrue(t, strings.Contains(err.Error(), "401"), "not contains 401")
fmt.Println("bad pass error:", err.Error())
},
}
for _, fn := range tests {
fn()
}
}