MCPcopy
hub / github.com/gin-gonic/gin / testRequest

Function testRequest

gin_integration_test.go:31–64  ·  view source on GitHub ↗

params[0]=url example:http://127.0.0.1:8080/index (cannot be empty) params[1]=response status (custom compare status) default:"200 OK" params[2]=response body (custom compare content) default:"it worked"

(t *testing.T, params ...string)

Source from the content-addressed store, hash-verified

29// params[1]=response status (custom compare status) default:"200 OK"
30// params[2]=response body (custom compare content) default:"it worked"
31func testRequest(t *testing.T, params ...string) {
32 if len(params) == 0 {
33 t.Fatal("url cannot be empty")
34 }
35
36 tr := &http.Transport{
37 TLSClientConfig: &tls.Config{
38 InsecureSkipVerify: true,
39 },
40 }
41 client := &http.Client{Transport: tr}
42
43 resp, err := client.Get(params[0])
44 require.NoError(t, err)
45 defer resp.Body.Close()
46
47 body, ioerr := io.ReadAll(resp.Body)
48 require.NoError(t, ioerr)
49
50 responseStatus := "200 OK"
51 if len(params) > 1 && params[1] != "" {
52 responseStatus = params[1]
53 }
54
55 responseBody := "it worked"
56 if len(params) > 2 && params[2] != "" {
57 responseBody = params[2]
58 }
59
60 assert.Equal(t, responseStatus, resp.Status, "should get a "+responseStatus)
61 if responseStatus == "200 OK" {
62 assert.Equal(t, responseBody, string(body), "resp body should match")
63 }
64}
65
66func TestRunEmpty(t *testing.T) {
67 os.Setenv("PORT", "")

Callers 9

TestRunEmptyFunction · 0.85
TestRunTLSFunction · 0.85
TestPusherFunction · 0.85
TestRunEmptyWithEnvFunction · 0.85
TestRunWithPortFunction · 0.85
TestRunQUICFunction · 0.85
TestEscapedColonFunction · 0.85

Calls 2

CloseMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected