MCPcopy
hub / github.com/httprunner/httprunner / TestHTTPProtocol

Function TestHTTPProtocol

hrp/tests/protocol_test.go:9–54  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestHTTPProtocol(t *testing.T) {
10 testcase := &hrp.TestCase{
11 Config: hrp.NewConfig("run request with HTTP/1.1 and HTTP/2").
12 SetBaseURL("https://postman-echo.com"),
13 TestSteps: []hrp.IStep{
14 hrp.NewStep("HTTP/1.1 get").
15 GET("/get").
16 WithParams(map[string]interface{}{"foo1": "foo1", "foo2": "foo2"}).
17 WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
18 Validate().
19 AssertEqual("status_code", 200, "check status code").
20 AssertEqual("proto", "HTTP/1.1", "check protocol type").
21 AssertLengthEqual("body.args.foo1", 4, "check param foo1"),
22 hrp.NewStep("HTTP/1.1 post").
23 POST("/post").
24 WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
25 WithBody(map[string]interface{}{"foo1": "foo1", "foo2": "foo2"}).
26 Validate().
27 AssertEqual("status_code", 200, "check status code").
28 AssertEqual("proto", "HTTP/1.1", "check protocol type").
29 AssertLengthEqual("body.json.foo1", 4, "check body foo1"),
30 hrp.NewStep("HTTP/2 get").
31 HTTP2().
32 GET("/get").
33 WithParams(map[string]interface{}{"foo1": "foo1", "foo2": "foo2"}).
34 WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
35 Validate().
36 AssertEqual("status_code", 200, "check status code").
37 AssertEqual("proto", "HTTP/2.0", "check protocol type").
38 AssertLengthEqual("body.args.foo1", 4, "check param foo1"),
39 hrp.NewStep("HTTP/2 post").
40 HTTP2().
41 POST("/post").
42 WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
43 WithBody(map[string]interface{}{"foo1": "foo1", "foo2": "foo2"}).
44 Validate().
45 AssertEqual("status_code", 200, "check status code").
46 AssertEqual("proto", "HTTP/2.0", "check protocol type").
47 AssertLengthEqual("body.json.foo1", 4, "check body foo1"),
48 },
49 }
50 err := hrp.NewRunner(t).Run(testcase)
51 if err != nil {
52 t.Fatalf("run testcase error: %v", err)
53 }
54}
55
56func TestWebSocketProtocol(t *testing.T) {
57 testcase := &hrp.TestCase{

Callers

nothing calls this directly

Calls 14

NewConfigFunction · 0.92
NewStepFunction · 0.92
NewRunnerFunction · 0.92
SetBaseURLMethod · 0.80
AssertLengthEqualMethod · 0.80
AssertEqualMethod · 0.80
GETMethod · 0.80
WithBodyMethod · 0.80
POSTMethod · 0.80
HTTP2Method · 0.80
RunMethod · 0.65
ValidateMethod · 0.45

Tested by

no test coverage detected