chore: fixup tests and ensure go vet and staticcheck pass

parent 2454122e
......@@ -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",
......
......@@ -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)
......
......@@ -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
}
......@@ -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,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"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment