-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathseed_test.go
67 lines (59 loc) · 1.96 KB
/
seed_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 p2p
import (
"net/http"
"reflect"
"testing"
log "github.com/sirupsen/logrus"
)
func testServer() {
mux := http.NewServeMux()
mux.HandleFunc("/seed.txt", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("127.0.0.1:80\n192.168.0.1:8088\n10.12.13.14:8110"))
})
mux.HandleFunc("/seedBad.txt", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("192.168.0.1:8088\n10.12.13.14:8110"))
})
mux.HandleFunc("/seedBlank.txt", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(""))
})
mux.HandleFunc("/git.txt", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("52.17.183.121:8108\n52.17.153.126:8108\n52.19.117.149:8108\n52.18.72.212:8108\n52.19.44.249:8108\n52.214.189.110:8108\n34.249.228.82:8108\n34.248.202.6:8108\n52.19.181.120:8108\n34.248.6.133:8108"))
})
go http.ListenAndServe("127.0.0.1:8000", mux)
}
func Test_seed_retrieve(t *testing.T) {
testServer()
log.SetLevel(log.DebugLevel)
s := newSeed("http://localhost:8000/seed.txt", 0)
s2 := newSeed("http://localhost:8000/seedBad.txt", 0)
s3 := newSeed("http://localhost:8000/git.txt", 0)
s4 := newSeed("http://localhost:8000/seedBlank.txt", 0)
tests := []struct {
name string
s *seed
want []Endpoint
}{
{"base", s, []Endpoint{{"127.0.0.1", "80"}, {"192.168.0.1", "8088"}, {"10.12.13.14", "8110"}}},
{"bad", s2, []Endpoint{{"192.168.0.1", "8088"}, {"10.12.13.14", "8110"}}},
{"mainnet", s3, []Endpoint{
{"52.17.183.121", "8108"},
{"52.17.153.126", "8108"},
{"52.19.117.149", "8108"},
{"52.18.72.212", "8108"},
{"52.19.44.249", "8108"},
{"52.214.189.110", "8108"},
{"34.249.228.82", "8108"},
{"34.248.202.6", "8108"},
{"52.19.181.120", "8108"},
{"34.248.6.133", "8108"},
}},
{"blank", s4, []Endpoint{}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.s.retrieve(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("seed.retrieve() = %v, want %v", got, tt.want)
}
})
}
}