open-consul/proto/pbservice/ids_test.go

68 lines
1.4 KiB
Go
Raw Normal View History

package pbservice
import (
"testing"
"github.com/stretchr/testify/require"
2022-03-23 16:10:03 +00:00
"github.com/hashicorp/consul/proto/pbcommon"
)
func TestCheckServiceNode_UniqueID(t *testing.T) {
type testCase struct {
name string
csn *CheckServiceNode
expected string
}
fn := func(t *testing.T, tc *testCase) {
require.Equal(t, tc.expected, tc.csn.UniqueID())
}
var testCases = []testCase{
{
name: "full",
csn: &CheckServiceNode{
Node: &Node{Node: "the-node-name"},
Service: &NodeService{
ID: "the-service-id",
2022-03-23 16:10:03 +00:00
EnterpriseMeta: &pbcommon.EnterpriseMeta{Namespace: "the-namespace"},
},
},
expected: "/the-node-name/the-namespace/the-service-id",
},
{
name: "without node",
csn: &CheckServiceNode{
Service: &NodeService{
ID: "the-service-id",
2022-03-23 16:10:03 +00:00
EnterpriseMeta: &pbcommon.EnterpriseMeta{Namespace: "the-namespace"},
},
},
expected: "/the-namespace/the-service-id",
},
{
name: "without service",
csn: &CheckServiceNode{
Node: &Node{Node: "the-node-name"},
},
expected: "/the-node-name/",
},
{
name: "without namespace",
csn: &CheckServiceNode{
Node: &Node{Node: "the-node-name"},
Service: &NodeService{
ID: "the-service-id",
},
},
expected: "/the-node-name//the-service-id",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
fn(t, &tc)
})
}
}