Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

60 lines (46 sloc) 1.117 kB
package mango
import (
"http/httptest"
"io/ioutil"
"testing"
"fmt"
"http"
"runtime"
)
func helloWorld(env Env) (Status, Headers, Body) {
return 200, Headers{}, Body("Hello World!")
}
func init() {
runtime.GOMAXPROCS(4)
fmt.Println("Testing Mango Version:", VersionString())
}
func TestHelloWorld(t *testing.T) {
stack := new(Stack)
testServer := httptest.NewServer(stack.HandlerFunc(helloWorld))
defer testServer.Close()
var client = http.Client{}
// Request against it
response, err := client.Get(testServer.URL)
if err != nil {
t.Error(err)
}
if response.StatusCode != 200 {
t.Error("Expected status to equal 200, got:", response.StatusCode)
}
body, _ := ioutil.ReadAll(response.Body)
if string(body) != "Hello World!" {
t.Error("Expected body:", string(body), "to equal: \"Hello World!\"")
}
}
func BenchmarkHelloWorld(b *testing.B) {
b.StopTimer()
stack := new(Stack)
testServer := httptest.NewServer(stack.HandlerFunc(helloWorld))
defer testServer.Close()
address := testServer.URL
b.StartTimer()
for i := 0; i < b.N; i++ {
http.Get(address)
}
b.StopTimer()
}
Jump to Line
Something went wrong with that request. Please try again.