1package structs 2 3import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7) 8 9func TestConsul_Copy(t *testing.T) { 10 t.Run("nil", func(t *testing.T) { 11 result := (*Consul)(nil).Copy() 12 require.Nil(t, result) 13 }) 14 15 t.Run("set", func(t *testing.T) { 16 result := (&Consul{ 17 Namespace: "one", 18 }).Copy() 19 require.Equal(t, &Consul{Namespace: "one"}, result) 20 }) 21} 22 23func TestConsul_Equals(t *testing.T) { 24 t.Run("nil and nil", func(t *testing.T) { 25 result := (*Consul)(nil).Equals((*Consul)(nil)) 26 require.True(t, result) 27 }) 28 29 t.Run("nil and set", func(t *testing.T) { 30 result := (*Consul)(nil).Equals(&Consul{Namespace: "one"}) 31 require.False(t, result) 32 }) 33 34 t.Run("same", func(t *testing.T) { 35 result := (&Consul{Namespace: "one"}).Equals(&Consul{Namespace: "one"}) 36 require.True(t, result) 37 }) 38 39 t.Run("different", func(t *testing.T) { 40 result := (&Consul{Namespace: "one"}).Equals(&Consul{Namespace: "two"}) 41 require.False(t, result) 42 }) 43} 44 45func TestConsul_Validate(t *testing.T) { 46 t.Run("empty ns", func(t *testing.T) { 47 result := (&Consul{Namespace: ""}).Validate() 48 require.Nil(t, result) 49 }) 50 51 t.Run("with ns", func(t *testing.T) { 52 result := (&Consul{Namespace: "one"}).Validate() 53 require.Nil(t, result) 54 }) 55} 56