@@ -11,8 +11,6 @@ import (
11
11
"github.com/ipfs/go-ipfs/blocks/key"
12
12
"github.com/ipfs/go-ipfs/core"
13
13
"github.com/ipfs/go-ipfs/core/mock"
14
-
15
- "github.com/cheekybits/is"
16
14
)
17
15
18
16
type testSession struct {
@@ -26,19 +24,16 @@ func newTestSession(t *testing.T, writable bool) *testSession {
26
24
if err != nil {
27
25
t .Fatalf ("coremock.NewMockNode() failed: %s" , err )
28
26
}
29
-
30
27
tk , err := assets .SeedInitDocs (mn )
31
28
if err != nil {
32
29
t .Fatalf ("assets.SeedInitDocs() failed: %s" , err )
33
30
}
34
-
35
31
gwh , err := newGatewayHandler (mn , GatewayConfig {Writable : writable })
36
32
if err != nil {
37
33
t .Fatalf ("newGatewayHandler() failed: %s" , err )
38
34
}
39
35
serveMux := http .NewServeMux ()
40
36
serveMux .Handle ("/" , gwh )
41
-
42
37
return & testSession {
43
38
key : tk ,
44
39
mn : mn ,
@@ -48,18 +43,26 @@ func newTestSession(t *testing.T, writable bool) *testSession {
48
43
49
44
func TestGateway_GET (t * testing.T ) {
50
45
ts := newTestSession (t , false )
51
- is := is .New (t )
52
46
resp , err := ts .hc .Get ("/ipfs/" + ts .key .B58String () + "/about" )
53
- is .Nil (err )
54
- is .Equal (resp .StatusCode , http .StatusOK )
47
+ if err != nil {
48
+ t .Fatalf ("http GET failed with err: %s" , err )
49
+ }
50
+ got , want := resp .StatusCode , http .StatusOK
51
+ if got != want {
52
+ t .Errorf ("http GET returned wrong status code. wanted %d got %d %s" , want , got , resp .Status )
53
+ }
55
54
}
56
55
57
56
func TestGateway_POSTwDisabled (t * testing.T ) {
58
57
ts := newTestSession (t , false )
59
- is := is .New (t )
60
58
resp , err := ts .hc .Post ("/ipfs/" + ts .key .B58String ()+ "/new" , "test" , nil )
61
- is .Nil (err )
62
- is .Equal (resp .StatusCode , http .StatusMethodNotAllowed )
59
+ if err != nil {
60
+ t .Fatalf ("http POST failed with err: %s" , err )
61
+ }
62
+ got , want := resp .StatusCode , http .StatusMethodNotAllowed
63
+ if got != want {
64
+ t .Errorf ("http POST returned wrong status code. wanted %d got %d %s" , want , got , resp .Status )
65
+ }
63
66
}
64
67
65
68
func TestGateway_Meaningful (t * testing.T ) {
@@ -74,10 +77,11 @@ func TestGateway_Meaningful(t *testing.T) {
74
77
// whose name (in this case: hash) is determined by the gateway and receives the response:
75
78
{"POST" , "/ipfs" , http .StatusCreated , []byte ("Hello World" ), "/ipfs/QmUXTtySmd7LD4p6RG6rZW6RuUuPZXTtNMmRQ6DSQo3aMw" },
76
79
77
- // TODO(cryptix): figure out how to specify the file/link name
78
- {"POST" , "/ipfs/" + ts .key .B58String (), http .StatusCreated , []byte ("Hello World" ), "/ipfs/QmUXTtySmd7LD4p6RG6rZW6RuUuPZXTtNMmRQ6DSQo3aMw " },
80
+ // creates or overwrites newFile on key
81
+ {"POST" , "/ipfs/" + ts .key .B58String () + "/newFile" , http .StatusCreated , []byte ("Hello World" ), "/ipfs/QmSN6DYGcb98NqAxN3FW8nJdcJquGFLu64fPVcfbFVdHJc " },
79
82
80
- {"DELETE" , "/ipfs/" + ts .key .B58String () + "/about" , http .StatusCreated , []byte {}, "/ipfs/test" },
83
+ // removes the link to about from key
84
+ {"DELETE" , "/ipfs/" + ts .key .B58String () + "/about" , http .StatusCreated , []byte {}, "/ipfs/QmNjJ3naRhHCn14E895R1xtGmDgKQb8vnVvQar6RrnraC1" },
81
85
}
82
86
for i , tcase := range tcases {
83
87
req , err := http .NewRequest (tcase .Method , tcase .URL , bytes .NewReader (tcase .Body ))
@@ -94,7 +98,6 @@ func TestGateway_Meaningful(t *testing.T) {
94
98
t .Logf ("response body: %q" , b )
95
99
}
96
100
}
97
-
98
101
if got := resp .Header .Get ("Location" ); got != tcase .Location {
99
102
t .Errorf ("case %d: location mismatch: want: %s. got: %s" , i , tcase .Location , got )
100
103
}
0 commit comments