/
runner_test.go
35 lines (29 loc) · 961 Bytes
/
runner_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
package runner
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRedirect(t *testing.T) {
cases := []struct {
Request string
TLS int
Expect string
}{
{Request: "http://gotify.net/meow", TLS: 443, Expect: "https://gotify.net:443/meow"},
{Request: "http://gotify.net:8080/meow", TLS: 443, Expect: "https://gotify.net:443/meow"},
{Request: "http://gotify.net:8080/meow", TLS: 8443, Expect: "https://gotify.net:8443/meow"},
}
for _, testCase := range cases {
name := fmt.Sprintf("%s -- %d -> %s", testCase.Request, testCase.TLS, testCase.Expect)
t.Run(name, func(t *testing.T) {
req := httptest.NewRequest("GET", testCase.Request, nil)
rec := httptest.NewRecorder()
redirectToHTTPS(fmt.Sprint(testCase.TLS)).ServeHTTP(rec, req)
assert.Equal(t, http.StatusFound, rec.Result().StatusCode)
assert.Equal(t, testCase.Expect, rec.Header().Get("location"))
})
}
}