2018-06-05 03:04:45 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2021-03-26 21:21:38 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2018-06-05 03:04:45 +00:00
|
|
|
)
|
|
|
|
|
2021-03-26 21:21:38 +00:00
|
|
|
func TestConnectNameFromServiceNode(t *testing.T) {
|
2018-06-05 03:04:45 +00:00
|
|
|
cases := []struct {
|
2021-03-26 21:21:38 +00:00
|
|
|
name string
|
|
|
|
input structs.ServiceNode
|
|
|
|
expected string
|
|
|
|
expectedOk bool
|
2018-06-05 03:04:45 +00:00
|
|
|
}{
|
|
|
|
{
|
2021-03-26 21:21:38 +00:00
|
|
|
name: "typical service, not native",
|
|
|
|
input: structs.ServiceNode{ServiceName: "db"},
|
|
|
|
expectedOk: false,
|
2018-06-05 03:04:45 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2021-03-26 21:21:38 +00:00
|
|
|
name: "typical service, is native",
|
|
|
|
input: structs.ServiceNode{
|
2018-06-05 17:51:05 +00:00
|
|
|
ServiceName: "dB",
|
|
|
|
ServiceConnect: structs.ServiceConnect{Native: true},
|
2018-06-05 03:04:45 +00:00
|
|
|
},
|
2021-03-26 21:21:38 +00:00
|
|
|
expectedOk: true,
|
|
|
|
expected: "dB",
|
2018-06-05 03:04:45 +00:00
|
|
|
},
|
|
|
|
{
|
2021-03-26 21:21:38 +00:00
|
|
|
name: "proxy service",
|
|
|
|
input: structs.ServiceNode{
|
2018-09-12 16:07:47 +00:00
|
|
|
ServiceKind: structs.ServiceKindConnectProxy,
|
|
|
|
ServiceName: "db",
|
|
|
|
ServiceProxy: structs.ConnectProxyConfig{DestinationServiceName: "fOo"},
|
2018-06-05 03:04:45 +00:00
|
|
|
},
|
2021-03-26 21:21:38 +00:00
|
|
|
expectedOk: true,
|
|
|
|
expected: "fOo",
|
2018-06-05 03:04:45 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
2021-03-26 21:21:38 +00:00
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
actual, ok := connectNameFromServiceNode(&tc.input)
|
|
|
|
if !tc.expectedOk {
|
|
|
|
require.False(t, ok, "expected no connect name")
|
2018-06-05 03:04:45 +00:00
|
|
|
return
|
|
|
|
}
|
2021-03-26 21:21:38 +00:00
|
|
|
require.Equal(t, tc.expected, actual)
|
2018-06-05 03:04:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|