2023-03-28 22:48:58 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2023-01-30 21:35:26 +00:00
|
|
|
package extensioncommon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/api"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func makeTestRuntimeConfig() RuntimeConfig {
|
|
|
|
sn := api.CompoundServiceName{Name: "api"}
|
|
|
|
|
|
|
|
rc := RuntimeConfig{
|
|
|
|
Kind: api.ServiceKindConnectProxy,
|
|
|
|
ServiceName: sn,
|
2023-02-06 17:14:35 +00:00
|
|
|
Upstreams: map[api.CompoundServiceName]*UpstreamData{
|
2023-01-30 21:35:26 +00:00
|
|
|
sn: {
|
|
|
|
EnvoyID: "eid",
|
|
|
|
OutgoingProxyKind: api.ServiceKindTerminatingGateway,
|
2023-05-30 18:53:42 +00:00
|
|
|
SNIs: map[string]struct{}{
|
2023-01-30 21:35:26 +00:00
|
|
|
"sni1": {},
|
|
|
|
"sni2": {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return rc
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRuntimeConfig_MatchesUpstreamServiceSNI(t *testing.T) {
|
|
|
|
rc := makeTestRuntimeConfig()
|
|
|
|
require.True(t, rc.MatchesUpstreamServiceSNI("sni1"))
|
|
|
|
require.True(t, rc.MatchesUpstreamServiceSNI("sni2"))
|
|
|
|
require.False(t, rc.MatchesUpstreamServiceSNI("sni3"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRuntimeConfig_EnvoyID(t *testing.T) {
|
|
|
|
rc := makeTestRuntimeConfig()
|
2023-05-23 11:55:06 +00:00
|
|
|
require.Equal(t, "eid", rc.UpstreamEnvoyID())
|
2023-01-30 21:35:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRuntimeConfig_OutgoingProxyKind(t *testing.T) {
|
|
|
|
rc := makeTestRuntimeConfig()
|
2023-05-23 11:55:06 +00:00
|
|
|
require.Equal(t, api.ServiceKindTerminatingGateway, rc.UpstreamOutgoingProxyKind())
|
2023-01-30 21:35:26 +00:00
|
|
|
}
|