This repository has been archived by the owner on Aug 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
control_test.go
103 lines (76 loc) · 3.95 KB
/
control_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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package syscoinrpc_test
import (
"os"
"testing"
"github.com/stretchr/testify/require"
"github.com/thebotguys/golang-syscoin-rpc-client"
)
func TestGetHelpInvalid(t *testing.T) {
cl, err := syscoinrpc.NewClient(invalidURL, "", "")
require.NoError(t, err, "Must have no error on creation, even with invalid URL")
_, err = cl.Control.GetHelp("")
require.Error(t, err, "Must error on any method with invalid URL")
}
func TestLoggingInvalid(t *testing.T) {
cl, err := syscoinrpc.NewClient(invalidURL, "", "")
require.NoError(t, err, "Must have no error on creation, even with invalid URL")
_, err = cl.Control.Logging([]string{}, []string{})
require.Error(t, err, "Must error on any method with invalid URL")
}
func TestGetMemoryInfoInvalid(t *testing.T) {
cl, err := syscoinrpc.NewClient(invalidURL, "", "")
require.NoError(t, err, "Must have no error on creation, even with invalid URL")
_, err = cl.Control.GetMemoryInfo()
require.Error(t, err, "Must error on any method with invalid URL")
}
func TestStopServerInvalid(t *testing.T) {
cl, err := syscoinrpc.NewClient(invalidURL, "", "")
require.NoError(t, err, "Must have no error on creation, even with invalid URL")
err = cl.Control.StopServer()
require.Error(t, err, "Must error on any method with invalid URL")
}
func TestGetUptimeInvalid(t *testing.T) {
cl, err := syscoinrpc.NewClient(invalidURL, "", "")
require.NoError(t, err, "Must have no error on creation, even with invalid URL")
_, err = cl.Control.GetUptime()
require.Error(t, err, "Must error on any method with invalid URL")
}
func TestGetHelpOK(t *testing.T) {
cl, err := syscoinrpc.NewClient(syscoinrpc.LocalNodeURL, os.Getenv("RPC_USER"), os.Getenv("RPC_PASSWORD"))
require.NoError(t, err, "Must have no error on creation, even with invalid URL")
expectedText := `"help ( \"command\" )\n\nList all commands, or get help for a specified command.\n\nArguments:\n1. \"command\" (string, optional) The command to get help on\n\nResult:\n\"text\" (string) The help text\n"`
text, err := cl.Control.GetHelp("help")
require.NoError(t, err, "Debug: Must not error")
require.Equal(t, expectedText, text, "GetHelp: `help` message must equal to the expected one")
}
func TestLoggingOK(t *testing.T) {
cl, err := syscoinrpc.NewClient(syscoinrpc.LocalNodeURL, os.Getenv("RPC_USER"), os.Getenv("RPC_PASSWORD"))
require.NoError(t, err, "Must have no error on creation, even with invalid URL")
includes := []string{"syscoin"}
excludes := []string{"tor"}
loggings, err := cl.Control.Logging(nil, nil)
require.NoError(t, err, "Loggings - no param: must not error")
t.Log("Loggings - no param:", loggings)
loggings, err = cl.Control.Logging(includes, nil)
require.NoError(t, err, "Loggings - only include: must not error")
t.Log("Loggings - only include:", loggings)
loggings, err = cl.Control.Logging(includes, excludes)
require.NoError(t, err, "Loggings - include + exclude: must not error")
t.Log("Loggings - include + exclude:", loggings)
loggings, err = cl.Control.Logging(nil, excludes)
require.EqualError(t, err, syscoinrpc.ErrLoggingFilters.Error(), "Loggings - only exclude: must error")
}
func TestGetMemoryInfoOK(t *testing.T) {
cl, err := syscoinrpc.NewClient(syscoinrpc.LocalNodeURL, os.Getenv("RPC_USER"), os.Getenv("RPC_PASSWORD"))
require.NoError(t, err, "Must have no error on creation, even with invalid URL")
info, err := cl.Control.GetMemoryInfo()
require.NoError(t, err, "GetMemoryInfo: must not error")
t.Log("GetMemoryInfo :", info)
}
func TestStopServerOK(t *testing.T) {
cl, err := syscoinrpc.NewClient(syscoinrpc.LocalNodeURL, os.Getenv("RPC_USER"), os.Getenv("RPC_PASSWORD"))
require.NoError(t, err, "Must have no error on creation, even with invalid URL")
t.Skip("This test would terminate the node, remove this skip to test it anyway")
err = cl.Control.StopServer()
require.NoError(t, err, "StopServer: must not error")
}