open-consul/agent/consul/state/index_connect_test.go
Ronald dd0e8eec14
copyright headers for agent folder (#16704)
* copyright headers for agent folder

* Ignore test data files

* fix proto files and remove headers in agent/uiserver folder

* ignore deep-copy files
2023-03-28 14:39:22 -04:00

59 lines
1.2 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package state
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/hashicorp/consul/agent/structs"
)
func TestConnectNameFromServiceNode(t *testing.T) {
cases := []struct {
name string
input structs.ServiceNode
expected string
expectedOk bool
}{
{
name: "typical service, not native",
input: structs.ServiceNode{ServiceName: "db"},
expectedOk: false,
},
{
name: "typical service, is native",
input: structs.ServiceNode{
ServiceName: "dB",
ServiceConnect: structs.ServiceConnect{Native: true},
},
expectedOk: true,
expected: "dB",
},
{
name: "proxy service",
input: structs.ServiceNode{
ServiceKind: structs.ServiceKindConnectProxy,
ServiceName: "db",
ServiceProxy: structs.ConnectProxyConfig{DestinationServiceName: "fOo"},
},
expectedOk: true,
expected: "fOo",
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
actual, ok := connectNameFromServiceNode(&tc.input)
if !tc.expectedOk {
require.False(t, ok, "expected no connect name")
return
}
require.Equal(t, tc.expected, actual)
})
}
}