aboutsummaryrefslogtreecommitdiff
path: root/tests/sleepy_test.go
blob: 655d0a6329a76ad1c1fe4e0c896eb83794a309c0 (plain)
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
package main

import (
	"github.com/dougblack/sleepy"
	"net/url"
    "net/http"
    "testing"
    "io/ioutil"
)

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 TestBasicGet(t *testing.T) {

	item := new(Item)

	var api = sleepy.NewAPI()
	api.AddResource(item, "/items", "/bar", "/baz")
	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.")
    }
}
bgstack15