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
|
||||
}
|
||||
|
||||
func (bc *BackoffConfig) setDefaults() {
|
||||
func setDefaults(bc *BackoffConfig) {
|
||||
md := bc.MaxDelay
|
||||
*bc = DefaultBackoffConfig
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ import "testing"
|
||||
|
||||
func TestBackoffConfigDefaults(t *testing.T) {
|
||||
b := BackoffConfig{}
|
||||
b.setDefaults()
|
||||
setDefaults(&b)
|
||||
if 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 {
|
||||
// Set defaults to ensure that provided BackoffConfig is valid and
|
||||
// unexported fields get default values.
|
||||
b.setDefaults()
|
||||
setDefaults(&b)
|
||||
return withBackoff(b)
|
||||
}
|
||||
|
||||
|
||||
@ -88,14 +88,14 @@ func TestWithBackoffConfigDefault(t *testing.T) {
|
||||
func TestWithBackoffConfig(t *testing.T) {
|
||||
b := BackoffConfig{MaxDelay: DefaultBackoffConfig.MaxDelay / 2}
|
||||
expected := b
|
||||
expected.setDefaults() // defaults should be set
|
||||
setDefaults(&expected) // defaults should be set
|
||||
testBackoffConfigSet(t, &expected, WithBackoffConfig(b))
|
||||
}
|
||||
|
||||
func TestWithBackoffMaxDelay(t *testing.T) {
|
||||
md := DefaultBackoffConfig.MaxDelay / 2
|
||||
expected := BackoffConfig{MaxDelay: md}
|
||||
expected.setDefaults()
|
||||
setDefaults(&expected)
|
||||
testBackoffConfigSet(t, &expected, WithBackoffMaxDelay(md))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user