diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | tests/sleepy_test.go (renamed from tests/test.go) | 17 | ||||
-rwxr-xr-x | tests/tests.test | bin | 0 -> 5637808 bytes |
3 files changed, 14 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9ed3b07 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.test diff --git a/tests/test.go b/tests/sleepy_test.go index b316043..655d0a6 100644 --- a/tests/test.go +++ b/tests/sleepy_test.go @@ -3,6 +3,9 @@ package main import ( "github.com/dougblack/sleepy" "net/url" + "net/http" + "testing" + "io/ioutil" ) type Item struct{} @@ -10,16 +13,22 @@ type Item struct{} func (item Item) Get(values url.Values) (int, interface{}) { items := []string{"item1", "item2"} data := map[string][]string{"items": items} - return 200, data } -func main() { +func TestBasicGet(t *testing.T) { item := new(Item) var api = sleepy.NewAPI() api.AddResource(item, "/items", "/bar", "/baz") - api.Start(3000) - + go api.Start(3000) + resp, err := http.Get("http://localhost:3000/items") + if err != nil { + t.Error(err) + } + body, _ := ioutil.ReadAll(resp.Body) + if string(body) != `{"items":["item1","item2"]}` { + t.Error("Not equal.") + } } diff --git a/tests/tests.test b/tests/tests.test Binary files differnew file mode 100755 index 0000000..0defd22 --- /dev/null +++ b/tests/tests.test |