Skip to content

Commit 54be825

Browse files
committed
Added HelloWorld test
1 parent 254e6ee commit 54be825

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
*.8
55
*.sw?
66
_obj
7+
_test*

mango_test.go

+35-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
1-
package main
1+
package mango
2+
3+
import (
4+
"http"
5+
"io/ioutil"
6+
"testing"
7+
"./mango"
8+
)
9+
10+
func helloWorld(env mango.Env) (mango.Status, mango.Headers, mango.Body) {
11+
return 200, make(map[string]string), mango.Body("Hello World!")
12+
}
13+
14+
func TestHelloWorld(t *testing.T) {
15+
// Start up the server
16+
stack := new(mango.Stack)
17+
stack.Address = "localhost:3000"
18+
go stack.Run(helloWorld)
19+
20+
// Request against it
21+
client := new(http.Client)
22+
response, _, err := client.Get("http://localhost:3000/")
23+
if err != nil {
24+
t.Error(err)
25+
}
26+
27+
if response.StatusCode != 200 {
28+
t.Error("Expected status to equal 200, got:", response.StatusCode)
29+
}
30+
31+
body, _ := ioutil.ReadAll(response.Body)
32+
if string(body) != "Hello World!" {
33+
t.Error("Expected body:", body, "to equal: \"Hello World!\"")
34+
}
35+
}

0 commit comments

Comments
 (0)