-
Notifications
You must be signed in to change notification settings - Fork 0
/
htmx_test.go
42 lines (32 loc) · 951 Bytes
/
htmx_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package htmxgo_test
import (
"bytes"
"net/http"
"net/http/httptest"
"testing"
htmxgo "github.com/ninedraft/htmx-go"
"github.com/stretchr/testify/assert"
)
func TestServeHTTP(t *testing.T) {
t.Log(
"ServeHTTP must write htmx library to response",
)
encodings := []string{
"", "deflate", "gzip", "br",
}
for _, encoding := range encodings {
encoding := encoding
t.Run(encoding, func(t *testing.T) {
t.Parallel()
req := httptest.NewRequest("GET", "/", nil)
req.Header.Set("Accept-Encoding", encoding)
got := httptest.NewRecorder()
got.Body = &bytes.Buffer{}
htmxgo.ServeHTTP(got, req)
assert.Equal(t, http.StatusOK, got.Code, "code mismatch")
assert.Equal(t, "application/javascript", got.Header().Get("Content-Type"), "content-type mismatch")
assert.Contains(t, got.Header().Get("Content-Encoding"), encoding, "content-encoding mismatch")
assert.NotEmpty(t, got.Body.Bytes(), "body")
})
}
}