From 2a39785d3f2bf8a686066c44b1e2ca3a6cc7b85d Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 6 Dec 2019 09:47:22 -0500 Subject: [PATCH] fix(options): make the disable providers/values options consistent --- dht_test.go | 14 ++++++++++++-- opts/options.go | 16 ++++++++-------- records_test.go | 14 ++++++++++++-- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/dht_test.go b/dht_test.go index 4e5d1ba..5aa9182 100644 --- a/dht_test.go +++ b/dht_test.go @@ -1430,8 +1430,18 @@ func TestProvideDisabled(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - dhtA := setupDHT(ctx, t, false, opts.EnableProviders(enabledA)) - dhtB := setupDHT(ctx, t, false, opts.EnableProviders(enabledB)) + var ( + optsA, optsB []opts.Option + ) + if !enabledA { + optsA = append(optsA, opts.DisableProviders()) + } + if !enabledB { + optsB = append(optsB, opts.DisableProviders()) + } + + dhtA := setupDHT(ctx, t, false, optsA...) + dhtB := setupDHT(ctx, t, false, optsB...) defer dhtA.Close() defer dhtB.Close() diff --git a/opts/options.go b/opts/options.go index 74529d2..0920ed1 100644 --- a/opts/options.go +++ b/opts/options.go @@ -182,28 +182,28 @@ func DisableAutoRefresh() Option { } } -// EnableProviders enables storing and retrieving provider records. +// DisableProviders disables storing and retrieving provider records. // -// Defaults to true. +// Defaults to enabled. // // WARNING: do not change this unless you're using a forked DHT (i.e., a private // network and/or distinct DHT protocols with the `Protocols` option). -func EnableProviders(enable bool) Option { +func DisableProviders() Option { return func(o *Options) error { - o.EnableProviders = enable + o.EnableProviders = false return nil } } -// EnableValues enables storing and retrieving value records. +// DisableProviders disables storing and retrieving value records. // -// Defaults to true. +// Defaults to enabled. // // WARNING: do not change this unless you're using a forked DHT (i.e., a private // network and/or distinct DHT protocols with the `Protocols` option). -func EnableValues(enable bool) Option { +func DisableValues() Option { return func(o *Options) error { - o.EnableValues = enable + o.EnableValues = false return nil } } diff --git a/records_test.go b/records_test.go index 2594b05..458de2b 100644 --- a/records_test.go +++ b/records_test.go @@ -317,8 +317,18 @@ func TestValuesDisabled(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - dhtA := setupDHT(ctx, t, false, dhtopt.EnableValues(enabledA)) - dhtB := setupDHT(ctx, t, false, dhtopt.EnableValues(enabledB)) + var ( + optsA, optsB []dhtopt.Option + ) + if !enabledA { + optsA = append(optsA, dhtopt.DisableValues()) + } + if !enabledB { + optsB = append(optsB, dhtopt.DisableValues()) + } + + dhtA := setupDHT(ctx, t, false, optsA...) + dhtB := setupDHT(ctx, t, false, optsB...) defer dhtA.Close() defer dhtB.Close()