forked from httprunner/hrp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep_test.go
79 lines (74 loc) · 2.49 KB
/
step_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
package httpboomer
import (
"testing"
)
var (
stepGET = Step("get with params").
GET("https://postman-echo.com/get").
WithParams(Params{"foo1": "bar1", "foo2": "bar2"}).
WithHeaders(Headers{"User-Agent": "HttpBoomer"}).
WithCookies(Cookies{"user": "debugtalk"}).
Validate().
AssertEqual("status_code", 200, "check status code")
stepPOSTData = Step("post form data").
POST("https://postman-echo.com/post").
WithParams(Params{"foo1": "bar1", "foo2": "bar2"}).
WithHeaders(Headers{"User-Agent": "HttpBoomer", "Content-Type": "application/x-www-form-urlencoded"}).
WithData("a=1&b=2").
WithCookies(Cookies{"user": "debugtalk"}).
Validate().
AssertEqual("status_code", 200, "check status code")
)
func TestRunRequestGetToStruct(t *testing.T) {
tStep := stepGET.ToStruct()
if tStep.Request.Method != GET {
t.Fatalf("tStep.Request.Method != GET")
}
if tStep.Request.URL != "https://postman-echo.com/get" {
t.Fatalf("tStep.Request.URL != 'https://postman-echo.com/get'")
}
if tStep.Request.Params["foo1"] != "bar1" || tStep.Request.Params["foo2"] != "bar2" {
t.Fatalf("tStep.Request.Params mismatch")
}
if tStep.Request.Headers["User-Agent"] != "HttpBoomer" {
t.Fatalf("tStep.Request.Headers mismatch")
}
if tStep.Request.Cookies["user"] != "debugtalk" {
t.Fatalf("tStep.Request.Cookies mismatch")
}
if tStep.Validators[0].Check != "status_code" || tStep.Validators[0].Expect != 200 {
t.Fatalf("tStep.Validators mismatch")
}
}
func TestRunRequestPostDataToStruct(t *testing.T) {
tStep := stepPOSTData.ToStruct()
if tStep.Request.Method != POST {
t.Fatalf("tStep.Request.Method != POST")
}
if tStep.Request.URL != "https://postman-echo.com/post" {
t.Fatalf("tStep.Request.URL != 'https://postman-echo.com/post'")
}
if tStep.Request.Params["foo1"] != "bar1" || tStep.Request.Params["foo2"] != "bar2" {
t.Fatalf("tStep.Request.Params mismatch")
}
if tStep.Request.Headers["User-Agent"] != "HttpBoomer" {
t.Fatalf("tStep.Request.Headers mismatch")
}
if tStep.Request.Cookies["user"] != "debugtalk" {
t.Fatalf("tStep.Request.Cookies mismatch")
}
if tStep.Request.Data != "a=1&b=2" {
t.Fatalf("tStep.Request.Data mismatch")
}
if tStep.Validators[0].Check != "status_code" || tStep.Validators[0].Expect != 200 {
t.Fatalf("tStep.Validators mismatch")
}
}
func TestRunRequestRun(t *testing.T) {
if err := stepGET.Run(); err != nil {
t.Fatalf("tStep.Run() error: %s", err)
}
if err := stepPOSTData.Run(); err != nil {
t.Fatalf("tStepPOSTData.Run() error: %s", err)
}
}