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
|
package acceptance_test
import (
"io"
"net/http"
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-pages/internal/feature"
"gitlab.com/gitlab-org/gitlab-pages/internal/testhelpers"
)
func TestRewrites(t *testing.T) {
t.Setenv(feature.RedirectsPlaceholders.EnvVariable, "true")
RunPagesProcess(t,
withListeners([]ListenSpec{httpListener}),
)
tests := map[string]struct {
host string
path string
expectedBody string
}{
"rewrite_for_splat_with_replacement": {
host: "group.redirects.gitlab-example.com",
path: "/project-redirects/arrakis/visitors-guide.html",
expectedBody: "Welcome to Dune!",
},
"splat_with_no_replacement": {
host: "group.redirects.gitlab-example.com",
path: "/project-redirects/spa/client/side/route",
expectedBody: "This is an SPA",
},
"existing_content_takes_precedence_over_rewrite_rules": {
host: "group.redirects.gitlab-example.com",
path: "/project-redirects/spa/existing-file.html",
expectedBody: "This is an existing file",
},
"rewrite_using_placeholders": {
host: "group.redirects.gitlab-example.com",
path: "/project-redirects/blog/2021/08/12",
expectedBody: "Rewrites are pretty neat!",
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
rsp, err := GetPageFromListener(t, httpListener, tt.host, tt.path)
require.NoError(t, err)
testhelpers.Close(t, rsp.Body)
body, err := io.ReadAll(rsp.Body)
require.NoError(t, err)
require.Contains(t, string(body), tt.expectedBody)
require.Equal(t, http.StatusOK, rsp.StatusCode)
})
}
}
|