2020-10-06 20:54:56 +00:00
|
|
|
package pbservice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"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",
|
|
|
|
EnterpriseMeta: pbcommon.EnterpriseMeta{Namespace: "the-namespace"},
|
|
|
|
},
|
|
|
|
},
|
2021-07-22 19:33:22 +00:00
|
|
|
expected: "/the-node-name/the-namespace/the-service-id",
|
2020-10-06 20:54:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "without node",
|
|
|
|
csn: CheckServiceNode{
|
|
|
|
Service: &NodeService{
|
|
|
|
ID: "the-service-id",
|
|
|
|
EnterpriseMeta: pbcommon.EnterpriseMeta{Namespace: "the-namespace"},
|
|
|
|
},
|
|
|
|
},
|
2021-07-22 19:33:22 +00:00
|
|
|
expected: "/the-namespace/the-service-id",
|
2020-10-06 20:54:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "without service",
|
|
|
|
csn: CheckServiceNode{
|
|
|
|
Node: &Node{Node: "the-node-name"},
|
|
|
|
},
|
2021-07-22 19:33:22 +00:00
|
|
|
expected: "/the-node-name/",
|
2020-10-06 20:54:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "without namespace",
|
|
|
|
csn: CheckServiceNode{
|
|
|
|
Node: &Node{Node: "the-node-name"},
|
|
|
|
Service: &NodeService{
|
|
|
|
ID: "the-service-id",
|
|
|
|
},
|
|
|
|
},
|
2021-07-22 19:33:22 +00:00
|
|
|
expected: "/the-node-name//the-service-id",
|
2020-10-06 20:54:56 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
fn(t, tc)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|