-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrip_test.go
51 lines (44 loc) · 957 Bytes
/
rip_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
package rip
import (
"testing"
"net/http"
"net/http/httptest"
)
type fooResource struct {
}
type fooSubResource struct {
}
type bazResource struct {
}
func TestMain(t *testing.T) {
root := New().
Add("foos", fooResource{}).
Add("bazes", bazResource{})
//root.Get("foos").
// Add("bars", fooSubResource{})
type MainRequestTest struct {
method string
url string
success bool
}
var mainRequestTests = []MainRequestTest{
{GET, "/foos", true},
{GET, "/foos/123", true},
{POST, "/foos", true},
{GET, "/notthere", false},
{GET, "/foos/none", false},
{DELETE, "/foos/123", true},
{GET, "/foos/bars", true},
{GET, "/foos/123/bazes", true},
{POST, "/foos/123/bazes", true},
}
for _, d := range mainRequestTests {
req, err := http.NewRequest(d.method, d.url, nil)
if err != nil {
t.Fatal(err)
}
rsp := httptest.NewRecorder()
root.ServeHTTP(rsp, req)
t.Logf("%d - %s", rsp.Code, rsp.Body.String())
}
}