mirror of https://github.com/status-im/consul.git
50 lines
927 B
Go
50 lines
927 B
Go
|
package catalogv2beta1
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/require"
|
||
|
)
|
||
|
|
||
|
func TestServiceEndpoints_GetIdentities(t *testing.T) {
|
||
|
cases := map[string]struct {
|
||
|
endpoints []*Endpoint
|
||
|
expIdentities []string
|
||
|
}{
|
||
|
"no endpoints": {
|
||
|
endpoints: nil,
|
||
|
expIdentities: nil,
|
||
|
},
|
||
|
"no identities": {
|
||
|
endpoints: []*Endpoint{
|
||
|
{},
|
||
|
{},
|
||
|
},
|
||
|
expIdentities: nil,
|
||
|
},
|
||
|
"single identity": {
|
||
|
endpoints: []*Endpoint{
|
||
|
{Identity: "foo"},
|
||
|
{Identity: "foo"},
|
||
|
{Identity: "foo"},
|
||
|
},
|
||
|
expIdentities: []string{"foo"},
|
||
|
},
|
||
|
"multiple identities": {
|
||
|
endpoints: []*Endpoint{
|
||
|
{Identity: "foo"},
|
||
|
{Identity: "foo"},
|
||
|
{Identity: "bar"},
|
||
|
},
|
||
|
expIdentities: []string{"bar", "foo"},
|
||
|
},
|
||
|
}
|
||
|
|
||
|
for name, c := range cases {
|
||
|
t.Run(name, func(t *testing.T) {
|
||
|
se := &ServiceEndpoints{Endpoints: c.endpoints}
|
||
|
require.Equal(t, c.expIdentities, se.GetIdentities())
|
||
|
})
|
||
|
}
|
||
|
}
|