github.com/Axway/agent-sdk@v1.1.101/pkg/watchmanager/options_test.go (about)

     1  package watchmanager
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/Axway/agent-sdk/pkg/watchmanager/proto"
     8  	"github.com/sirupsen/logrus"
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  type testSequenceProvider struct {
    13  	id int64
    14  }
    15  
    16  func (s *testSequenceProvider) GetSequence() int64 {
    17  	return s.id
    18  }
    19  
    20  func (s *testSequenceProvider) SetSequence(id int64) {
    21  	s.id = id
    22  }
    23  
    24  func TestWatchOptions(t *testing.T) {
    25  	entry := logrus.NewEntry(logrus.New())
    26  	seq := &testSequenceProvider{}
    27  	seq.SetSequence(1)
    28  	opts := []Option{
    29  		WithTLSConfig(nil),
    30  		WithKeepAlive(1*time.Second, 1*time.Second),
    31  		WithLogger(entry),
    32  		WithHarvester(&mockHarvester{}, seq),
    33  		WithProxy("http://proxy"),
    34  		WithSingleEntryAddr("single-entry"),
    35  	}
    36  
    37  	options := newWatchOptions()
    38  
    39  	for _, opt := range opts {
    40  		opt.apply(options)
    41  	}
    42  
    43  	assert.Nil(t, options.tlsCfg)
    44  	assert.Equal(t, entry, options.loggerEntry)
    45  	assert.Equal(t, 1*time.Second, options.keepAlive.timeout)
    46  	assert.Equal(t, 1*time.Second, options.keepAlive.time)
    47  	assert.NotNil(t, options.sequence)
    48  	assert.Equal(t, "http://proxy", options.proxyURL)
    49  	assert.Equal(t, "single-entry", options.singleEntryAddr)
    50  }
    51  
    52  type mockHarvester struct{}
    53  
    54  func (m mockHarvester) EventCatchUp(link string, events chan *proto.Event) error {
    55  	// TODO implement me
    56  	panic("implement me")
    57  }
    58  
    59  func (m mockHarvester) ReceiveSyncEvents(topicSelfLink string, sequenceID int64, eventCh chan *proto.Event) (int64, error) {
    60  	// TODO implement me
    61  	panic("implement me")
    62  }