-
Notifications
You must be signed in to change notification settings - Fork 1
/
cmd_tests.go
53 lines (39 loc) · 1.24 KB
/
cmd_tests.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
package main
import (
"fmt"
"log"
tb "gopkg.in/tucnak/telebot.v2"
)
func (u *urlTester) test(m *tb.Message, returns []interface{}) {
u.testURL(m, false, returns)
}
func (u *urlTester) testFull(m *tb.Message, returns []interface{}) {
u.testURL(m, true, returns)
}
func (u *urlTester) testURL(m *tb.Message, full bool, returns []interface{}) {
var (
headerString string
message string
method string
urlString string
statusCode int
err error
)
u.saveHistory(m)
method = returns[0].(string)
urlString = returns[1].(string)
statusCode = returns[2].(int)
duration, body, headers, resultCode, _, _, _, expected, err := u.sendRequest(method, urlString, statusCode, "", "")
log.Println(method, urlString, statusCode, resultCode, expected, err)
if err != nil {
u.explainError(m, "", err)
return
}
headerString = headersToString(headers)
if full {
message = fmt.Sprintf("Expected result: %t\nDuration: %s\nhttp status: %d\n\nHeaders:\n%s\n\nBody:\n%s\n", expected, duration.String(), resultCode, headerString, body)
} else {
message = fmt.Sprintf("Expected result: %t\nDuration: %s\nhttp status: %d\n\nHeaders:\n%s\n", expected, duration.String(), resultCode, headerString)
}
u.bot.Send(m.Sender, message)
}