forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ethstats_test.go
67 lines (61 loc) · 1.81 KB
/
ethstats_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
package ethstats
import (
"strconv"
"testing"
)
func TestParseEthstatsURL(t *testing.T) {
cases := []struct {
url string
node, pass, host string
}{
{
url: `"debug meowsbits":mypass@ws:https://mordor.dash.fault.dev:3000`,
node: "debug meowsbits", pass: "mypass", host: "ws:https://mordor.dash.fault.dev:3000",
},
{
url: `"debug @meowsbits":mypass@ws:https://mordor.dash.fault.dev:3000`,
node: "debug @meowsbits", pass: "mypass", host: "ws:https://mordor.dash.fault.dev:3000",
},
{
url: `"debug: @meowsbits":mypass@ws:https://mordor.dash.fault.dev:3000`,
node: "debug: @meowsbits", pass: "mypass", host: "ws:https://mordor.dash.fault.dev:3000",
},
{
url: `name:@ws:https://mordor.dash.fault.dev:3000`,
node: "name", pass: "", host: "ws:https://mordor.dash.fault.dev:3000",
},
{
url: `name@ws:https://mordor.dash.fault.dev:3000`,
node: "name", pass: "", host: "ws:https://mordor.dash.fault.dev:3000",
},
{
url: `:mypass@ws:https://mordor.dash.fault.dev:3000`,
node: "", pass: "mypass", host: "ws:https://mordor.dash.fault.dev:3000",
},
{
url: `:@ws:https://mordor.dash.fault.dev:3000`,
node: "", pass: "", host: "ws:https://mordor.dash.fault.dev:3000",
},
}
for i, c := range cases {
parts, err := parseEthstatsURL(c.url)
if err != nil {
t.Fatal(err)
}
node, pass, host := parts[0], parts[1], parts[2]
// unquote because the value provided will be used as a CLI flag value, so unescaped quotes will be removed
nodeUnquote, err := strconv.Unquote(node)
if err == nil {
node = nodeUnquote
}
if node != c.node {
t.Errorf("case=%d mismatch node value, got: %v ,want: %v", i, node, c.node)
}
if pass != c.pass {
t.Errorf("case=%d mismatch pass value, got: %v ,want: %v", i, pass, c.pass)
}
if host != c.host {
t.Errorf("case=%d mismatch host value, got: %v ,want: %v", i, host, c.host)
}
}
}