Welcome to mirror list, hosted at ThFree Co, Russian Federation.

encodings_test.go « acceptance « test - gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 18f2c492f93c9ad73fdca8171392a7c603fadcd9 (plain)
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) {
	RunPagesProcess(t,
		withListeners([]ListenSpec{httpListener}),
	)

	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) {
	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",
		},
	}

	RunPagesProcess(t,
		withListeners([]ListenSpec{httpListener}),
	)

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			header := http.Header{
				"Accept-Encoding": []string{tt.encoding},
			}
			rsp, err := GetPageFromListenerWithHeaders(t, httpListener, "group.gitlab-example.com", "index.html", header)
			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"))
		})
	}
}