Repository navigation
Expand file tree
/
Copy pathe2e_test.go
More file actions
69 lines (58 loc) · 1.8 KB
/
Copy pathe2e_test.go
File metadata and controls
69 lines (58 loc) · 1.8 KB
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
//go:build e2e
package main
import (
"net/http"
"testing"
"time"
)
var e2eClient = &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
Timeout: 10 * time.Second,
}
// TestE2E_GithubRedirect verifies that github.redirect.name redirects to the
// GitHub repo. Requires real DNS and a live server.
//
// Run with: go test -tags e2e -v ./...
func TestE2E_GithubRedirect(t *testing.T) {
resp, err := e2eClient.Get("http://github.redirect.name/")
if err != nil {
t.Fatalf("request failed: %v", err)
}
resp.Body.Close()
if resp.StatusCode != http.StatusFound {
t.Errorf("status: want 302, got %d", resp.StatusCode)
}
want := "https://github.com/frolic/redirect.name"
if loc := resp.Header.Get("Location"); loc != want {
t.Errorf("Location: want %q, got %q", want, loc)
}
}
// TestE2E_HTTPS verifies that the same redirect is served over HTTPS and that
// the TLS handshake completes (i.e. a certificate has been provisioned).
func TestE2E_HTTPS(t *testing.T) {
resp, err := e2eClient.Get("https://github.redirect.name/")
if err != nil {
t.Fatalf("HTTPS request failed (cert may not be provisioned): %v", err)
}
resp.Body.Close()
if resp.StatusCode != http.StatusFound {
t.Errorf("status: want 302, got %d", resp.StatusCode)
}
want := "https://github.com/frolic/redirect.name"
if loc := resp.Header.Get("Location"); loc != want {
t.Errorf("Location: want %q, got %q", want, loc)
}
}
// TestE2E_Healthz verifies the healthz endpoint on the live server.
func TestE2E_Healthz(t *testing.T) {
resp, err := e2eClient.Get("https://github.redirect.name/healthz")
if err != nil {
t.Fatalf("request failed: %v", err)
}
resp.Body.Close()
if resp.StatusCode != http.StatusOK {
t.Errorf("healthz: want 200, got %d", resp.StatusCode)
}
}