mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 09:34:33 +08:00
add pusher test
This commit is contained in:
parent
7d58ced738
commit
77d2d3576b
@ -8,6 +8,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -69,6 +70,42 @@ func TestRunTLS(t *testing.T) {
|
|||||||
testRequest(t, "https://localhost:8443/example")
|
testRequest(t, "https://localhost:8443/example")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPusher(t *testing.T) {
|
||||||
|
var html = template.Must(template.New("https").Parse(`
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Https Test</title>
|
||||||
|
<script src="/assets/app.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1 style="color:red;">Welcome, Ginner!</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`))
|
||||||
|
|
||||||
|
router := New()
|
||||||
|
router.Static("./assets", "./assets")
|
||||||
|
router.SetHTMLTemplate(html)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
router.GET("/pusher", func(c *Context) {
|
||||||
|
if pusher := c.Writer.Pusher(); pusher != nil {
|
||||||
|
pusher.Push("/assets/app.js", nil)
|
||||||
|
}
|
||||||
|
c.String(http.StatusOK, "it worked")
|
||||||
|
})
|
||||||
|
|
||||||
|
assert.NoError(t, router.RunTLS(":8449", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))
|
||||||
|
}()
|
||||||
|
|
||||||
|
// have to wait for the goroutine to start and run the server
|
||||||
|
// otherwise the main thread will complete
|
||||||
|
time.Sleep(5 * time.Millisecond)
|
||||||
|
|
||||||
|
assert.Error(t, router.RunTLS(":8449", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))
|
||||||
|
testRequest(t, "https://localhost:8449/pusher")
|
||||||
|
}
|
||||||
|
|
||||||
func TestRunEmptyWithEnv(t *testing.T) {
|
func TestRunEmptyWithEnv(t *testing.T) {
|
||||||
os.Setenv("PORT", "3123")
|
os.Setenv("PORT", "3123")
|
||||||
router := New()
|
router := New()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user