-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathmango_test.go
56 lines (44 loc) · 1.06 KB
/
mango_test.go
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
package mango
import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)
func helloWorld(env Env) (Status, Headers, Body) {
return 200, Headers{}, Body("Hello World!")
}
func init() {
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()
}