Permalink
Browse files

Removing http/httptest from module tests because it is *SLOW*

  • Loading branch information...
1 parent 009def6 commit ebf26101b633c2d029044a4b0f39beafdccc458d @paulbellamy committed Jun 12, 2011
Showing with 37 additions and 44 deletions.
  1. +0 −2 TODO
  2. +6 −7 jsonp_test.go
  3. +7 −7 logger_test.go
  4. +6 −7 routing_test.go
  5. +6 −7 sessions_test.go
  6. +6 −7 show_errors_test.go
  7. +6 −7 static_test.go
View
@@ -1,9 +1,7 @@
* Better cookie handler
* Domain/Expiry
* Clean up/Flesh out tests more
- * Use http/httptest for full-stack testing
* Better benchmarking
- * Per-module
* End-to-End
POTENTIAL MIDDLEWARE
View
@@ -2,7 +2,6 @@ package mango
import (
"http"
- "http/httptest"
"testing"
"runtime"
)
@@ -150,15 +149,15 @@ func TestJSONPInvalidCallback(t *testing.T) {
func BenchmarkJSONP(b *testing.B) {
b.StopTimer()
- stack := new(Stack)
- stack.Middleware(JSONP)
- testServer := httptest.NewServer(stack.HandlerFunc(jsonServer))
- defer testServer.Close()
- address := testServer.URL
+ jsonpStack := new(Stack)
+ jsonpStack.Middleware(JSONP)
+ jsonpApp := jsonpStack.Compile(jsonServer)
+
+ request, _ := http.NewRequest("GET", "http://localhost:3000/?callback=parseResponse", nil)
b.StartTimer()
for i := 0; i < b.N; i++ {
- http.Get(address)
+ jsonpApp(Env{"mango.request": &Request{request}})
}
b.StopTimer()
}
View
@@ -3,7 +3,6 @@ package mango
import (
"bytes"
"http"
- "http/httptest"
"log"
"testing"
"runtime"
@@ -48,16 +47,17 @@ func TestLogger(t *testing.T) {
func BenchmarkLogger(b *testing.B) {
b.StopTimer()
- stack := new(Stack)
+ loggerStack := new(Stack)
custom_logger := log.New(loggerBuffer, "prefixed:", 0)
- stack.Middleware(Logger(custom_logger))
- testServer := httptest.NewServer(stack.HandlerFunc(loggerTestServer))
- defer testServer.Close()
- address := testServer.URL
+ loggerStack.Middleware(Logger(custom_logger))
+ loggerApp := loggerStack.Compile(loggerTestServer)
+
+ // Request against it
+ request, _ := http.NewRequest("GET", "http://localhost:3000/", nil)
b.StartTimer()
for i := 0; i < b.N; i++ {
- http.Get(address)
+ loggerApp(Env{"mango.request": &Request{request}})
}
b.StopTimer()
}
View
@@ -2,7 +2,6 @@ package mango
import (
"http"
- "http/httptest"
"testing"
"runtime"
)
@@ -97,18 +96,18 @@ func TestRoutingFailure(t *testing.T) {
func BenchmarkRouting(b *testing.B) {
b.StopTimer()
- stack := new(Stack)
+ routingStack := new(Stack)
routes := make(map[string]App)
routes["/a"] = routingATestServer
routes["/b"] = routingBTestServer
- stack.Middleware(Routing(routes))
- testServer := httptest.NewServer(stack.HandlerFunc(routingTestServer))
- defer testServer.Close()
- address := testServer.URL
+ routingStack.Middleware(Routing(routes))
+ routingApp := routingStack.Compile(routingTestServer)
+
+ request, _ := http.NewRequest("GET", "http://localhost:3000/a", nil)
b.StartTimer()
for i := 0; i < b.N; i++ {
- http.Get(address)
+ routingApp(Env{"mango.request": &Request{request}})
}
b.StopTimer()
}
View
@@ -2,7 +2,6 @@ package mango
import (
"http"
- "http/httptest"
"runtime"
"testing"
)
@@ -45,15 +44,15 @@ func TestSessions(t *testing.T) {
func BenchmarkSessions(b *testing.B) {
b.StopTimer()
- stack := new(Stack)
- stack.Middleware(Sessions("my_secret", "my_key", ".my.domain.com"))
- testServer := httptest.NewServer(stack.HandlerFunc(sessionsTestServer))
- defer testServer.Close()
- address := testServer.URL
+ sessionsStack := new(Stack)
+ sessionsStack.Middleware(Sessions("my_secret", "my_key", ".my.domain.com"))
+ sessionsApp := sessionsStack.Compile(sessionsTestServer)
+
+ request, _ := http.NewRequest("GET", "http://localhost:3000/", nil)
b.StartTimer()
for i := 0; i < b.N; i++ {
- http.Get(address)
+ sessionsApp(Env{"mango.request": &Request{request}})
}
b.StopTimer()
}
View
@@ -2,7 +2,6 @@ package mango
import (
"http"
- "http/httptest"
"testing"
"runtime"
)
@@ -43,15 +42,15 @@ func TestShowErrors(t *testing.T) {
func BenchmarkShowErrors(b *testing.B) {
b.StopTimer()
- stack := new(Stack)
- stack.Middleware(ShowErrors("<html><body>{Error|html}</body></html>"))
- testServer := httptest.NewServer(stack.HandlerFunc(showErrorsTestServer))
- defer testServer.Close()
- address := testServer.URL
+ showErrorsStack := new(Stack)
+ showErrorsStack.Middleware(ShowErrors("<html><body>{Error|html}</body></html>"))
+ showErrorsApp := showErrorsStack.Compile(showErrorsTestServer)
+
+ request, _ := http.NewRequest("GET", "http://localhost:3000/", nil)
b.StartTimer()
for i := 0; i < b.N; i++ {
- http.Get(address)
+ showErrorsApp(Env{"mango.request": &Request{request}})
}
b.StopTimer()
}
View
@@ -2,7 +2,6 @@ package mango
import (
"http"
- "http/httptest"
"testing"
"runtime"
)
@@ -66,15 +65,15 @@ func TestStaticFail(t *testing.T) {
func BenchmarkStatic(b *testing.B) {
b.StopTimer()
- stack := new(Stack)
- stack.Middleware(Static("./static"))
- testServer := httptest.NewServer(stack.HandlerFunc(staticTestServer))
- defer testServer.Close()
- address := testServer.URL
+ staticStack := new(Stack)
+ staticStack.Middleware(Static("./static"))
+ staticApp := staticStack.Compile(staticTestServer)
+
+ request, _ := http.NewRequest("GET", "http://localhost:3000/static.html", nil)
b.StartTimer()
for i := 0; i < b.N; i++ {
- http.Get(address)
+ staticApp(Env{"mango.request": &Request{request}})
}
b.StopTimer()
}

0 comments on commit ebf2610

Please sign in to comment.