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

Function TestPusher

gin_integration_test.go:173–208  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

171}
172
173func TestPusher(t *testing.T) {
174 html := template.Must(template.New("https").Parse(`
175<html>
176<head>
177 <title>Https Test</title>
178 <script src="/assets/app.js"></script>
179</head>
180<body>
181 <h1 style="color:red;">Welcome, Ginner!</h1>
182</body>
183</html>
184`))
185
186 router := New()
187 router.Static("./assets", "./assets")
188 router.SetHTMLTemplate(html)
189
190 go func() {
191 router.GET("/pusher", func(c *Context) {
192 if pusher := c.Writer.Pusher(); pusher != nil {
193 err := pusher.Push("/assets/app.js", nil)
194 assert.NoError(t, err)
195 }
196 c.String(http.StatusOK, "it worked")
197 })
198
199 assert.NoError(t, router.RunTLS(":8449", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))
200 }()
201
202 // have to wait for the goroutine to start and run the server
203 // otherwise the main thread will complete
204 time.Sleep(5 * time.Millisecond)
205
206 require.Error(t, router.RunTLS(":8449", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))
207 testRequest(t, "https://localhost:8449/pusher")
208}
209
210func TestRunEmptyWithEnv(t *testing.T) {
211 os.Setenv("PORT", "3123")

Callers

nothing calls this directly

Calls 10

NewFunction · 0.85
testRequestFunction · 0.85
SetHTMLTemplateMethod · 0.80
PushMethod · 0.80
RunTLSMethod · 0.80
StaticMethod · 0.65
GETMethod · 0.65
PusherMethod · 0.65
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected