Permalink
Browse files

Added HelloWorld test

  • Loading branch information...
1 parent 254e6ee commit 54be825a6924d318fe0939878a51dc1d6e206543 @paulbellamy committed May 24, 2011
Showing with 36 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +35 −1 mango_test.go
View
@@ -4,3 +4,4 @@
*.8
*.sw?
_obj
+_test*
View
@@ -1 +1,35 @@
-package main
+package mango
+
+import (
+ "http"
+ "io/ioutil"
+ "testing"
+ "./mango"
+)
+
+func helloWorld(env mango.Env) (mango.Status, mango.Headers, mango.Body) {
+ return 200, make(map[string]string), mango.Body("Hello World!")
+}
+
+func TestHelloWorld(t *testing.T) {
+ // Start up the server
+ stack := new(mango.Stack)
+ stack.Address = "localhost:3000"
+ go stack.Run(helloWorld)
+
+ // Request against it
+ client := new(http.Client)
+ response, _, err := client.Get("http://localhost:3000/")
+ 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:", body, "to equal: \"Hello World!\"")
+ }
+}

0 comments on commit 54be825

Please sign in to comment.