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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
package acceptance_test
import (
"mime"
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
func TestMIMETypes(t *testing.T) {
skipUnlessEnabled(t)
teardown := RunPagesProcessWithoutWait(t, *pagesBinary, listeners, "")
defer teardown()
require.NoError(t, httpListener.WaitUntilRequestSucceeds(nil))
tests := map[string]struct {
file string
expectedContentType string
}{
"manifest_json": {
file: "file.webmanifest",
expectedContentType: "application/manifest+json",
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
rsp, err := GetPageFromListener(t, httpListener, "group.gitlab-example.com", "project/"+tt.file)
require.NoError(t, err)
defer rsp.Body.Close()
require.Equal(t, http.StatusOK, rsp.StatusCode)
mt, _, err := mime.ParseMediaType(rsp.Header.Get("Content-Type"))
require.NoError(t, err)
require.Equal(t, tt.expectedContentType, mt)
})
}
}
func TestCompressedEncoding(t *testing.T) {
skipUnlessEnabled(t)
tests := []struct {
name string
host string
path string
encoding string
}{
{
"gzip encoding",
"group.gitlab-example.com",
"index.html",
"gzip",
},
{
"brotli encoding",
"group.gitlab-example.com",
"index.html",
"br",
},
}
teardown := RunPagesProcess(t, *pagesBinary, listeners, "")
defer teardown()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rsp, err := GetCompressedPageFromListener(t, httpListener, "group.gitlab-example.com", "index.html", tt.encoding)
require.NoError(t, err)
defer rsp.Body.Close()
require.Equal(t, http.StatusOK, rsp.StatusCode)
require.Equal(t, tt.encoding, rsp.Header.Get("Content-Encoding"))
})
}
}
|