Skip to content
This repository
Newer
Older
100644 52 lines (40 sloc) 1.301 kb
85921571 »
2011-06-11 moving show_errors_test into seperate file
1 package mango
2
3 import (
6d064afb »
2012-03-10 Updating to compile on weekly.2012-03-04
4 "net/http"
85921571 »
2011-06-11 moving show_errors_test into seperate file
5 "testing"
6 )
7
8 func showErrorsTestServer(env Env) (Status, Headers, Body) {
9 panic("foo!")
10 return 200, Headers{}, Body("Hello World!")
11 }
12
13 func TestShowErrors(t *testing.T) {
14 // Compile the stack
15 showErrorsStack := new(Stack)
3c286b22 »
2011-08-20 Updating to new templates package for weekly.2011-08-17
16 showErrorsStack.Middleware(ShowErrors("<html><body>{{.Error|html}}</body></html>"))
85921571 »
2011-06-11 moving show_errors_test into seperate file
17 showErrorsApp := showErrorsStack.Compile(showErrorsTestServer)
18
19 // Request against it
20 request, err := http.NewRequest("GET", "http://localhost:3000/", nil)
21 status, _, body := showErrorsApp(Env{"mango.request": &Request{request}})
22
23 if err != nil {
24 t.Error(err)
25 }
26
27 if status != 500 {
28 t.Error("Expected status to equal 500, got:", status)
29 }
30
31 expected := "<html><body>foo!</body></html>"
32 if string(body) != expected {
33 t.Error("Expected response body to equal: \"", expected, "\" got: \"", string(body), "\"")
34 }
35 }
009def6b »
2011-06-12 Adding in benchmarks using http/httptest
36
37 func BenchmarkShowErrors(b *testing.B) {
38 b.StopTimer()
39
ebf26101 »
2011-06-12 Removing http/httptest from module tests because it is *SLOW*
40 showErrorsStack := new(Stack)
41 showErrorsStack.Middleware(ShowErrors("<html><body>{Error|html}</body></html>"))
42 showErrorsApp := showErrorsStack.Compile(showErrorsTestServer)
43
44 request, _ := http.NewRequest("GET", "http://localhost:3000/", nil)
009def6b »
2011-06-12 Adding in benchmarks using http/httptest
45
46 b.StartTimer()
47 for i := 0; i < b.N; i++ {
ebf26101 »
2011-06-12 Removing http/httptest from module tests because it is *SLOW*
48 showErrorsApp(Env{"mango.request": &Request{request}})
009def6b »
2011-06-12 Adding in benchmarks using http/httptest
49 }
50 b.StopTimer()
51 }
Something went wrong with that request. Please try again.