Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 53 lines (40 sloc) 1.178 kB
07c74e6 @paulbellamy Added mango.Redirect to make redirects a bit easier
authored
1 package mango
2
3 import (
6d064af @paulbellamy Updating to compile on weekly.2012-03-04
authored
4 "net/http"
07c74e6 @paulbellamy Added mango.Redirect to make redirects a bit easier
authored
5 "testing"
6 )
7
8 func redirectTestServer(env Env) (Status, Headers, Body) {
9 return Redirect(302, "/somewhere")
10 }
11
12 func TestRedirect(t *testing.T) {
13 // Compile the stack
14 redirectApp := new(Stack).Compile(redirectTestServer)
15
16 // Request against it
17 request, err := http.NewRequest("GET", "http://localhost:3000/", nil)
18 status, headers, body := redirectApp(Env{"mango.request": &Request{request}})
19
20 if err != nil {
21 t.Error(err)
22 }
23
24 if status != 302 {
25 t.Error("Expected status to equal 302, got:", status)
26 }
27
28 expected := "/somewhere"
29 if headers["Location"][0] != expected {
30 t.Error("Expected Location header to be: \"", expected, "\" got: \"", headers["Location"][0], "\"")
31 }
32
33 expectedBody := Body("")
34 if body != expectedBody {
35 t.Error("Expected body to be: \"", expected, "\" got: \"", body, "\"")
36 }
37 }
38
39 func BenchmarkRedirect(b *testing.B) {
40 b.StopTimer()
41
42 redirectApp := new(Stack).Compile(redirectTestServer)
43
44 // Request against it
45 request, _ := http.NewRequest("GET", "http://localhost:3000/", nil)
46
47 b.StartTimer()
48 for i := 0; i < b.N; i++ {
49 redirectApp(Env{"mango.request": &Request{request}})
50 }
51 b.StopTimer()
52 }
Something went wrong with that request. Please try again.