consul/proto/pbservice/ids_test.go
Dhia Ayachi 72a997242b
split pbcommon to pbcommon and pbcommongogo (#12587)
* mogify needed pbcommon structs

* mogify needed pbconnect structs

* fix compilation errors and make config_translate_test pass

* add missing file

* remove redundant oss func declaration

* fix EnterpriseMeta to copy the right data for enterprise

* rename pbcommon package to pbcommongogo

* regenerate proto and mog files

* add missing mog files

* add pbcommon package

* pbcommon no mog

* fix enterprise meta code generation

* fix enterprise meta code generation (pbcommongogo)

* fix mog generation for gogo

* use `protoc-go-inject-tag` to inject tags

* rename proto package

* pbcommon no mog

* use `protoc-go-inject-tag` to inject tags

* add non gogo proto to make file

* fix proto get
2022-03-22 16:30:00 -04:00

68 lines
1.4 KiB
Go

package pbservice
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/hashicorp/consul/proto/pbcommongogo"
)
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: pbcommongogo.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: pbcommongogo.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)
})
}
}