Skip to content

Commit

Permalink
core/corehttp/gateway_test: Externalize test to use shell/unixfs' Add…
Browse files Browse the repository at this point in the history
…FromReader

We don't want to create core -> shell -> core import cycles, so we
need to move this test out of the corehttp package before we can
safely use AddFromReader.  Moving the tests into their own _test
package means we need to explicitly import the corehttp package, which
in turn means we need to *export* makeHandler (now MakeHandler).

Pulling in the shell code also increases the surface area for bugs
breaking the test, which was previously only testing the low-level
code.  Not that I expect many bugs in shell/unixfs's AddFromReader,
but it's still nice to rule out a whole API when tracking down issues
;).

Personally, it seems simpler to stick to keep using
importer.BuildDagFromReader directly from this test, but Juan prefers
the external approach taken by this commit [1].

[1]: #1136 (comment)
  • Loading branch information
wking committed May 4, 2015
1 parent 93df40d commit c8f7b39
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
6 changes: 3 additions & 3 deletions core/corehttp/corehttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ var log = eventlog.Logger("core/server")
// initially passed in if not.
type ServeOption func(*core.IpfsNode, *http.ServeMux) (*http.ServeMux, error)

// makeHandler turns a list of ServeOptions into a http.Handler that implements
// MakeHandler turns a list of ServeOptions into a http.Handler that implements
// all of the given options, in order.
func makeHandler(n *core.IpfsNode, options ...ServeOption) (http.Handler, error) {
func MakeHandler(n *core.IpfsNode, options ...ServeOption) (http.Handler, error) {
topMux := http.NewServeMux()
mux := topMux
for _, option := range options {
Expand All @@ -49,7 +49,7 @@ func ListenAndServe(n *core.IpfsNode, listeningMultiAddr string, options ...Serv
if err != nil {
return err
}
handler, err := makeHandler(n, options...)
handler, err := MakeHandler(n, options...)
if err != nil {
return err
}
Expand Down
18 changes: 7 additions & 11 deletions core/corehttp/gateway_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package corehttp
package corehttp_test

import (
"errors"
Expand All @@ -10,13 +10,13 @@ import (

context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
core "github.com/ipfs/go-ipfs/core"
importer "github.com/ipfs/go-ipfs/importer"
chunk "github.com/ipfs/go-ipfs/importer/chunk"
corehttp "github.com/ipfs/go-ipfs/core/corehttp"
namesys "github.com/ipfs/go-ipfs/namesys"
ci "github.com/ipfs/go-ipfs/p2p/crypto"
path "github.com/ipfs/go-ipfs/path"
repo "github.com/ipfs/go-ipfs/repo"
config "github.com/ipfs/go-ipfs/repo/config"
unixfs "github.com/ipfs/go-ipfs/shell/unixfs"
testutil "github.com/ipfs/go-ipfs/util/testutil"
)

Expand Down Expand Up @@ -61,11 +61,7 @@ func TestGatewayGet(t *testing.T) {
t.Skip("not sure whats going on here")
ns := mockNamesys{}
n := newNodeWithMockNamesys(t, ns)
dagNode, err := importer.BuildDagFromReader(
strings.NewReader("fnord"),
n.DAG,
n.Pinning.GetManual(),
chunk.DefaultSplitter)
dagNode, err := unixfs.AddFromReader(n, strings.NewReader("fnord"))
if err != nil {
t.Fatal(err)
}
Expand All @@ -76,9 +72,9 @@ func TestGatewayGet(t *testing.T) {
k := key.String()
ns["example.com"] = path.FromString("/ipfs/" + k)

h, err := makeHandler(n,
IPNSHostnameOption(),
GatewayOption(false),
h, err := corehttp.MakeHandler(n,
corehttp.IPNSHostnameOption(),
corehttp.GatewayOption(false),
)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit c8f7b39

Please sign in to comment.