forked from Difrex/go-idec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proto_test.go
162 lines (143 loc) · 4.57 KB
/
proto_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package idec
import (
"net/http"
"testing"
"gopkg.in/jarcoal/httpmock.v1"
)
func TestNewExtensions(t *testing.T) {
e := NewExtensions()
if e.ListTXT != "list.txt" {
t.Error("list.txt not found")
}
}
func TestGetMessagesIDS(t *testing.T) {
httpmock.Activate()
fc := FetchConfig{
Node: "http://localhost/idec/",
Echoes: []string{"ii.test.14"},
Num: 5,
Offset: -5,
Limit: 5,
}
httpmock.RegisterResponder("GET", "http://localhost/idec/u/e/ii.test.14/-5:5", func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(200, `ii.test.14
hXzRNEzmMuzKkT1HCxUb
JN3ylpxjaNofxgPy6NhL
xF3kkmrZYld330BO7qaA
3uS3uij0Y4AUnSxhf4WB
zi9YpQGddLW5WQKi9GMf`)
return resp, nil
})
id, err := fc.GetMessagesIDS()
if err != nil {
t.Error(err)
}
if len(id) == 0 {
t.Error("Message not fetched")
}
}
func TestGetAllMessagesIDS(t *testing.T) {
httpmock.Activate()
fc := FetchConfig{
Node: "http://localhost/idec/",
Echoes: []string{"ii.test.14"},
}
httpmock.RegisterResponder("GET", "http://localhost/idec/u/e/ii.test.14", func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(200, `ii.test.14
hXzRNEzmMuzKkT1HCxUb
JN3ylpxjaNofxgPy6NhL
xF3kkmrZYld330BO7qaA
3uS3uij0Y4AUnSxhf4WB
zi9YpQGddLW5WQKi9GMf`)
return resp, nil
})
id, err := fc.GetAllMessagesIDS()
if err != nil {
t.Error(err)
}
if len(id) == 0 {
t.Error("Message not fetched")
}
}
func TestGetRawMessages(t *testing.T) {
httpmock.Activate()
fc := FetchConfig{
Node: "http://localhost/idec/",
Echoes: []string{"ii.test.14"},
}
httpmock.RegisterResponder("GET", "http://localhost/idec/u/m/hXzRNEzmMuzKkT1HCxUb/JN3ylpxjaNofxgPy6NhL", func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(200, `hXzRNEzmMuzKkT1HCxUb:aWkvb2svcmVwdG8vSk4zeWxweGphTm9meGdQeTZOaEwKaWkudGVzdC4xNAoxNTUxNjk5NjE0CkRpZnJleApkeW5hbWljLDEKRGlmcmV4ClJlOiBpZGVjCgpzZGZnc2ZkZyBzZGdmCgpmZGcgc2dmIHMKCmZkZyBzZGZnIHMKc2RmZyBzZGZnIHMKCgoKc2ZkZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dn
JN3ylpxjaNofxgPy6NhL:aWkvb2svcmVwdG8veEYza2ttclpZbGQzMzBCTzdxYUEKaWkudGVzdC4xNAoxNTUxNjk5NTk1CkRpZnJleApkeW5hbWljLDEKRGlmcmV4ClJlOiBpZGVjCgpKS0hKS0hLSlNGSCBscwo9PT0gZHMKc2RmZyBzZGZnCmdmc2QgZGZnc2dmIGYKPT09PQpzaCAtYyAnZWNobyBPSycKPT09PQ==`)
return resp, nil
})
ids := []ID{ID{"ii.test.14", "hXzRNEzmMuzKkT1HCxUb"}, ID{"ii.test.14", "JN3ylpxjaNofxgPy6NhL"}}
msg, err := fc.GetRawMessages(ids)
if err != nil {
t.Error(err)
}
if len(msg) == 0 {
t.Error("Messages not fetched")
}
}
func TestGetEchoList(t *testing.T) {
httpmock.Activate()
fc := FetchConfig{
Node: "http://localhost/idec/",
Echoes: []string{"ii.test.14"},
}
httpmock.RegisterResponder("GET", "http://localhost/idec/x/features", func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(200, `list.txt
u/e
u/m
x/c`)
return resp, nil
})
httpmock.RegisterResponder("GET", "http://localhost/idec/list.txt", func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(200, `bash.rss:14573:RSS с сайта bash.im
creepy.14:334:Страшные истории
develop.16:402:Обсуждение вопросов программирования
file.wishes:10:Поиск файлов`)
return resp, nil
})
echoes, err := fc.GetEchoList()
if err != nil {
t.Error(err)
}
if len(echoes) == 0 {
t.Error("Wrong echoes list")
}
httpmock.RegisterResponder("GET", "http://localhost/idec/x/features", func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(200, `u/e
u/m
x/c`)
return resp, nil
})
_, err = fc.GetEchoList()
if err == nil {
t.Error(err)
}
}
func TestPostMessage(t *testing.T) {
httpmock.Activate()
fc := FetchConfig{
Node: "http://localhost/idec/",
Echoes: []string{"ii.test.14"},
}
message := "aWkvb2svcmVwdG8veEYza2ttclpZbGQzMzBCTzdxYUEKaWkudGVzdC4xNAoxNTUxNjk5NTk1CkRpZnJleApkeW5hbWljLDEKRGlmcmV4ClJlOiBpZGVjCgpKS0hKS0hLSlNGSCBscwo9PT0gZHMKc2RmZyBzZGZnCmdmc2QgZGZnc2dmIGYKPT09PQpzaCAtYyAnZWNobyBPSycKPT09PQ=="
httpmock.RegisterResponder("POST", "http://localhost/idec/u/point", func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(200, `msg ok`)
return resp, nil
})
err := fc.PostMessage("auth", message)
if err != nil {
t.Error(err)
}
httpmock.RegisterResponder("POST", "http://localhost/idec/u/point", func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(403, `error: wrong authstring`)
return resp, nil
})
err = fc.PostMessage("auth", message)
if err == nil {
t.Error("Errors not precessed")
}
}