func (s *RingpopOptionsTestSuite) TestClockNil() {
	rp, err := New("test", Clock(nil))
	s.Nil(rp)
	s.Error(err)
}
TestClockNil confirms that nil clock option returns an error.
package ringpop
import (
	"testing"
	"time"
	"github.com/stretchr/testify/mock"
	"github.com/stretchr/testify/suite"
	"github.com/uber/ringpop-go/events"
	"github.com/uber/ringpop-go/hashring"
	"github.com/uber/ringpop-go/logging"
	"github.com/uber/ringpop-go/membership"
	"github.com/uber/ringpop-go/swim"
	"github.com/uber/ringpop-go/test/mocks"
	mocklogger "github.com/uber/ringpop-go/test/mocks/logger"
	"github.com/uber/tchannel-go"
)
type RingpopOptionsTestSuite struct {
	suite.Suite
	ringpop *Ringpop
	channel *tchannel.Channel
}
func (s *RingpopOptionsTestSuite) SetupTest() {
	ch, err := tchannel.NewChannel("test", nil)
	s.Require().NoError(err, "Channel creation failed")
	s.channel = ch
}
func (s *RingpopOptionsTestSuite) TearDownTest() {
	s.channel.Close()
}
func (s *RingpopOptionsTestSuite) TestDefaults() {
	rp, err := New("test", Channel(s.channel))
	s.Require().NotNil(rp)
	s.Require().NoError(err)
	s.NotNil(rp.logger)
	s.NotNil(rp.statter)
	s.Equal(defaultHashRingConfiguration, rp.configHashRing)
	testRingpop := &Ringpop{}
	defaultStatter(testRingpop)
	defaultHashRingOptions(testRingpop)
	s.Equal(testRingpop.statter, rp.statter)
	s.Equal(testRingpop.configHashRing, rp.configHashRing)
}
func (s *RingpopOptionsTestSuite) TestDefaultAddressResolver() {
	s.channel.ListenAndServe("127.0.0.1:0")
	hostport := s.channel.PeerInfo().HostPort
	rp, err := New("test", Channel(s.channel))
	s.Require().NotNil(rp)
	s.Require().NoError(err)
	address, err := rp.address()
	s.Equal(hostport, address)
	s.NoError(err)
}
func (s *RingpopOptionsTestSuite) TestChannelRequired() {
	rp, err := New("test")
	s.Nil(rp)
	s.Error(err)
}
func (s *RingpopOptionsTestSuite) TestLogger() {
	mockLogger := &mocklogger.Logger{}
	for _, meth := range []string{"Debug", "Info", "Warn", "Error"} {
		mockLogger.On(meth, mock.Anything)
		mockLogger.On(meth+"f", mock.Anything, mock.Anything)
	}
	mockLogger.On("WithField", mock.Anything, mock.Anything).Return(mockLogger)
	mockLogger.On("WithFields", mock.Anything).Return(mockLogger)
	rp, err := New("test", Channel(s.channel), Logger(mockLogger))
	defer logging.SetLogger(nil)
	s.Require().NotNil(rp)
	s.Require().NoError(err)
	mockLogger.On("Panic", []interface{}{"hello"})
	rp.logger.Panic("hello")
	mockLogger.AssertCalled(s.T(), "Panic", []interface{}{"hello"})
}
func (s *RingpopOptionsTestSuite) TestLogLevelsError() {
	levels := map[string]logging.Level{"named": logging.Panic}
	_, err := New("test", Channel(s.channel), LogLevels(levels))
	s.Error(err, "Setting log levels above Fatal should fail.")
}
func (s *RingpopOptionsTestSuite) TestStatter() {
	mockStatter := &mocks.StatsReporter{}
	rp, err := New("test", Channel(s.channel), Statter(mockStatter))
	s.Require().NotNil(rp)
	s.Require().NoError(err)
	s.Exactly(mockStatter, rp.statter)
}
func (s *RingpopOptionsTestSuite) TestHashRingConfig() {
	rp, err := New("test", Channel(s.channel), HashRingConfig(
		&hashring.Configuration{
			ReplicaPoints: 42,
		}),
	)
	s.Require().NotNil(rp)
	s.Require().NoError(err)
	s.Equal(rp.configHashRing.ReplicaPoints, 42)
}
func (s *RingpopOptionsTestSuite) TestAddressResolverFunc() {
	f := func() (string, error) {
		return "127.0.0.1:3001", nil
	}
	rp, err := New("test", Channel(s.channel), AddressResolverFunc(f))
	s.Require().NotNil(rp)
	s.Require().NoError(err)
	address, err := rp.addressResolver()
	s.Equal("127.0.0.1:3001", address)
	s.NoError(err)
}
func (s *RingpopOptionsTestSuite) TestMissingAddressResolver() {
	rp, err := New("test", Channel(s.channel), AddressResolverFunc(nil))
	s.Nil(rp)
	s.Error(err)
}
func (s *RingpopOptionsTestSuite) TestIdentity() {
	rp, err := New("test", Channel(s.channel), Identity("identity"))
	s.Require().NotNil(rp)
	s.Require().NoError(err)
	identity, has := rp.config.InitialLabels[membership.IdentityLabelKey]
	s.Equal(true, has, "Identity label set")
	s.Equal("identity", identity)
}
func (s *RingpopOptionsTestSuite) TestDefaultIdentity() {
	rp, err := New("test", Channel(s.channel))
	s.Require().NotNil(rp)
	s.Require().NoError(err)
	_, has := rp.config.InitialLabels[membership.IdentityLabelKey]
	s.Equal(false, has, "Identity label not set")
}
func (s *RingpopOptionsTestSuite) TestHostPortIdentity() {
	rp, err := New("test", Channel(s.channel), Identity("127.0.0.1:1234"))
	s.Nil(rp)
	s.Error(err)
}