Skip to content

Commit

Permalink
Merge pull request ipfs/go-namesys#14 from iand/chore/repo-health
Browse files Browse the repository at this point in the history
chore: fixup tests and ensure go vet and staticcheck pass

This commit was moved from ipfs/go-namesys@42d3e89
  • Loading branch information
Stebalien authored May 10, 2021
2 parents 56a1f4c + 8ec870d commit 6867c9d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 0 additions & 1 deletion namesys/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func (m *mockDNS) lookupTXT(ctx context.Context, name string) (txt []string, err
}

func TestDnsEntryParsing(t *testing.T) {

goodEntries := []string{
"QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
Expand Down
2 changes: 1 addition & 1 deletion namesys/namesys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestPublishWithTTL(t *testing.T) {
ttl := 1 * time.Second
eol := time.Now().Add(2 * time.Second)

ctx := context.WithValue(context.Background(), "ipns-publish-ttl", ttl)
ctx := ContextWithTTL(context.Background(), ttl)
err = nsys.Publish(ctx, priv, p)
if err != nil {
t.Fatal(err)
Expand Down
12 changes: 11 additions & 1 deletion namesys/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (p *IpnsPublisher) PublishWithEOL(ctx context.Context, k ci.PrivKey, value
// as such, i'm using the context to wire it through to avoid changing too
// much code along the way.
func checkCtxTTL(ctx context.Context) (time.Duration, bool) {
v := ctx.Value("ipns-publish-ttl")
v := ctx.Value(ttlContextKey)
if v == nil {
return 0, false
}
Expand Down Expand Up @@ -296,3 +296,13 @@ func PublishEntry(ctx context.Context, r routing.ValueStore, ipnskey string, rec
func PkKeyForID(id peer.ID) string {
return "/pk/" + string(id)
}

// contextKey is a private comparable type used to hold value keys in contexts
type contextKey string

var ttlContextKey contextKey = "ipns-publish-ttl"

// ContextWithTTL returns a copy of the parent context with an added value representing the TTL
func ContextWithTTL(ctx context.Context, ttl time.Duration) context.Context {
return context.WithValue(context.Background(), ttlContextKey, ttl)
}
3 changes: 2 additions & 1 deletion namesys/publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package namesys
import (
"context"
"crypto/rand"
"github.com/ipfs/go-path"
"testing"
"time"

"github.com/ipfs/go-path"

ds "github.com/ipfs/go-datastore"
dssync "github.com/ipfs/go-datastore/sync"
dshelp "github.com/ipfs/go-ipfs-ds-help"
Expand Down

0 comments on commit 6867c9d

Please sign in to comment.