forked from ipfs/go-ipfs-cmds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_test.go
47 lines (42 loc) · 950 Bytes
/
parse_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
package http
import (
"net/http"
"testing"
cmds "github.com/ipfs/go-ipfs-cmds"
)
func TestParse(t *testing.T) {
root := &cmds.Command{
Subcommands: map[string]*cmds.Command{
"block": &cmds.Command{
Subcommands: map[string]*cmds.Command{
"put": &cmds.Command{
Run: func(req cmds.Request, resp cmds.ResponseEmitter) {
defer resp.Close()
resp.Emit("done")
},
},
},
},
},
}
r, err := http.NewRequest("GET", "/api/v0/block/put", nil)
if err != nil {
t.Fatal(err)
}
req, err := Parse(r, root)
if err != nil {
t.Fatal(err)
}
pth := req.Path()
if pth[0] != "block" || pth[1] != "put" || len(pth) != 2 {
t.Errorf("incorrect path %v, expected %v", pth, []string{"block", "put"})
}
r, err = http.NewRequest("GET", "/api/v0/block/bla", nil)
if err != nil {
t.Fatal(err)
}
req, err = Parse(r, root)
if err != ErrNotFound {
t.Errorf("expected ErrNotFound, got: %v", err)
}
}