open-consul/proto/pbservice/ids_test.go
Eric 91a493efe9 Bump go-control-plane
* `go get cloud.google.com/go@v0.59.0`
* `go get github.com/envoyproxy/go-control-plane@v0.9.9`
* `make envoy-library`
* Bumpprotoc to 3.15.8
2022-03-30 13:11:27 -04:00

68 lines
1.4 KiB
Go

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"},
},
},
expected: "/the-node-name/the-namespace/the-service-id",
},
{
name: "without node",
csn: &CheckServiceNode{
Service: &NodeService{
ID: "the-service-id",
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)
})
}
}