github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/orderer/common/follower/options_test.go (about)

     1  /*
     2  Copyright hechain. 2017 All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package follower
     8  
     9  import (
    10  	"testing"
    11  	"time"
    12  
    13  	"github.com/hechain20/hechain/common/flogging"
    14  	"github.com/stretchr/testify/require"
    15  )
    16  
    17  func TestOptions_applyDefaults(t *testing.T) {
    18  	t.Run("on empty object", func(t *testing.T) {
    19  		opt := Options{}
    20  		opt.applyDefaults()
    21  		require.Equal(t, defaultPullRetryMinInterval, opt.PullRetryMinInterval)
    22  		require.Equal(t, defaultPullRetryMaxInterval, opt.PullRetryMaxInterval)
    23  		require.Equal(t, defaultHeightPollMinInterval, opt.HeightPollMinInterval)
    24  		require.Equal(t, defaultHeightPollMaxInterval, opt.HeightPollMaxInterval)
    25  		require.NotNil(t, opt.Logger)
    26  		require.NotNil(t, opt.TimeAfter)
    27  	})
    28  	t.Run("with alternatives", func(t *testing.T) {
    29  		timeAfterFunc := func(d time.Duration) <-chan time.Time { return make(chan time.Time) }
    30  		opt := Options{
    31  			Logger:                flogging.MustGetLogger("test"),
    32  			PullRetryMinInterval:  time.Microsecond,
    33  			PullRetryMaxInterval:  time.Hour,
    34  			HeightPollMinInterval: time.Millisecond,
    35  			HeightPollMaxInterval: time.Minute,
    36  
    37  			TimeAfter: timeAfterFunc,
    38  		}
    39  		opt.applyDefaults()
    40  		require.Equal(t, time.Microsecond, opt.PullRetryMinInterval)
    41  		require.Equal(t, time.Hour, opt.PullRetryMaxInterval)
    42  		require.Equal(t, time.Millisecond, opt.HeightPollMinInterval)
    43  		require.Equal(t, time.Minute, opt.HeightPollMaxInterval)
    44  		require.NotNil(t, opt.Logger)
    45  		require.NotNil(t, opt.TimeAfter)
    46  	})
    47  }