hashicorp-copywrite[bot] 5fb9df1640
[COMPLIANCE] License changes (#18443)
* Adding explicit MPL license for sub-package

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Adding explicit MPL license for sub-package

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Updating the license from MPL to Business Source License

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl.

* add missing license headers

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-08-11 09:12:13 -04:00

154 lines
3.4 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package pbservice
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/hashicorp/consul/proto/private/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",
PeerName: "my-peer",
Partition: "the-partition",
},
Service: &NodeService{
ID: "the-service-id",
EnterpriseMeta: &pbcommon.EnterpriseMeta{
Partition: "the-partition",
Namespace: "the-namespace",
},
PeerName: "my-peer",
},
},
expected: "the-partition/my-peer/the-node-name/the-namespace/the-service-id",
},
{
name: "without node",
csn: &CheckServiceNode{
Service: &NodeService{
ID: "the-service-id",
EnterpriseMeta: &pbcommon.EnterpriseMeta{
Partition: "the-partition",
Namespace: "the-namespace",
},
PeerName: "my-peer",
},
},
expected: "the-partition/my-peer/the-namespace/the-service-id",
},
{
name: "without service",
csn: &CheckServiceNode{
Node: &Node{
Node: "the-node-name",
PeerName: "my-peer",
Partition: "the-partition",
},
},
expected: "the-partition/my-peer/the-node-name/",
},
{
name: "without namespace",
csn: &CheckServiceNode{
Node: &Node{
Node: "the-node-name",
PeerName: "my-peer",
Partition: "the-partition",
},
Service: &NodeService{
ID: "the-service-id",
PeerName: "my-peer",
EnterpriseMeta: &pbcommon.EnterpriseMeta{
Partition: "the-partition",
},
},
},
expected: "the-partition/my-peer/the-node-name//the-service-id",
},
{
name: "without peer name",
csn: &CheckServiceNode{
Node: &Node{
Node: "the-node-name",
Partition: "the-partition",
},
Service: &NodeService{
ID: "the-service-id",
EnterpriseMeta: &pbcommon.EnterpriseMeta{
Partition: "the-partition",
Namespace: "the-namespace",
},
},
},
expected: "the-partition//the-node-name/the-namespace/the-service-id",
},
{
name: "without partition",
csn: &CheckServiceNode{
Node: &Node{
Node: "the-node-name",
PeerName: "my-peer",
},
Service: &NodeService{
ID: "the-service-id",
PeerName: "my-peer",
EnterpriseMeta: &pbcommon.EnterpriseMeta{
Namespace: "the-namespace",
},
},
},
expected: "/my-peer/the-node-name/the-namespace/the-service-id",
},
{
name: "without partition or namespace",
csn: &CheckServiceNode{
Node: &Node{
Node: "the-node-name",
PeerName: "my-peer",
},
Service: &NodeService{
ID: "the-service-id",
PeerName: "my-peer",
},
},
expected: "/my-peer/the-node-name//the-service-id",
},
{
name: "without partition or namespace or peer name",
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)
})
}
}