Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d251b34

Browse files
committedNov 3, 2015
compliant writableGW: updated tests with expected data
License: MIT Signed-off-by: Henry <cryptix@riseup.net>
1 parent 385749e commit d251b34

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed
 

‎core/corehttp/gateway_handler_test.go

+18-15
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"github.com/ipfs/go-ipfs/blocks/key"
1212
"github.com/ipfs/go-ipfs/core"
1313
"github.com/ipfs/go-ipfs/core/mock"
14-
15-
"github.com/cheekybits/is"
1614
)
1715

1816
type testSession struct {
@@ -26,19 +24,16 @@ func newTestSession(t *testing.T, writable bool) *testSession {
2624
if err != nil {
2725
t.Fatalf("coremock.NewMockNode() failed: %s", err)
2826
}
29-
3027
tk, err := assets.SeedInitDocs(mn)
3128
if err != nil {
3229
t.Fatalf("assets.SeedInitDocs() failed: %s", err)
3330
}
34-
3531
gwh, err := newGatewayHandler(mn, GatewayConfig{Writable: writable})
3632
if err != nil {
3733
t.Fatalf("newGatewayHandler() failed: %s", err)
3834
}
3935
serveMux := http.NewServeMux()
4036
serveMux.Handle("/", gwh)
41-
4237
return &testSession{
4338
key: tk,
4439
mn: mn,
@@ -48,18 +43,26 @@ func newTestSession(t *testing.T, writable bool) *testSession {
4843

4944
func TestGateway_GET(t *testing.T) {
5045
ts := newTestSession(t, false)
51-
is := is.New(t)
5246
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+
}
5554
}
5655

5756
func TestGateway_POSTwDisabled(t *testing.T) {
5857
ts := newTestSession(t, false)
59-
is := is.New(t)
6058
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+
}
6366
}
6467

6568
func TestGateway_Meaningful(t *testing.T) {
@@ -74,10 +77,11 @@ func TestGateway_Meaningful(t *testing.T) {
7477
// whose name (in this case: hash) is determined by the gateway and receives the response:
7578
{"POST", "/ipfs", http.StatusCreated, []byte("Hello World"), "/ipfs/QmUXTtySmd7LD4p6RG6rZW6RuUuPZXTtNMmRQ6DSQo3aMw"},
7679

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"},
7982

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"},
8185
}
8286
for i, tcase := range tcases {
8387
req, err := http.NewRequest(tcase.Method, tcase.URL, bytes.NewReader(tcase.Body))
@@ -94,7 +98,6 @@ func TestGateway_Meaningful(t *testing.T) {
9498
t.Logf("response body: %q", b)
9599
}
96100
}
97-
98101
if got := resp.Header.Get("Location"); got != tcase.Location {
99102
t.Errorf("case %d: location mismatch: want: %s. got: %s", i, tcase.Location, got)
100103
}

0 commit comments

Comments
 (0)
Please sign in to comment.