github.com/xmidt-org/webpa-common@v1.11.9/service/consul/options_test.go (about)

     1  package consul
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/hashicorp/consul/api"
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func testOptionsDefault(t *testing.T, o *Options) {
    12  	assert := assert.New(t)
    13  
    14  	assert.NotNil(o.config())
    15  	assert.False(o.disableGenerateID())
    16  	assert.Len(o.registrations(), 0)
    17  	assert.Len(o.watches(), 0)
    18  }
    19  
    20  func testOptionsCustom(t *testing.T) {
    21  	var (
    22  		assert  = assert.New(t)
    23  		require = require.New(t)
    24  
    25  		o = Options{
    26  			Client: &api.Config{
    27  				Address: "somewhere.com",
    28  				Scheme:  "ftp",
    29  			},
    30  
    31  			DisableGenerateID: true,
    32  
    33  			Registrations: []api.AgentServiceRegistration{
    34  				api.AgentServiceRegistration{
    35  					ID:   "foo",
    36  					Name: "bar",
    37  				},
    38  			},
    39  
    40  			Watches: []Watch{
    41  				Watch{
    42  					Service:     "moo",
    43  					Tags:        []string{"a", "b"},
    44  					PassingOnly: true,
    45  				},
    46  			},
    47  		}
    48  	)
    49  
    50  	c := o.config()
    51  	require.NotNil(c)
    52  	assert.Equal("somewhere.com", c.Address)
    53  	assert.Equal("ftp", c.Scheme)
    54  
    55  	assert.True(o.disableGenerateID())
    56  
    57  	assert.Equal(
    58  		[]api.AgentServiceRegistration{
    59  			api.AgentServiceRegistration{
    60  				ID:   "foo",
    61  				Name: "bar",
    62  			},
    63  		},
    64  		o.registrations(),
    65  	)
    66  
    67  	assert.Equal(
    68  		[]Watch{
    69  			Watch{
    70  				Service:     "moo",
    71  				Tags:        []string{"a", "b"},
    72  				PassingOnly: true,
    73  			},
    74  		},
    75  		o.watches(),
    76  	)
    77  }
    78  
    79  func TestOptions(t *testing.T) {
    80  	t.Run("Default", func(t *testing.T) {
    81  		testOptionsDefault(t, nil)
    82  		testOptionsDefault(t, new(Options))
    83  	})
    84  
    85  	t.Run("Custom", testOptionsCustom)
    86  }