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

Function TestH2c

gin_test.go:85–121  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

83}
84
85func TestH2c(t *testing.T) {
86 ln, err := net.Listen("tcp", localhostIP+":0")
87 if err != nil {
88 t.Error(err)
89 }
90 r := Default()
91 r.UseH2C = true
92 r.GET("/", func(c *Context) {
93 c.String(200, "<h1>Hello world</h1>")
94 })
95 go func() {
96 err := http.Serve(ln, r.Handler())
97 if err != nil {
98 t.Log(err)
99 }
100 }()
101 defer ln.Close()
102
103 url := "http://" + ln.Addr().String() + "/"
104
105 httpClient := http.Client{
106 Transport: &http2.Transport{
107 AllowHTTP: true,
108 DialTLS: func(netw, addr string, cfg *tls.Config) (net.Conn, error) {
109 return net.Dial(netw, addr)
110 },
111 },
112 }
113
114 res, err := httpClient.Get(url)
115 if err != nil {
116 t.Error(err)
117 }
118
119 resp, _ := io.ReadAll(res.Body)
120 assert.Equal(t, "<h1>Hello world</h1>", string(resp))
121}
122
123func TestLoadHTMLGlobTestMode(t *testing.T) {
124 ts := setupHTMLFiles(

Callers

nothing calls this directly

Calls 7

CloseMethod · 0.80
DefaultFunction · 0.70
GETMethod · 0.65
StringMethod · 0.65
ErrorMethod · 0.45
HandlerMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected