Merge pull request #641 from iamqizhao/master

make setDefault(...) non-member function
This commit is contained in:
Menghan Li
2016-04-18 13:39:30 -07:00
4 changed files with 5 additions and 5 deletions

View File

@ -49,7 +49,7 @@ type BackoffConfig struct {
jitter float64
}
func (bc *BackoffConfig) setDefaults() {
func setDefaults(bc *BackoffConfig) {
md := bc.MaxDelay
*bc = DefaultBackoffConfig

View File

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

View File

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

View File

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