fix(options): make the disable providers/values options consistent

This commit is contained in:
Steven Allen 2019-12-06 09:47:22 -05:00
parent ba86f51884
commit 2a39785d3f
3 changed files with 32 additions and 12 deletions

View File

@ -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()

View File

@ -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
}
}

View File

@ -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()