Skip to content
This repository was archived by the owner on Jun 19, 2023. It is now read-only.

feat!: use path.Path instead of string in routing API #104

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package iface

import (
"context"

path "github.com/ipfs/interface-go-ipfs-core/path"
)

// RoutingAPI specifies the interface to the routing layer.
type RoutingAPI interface {
// Get retrieves the best value for a given key
Get(context.Context, string) ([]byte, error)
Get(context.Context, path.Path) ([]byte, error)

// Put sets a value for a given key
Put(ctx context.Context, key string, value []byte) error
Put(context.Context, path.Path, []byte) error
}
9 changes: 6 additions & 3 deletions tests/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/gogo/protobuf/proto"
ipns_pb "github.com/ipfs/go-ipns/pb"
iface "github.com/ipfs/interface-go-ipfs-core"
"github.com/ipfs/interface-go-ipfs-core/path"
)

func (tp *TestSuite) TestRouting(t *testing.T) {
Expand Down Expand Up @@ -48,9 +49,10 @@ func (tp *TestSuite) TestRoutingGet(t *testing.T) {

// Node 1: publishes an IPNS name
ipnsEntry := tp.testRoutingPublishKey(t, ctx, apis[0])
ipnsPath := path.Join(path.New("/ipns"), ipnsEntry.Name())

// Node 2: retrieves the best value for the IPNS name.
data, err := apis[1].Routing().Get(ctx, "/ipns/"+ipnsEntry.Name())
data, err := apis[1].Routing().Get(ctx, ipnsPath)
if err != nil {
t.Fatal(err)
}
Expand All @@ -77,15 +79,16 @@ func (tp *TestSuite) TestRoutingPut(t *testing.T) {

// Create and publish IPNS entry.
ipnsEntry := tp.testRoutingPublishKey(t, ctx, apis[0])
ipnsPath := path.Join(path.New("/ipns"), ipnsEntry.Name())

// Get valid routing value.
data, err := apis[0].Routing().Get(ctx, "/ipns/"+ipnsEntry.Name())
data, err := apis[0].Routing().Get(ctx, ipnsPath)
if err != nil {
t.Fatal(err)
}

// Put routing value.
err = apis[0].Routing().Put(ctx, "/ipns/"+ipnsEntry.Name(), data)
err = apis[0].Routing().Put(ctx, ipnsPath, data)
if err != nil {
t.Fatal(err)
}
Expand Down