Merge pull request #641 from iamqizhao/master
make setDefault(...) non-member function
This commit is contained in:
@ -49,7 +49,7 @@ type BackoffConfig struct {
|
|||||||
jitter float64
|
jitter float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BackoffConfig) setDefaults() {
|
func setDefaults(bc *BackoffConfig) {
|
||||||
md := bc.MaxDelay
|
md := bc.MaxDelay
|
||||||
*bc = DefaultBackoffConfig
|
*bc = DefaultBackoffConfig
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import "testing"
|
|||||||
|
|
||||||
func TestBackoffConfigDefaults(t *testing.T) {
|
func TestBackoffConfigDefaults(t *testing.T) {
|
||||||
b := BackoffConfig{}
|
b := BackoffConfig{}
|
||||||
b.setDefaults()
|
setDefaults(&b)
|
||||||
if b != DefaultBackoffConfig {
|
if b != DefaultBackoffConfig {
|
||||||
t.Fatalf("expected BackoffConfig to pickup default parameters: %v != %v", b, DefaultBackoffConfig)
|
t.Fatalf("expected BackoffConfig to pickup default parameters: %v != %v", b, DefaultBackoffConfig)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -129,7 +129,7 @@ func WithBackoffMaxDelay(md time.Duration) DialOption {
|
|||||||
func WithBackoffConfig(b BackoffConfig) DialOption {
|
func WithBackoffConfig(b BackoffConfig) DialOption {
|
||||||
// Set defaults to ensure that provided BackoffConfig is valid and
|
// Set defaults to ensure that provided BackoffConfig is valid and
|
||||||
// unexported fields get default values.
|
// unexported fields get default values.
|
||||||
b.setDefaults()
|
setDefaults(&b)
|
||||||
return withBackoff(b)
|
return withBackoff(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -88,14 +88,14 @@ func TestWithBackoffConfigDefault(t *testing.T) {
|
|||||||
func TestWithBackoffConfig(t *testing.T) {
|
func TestWithBackoffConfig(t *testing.T) {
|
||||||
b := BackoffConfig{MaxDelay: DefaultBackoffConfig.MaxDelay / 2}
|
b := BackoffConfig{MaxDelay: DefaultBackoffConfig.MaxDelay / 2}
|
||||||
expected := b
|
expected := b
|
||||||
expected.setDefaults() // defaults should be set
|
setDefaults(&expected) // defaults should be set
|
||||||
testBackoffConfigSet(t, &expected, WithBackoffConfig(b))
|
testBackoffConfigSet(t, &expected, WithBackoffConfig(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWithBackoffMaxDelay(t *testing.T) {
|
func TestWithBackoffMaxDelay(t *testing.T) {
|
||||||
md := DefaultBackoffConfig.MaxDelay / 2
|
md := DefaultBackoffConfig.MaxDelay / 2
|
||||||
expected := BackoffConfig{MaxDelay: md}
|
expected := BackoffConfig{MaxDelay: md}
|
||||||
expected.setDefaults()
|
setDefaults(&expected)
|
||||||
testBackoffConfigSet(t, &expected, WithBackoffMaxDelay(md))
|
testBackoffConfigSet(t, &expected, WithBackoffMaxDelay(md))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user