forked from web-platform-tests/wpt.fyi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interop_handler_test.go
65 lines (54 loc) · 1.8 KB
/
interop_handler_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// +build small
package webapp
// Copyright 2022 The WPT Dashboard Project. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/gorilla/mux"
"github.com/stretchr/testify/assert"
)
func TestInteropHandler_redirect(t *testing.T) {
// 1999 is an invalid interop year and should be redirected.
req := httptest.NewRequest("GET", "/interop-1999?embedded", strings.NewReader("{}"))
req = mux.SetURLVars(req, map[string]string{
"name": "interop",
"year": "1999",
"embedded": "true",
})
w := httptest.NewRecorder()
interopHandler(w, req)
resp := w.Result()
assert.Equal(t, resp.StatusCode, http.StatusTemporaryRedirect)
loc, err := resp.Location()
assert.Nil(t, err)
// Check if embedded param is maintained after redirect.
assert.NotEqual(t, loc.Path, "interop-2022?embedded")
}
func TestInteropHandler_compatRedirect(t *testing.T) {
// "/compat20XX" paths should redirect to the interop version of the given year.
req := httptest.NewRequest("GET", "/compat2021", strings.NewReader("{}"))
req = mux.SetURLVars(req, map[string]string{
"name": "compat",
"year": "2021",
})
w := httptest.NewRecorder()
interopHandler(w, req)
resp := w.Result()
assert.Equal(t, resp.StatusCode, http.StatusTemporaryRedirect)
}
func TestInteropHandler_success(t *testing.T) {
// A typical "/interop-20XX" path with a valid year should not redirect.
req := httptest.NewRequest("GET", "/interop-"+defaultRedirectYear, strings.NewReader("{}"))
req = mux.SetURLVars(req, map[string]string{
"name": "interop",
"year": defaultRedirectYear,
})
w := httptest.NewRecorder()
interopHandler(w, req)
resp := w.Result()
assert.Equal(t, resp.StatusCode, http.StatusOK)
}