-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
34 lines (28 loc) · 748 Bytes
/
main_test.go
File metadata and controls
34 lines (28 loc) · 748 Bytes
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
package main
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestRedirectHandler(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(Redirect))
defer server.Close()
client := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}}
resp, err := client.Get(server.URL)
if err != nil {
t.Fatal(err)
}
if resp.StatusCode != http.StatusTemporaryRedirect {
t.Fatalf("Received non-307 response: %d\n", resp.StatusCode)
}
url, _ := resp.Location()
if url.Scheme != "https" {
t.Fatalf("Redirect to the wrong HTTPS Scheme: %s\n", url.Scheme)
}
if url.Host != "127.0.0.1:443" {
t.Fatalf("Redirect to the wrong HTTPS Host: %s\n", url.Host)
}
}