77f6b20db0
Ensure nothing in the troubleshoot go module depends on consul's top level module. This is so we can import troubleshoot into consul-k8s and not import all of consul. * turns troubleshoot into a go module [authored by @curtbushko] * gets the envoy protos into the troubleshoot module [authored by @curtbushko] * adds a new go module `envoyextensions` which has xdscommon and extensioncommon folders that both the xds package and the troubleshoot package can import * adds testing and linting for the new go modules * moves the unit tests in `troubleshoot/validateupstream` that depend on proxycfg/xds into the xds package, with a comment describing why those tests cannot be in the troubleshoot package * fixes all the imports everywhere as a result of these changes Co-authored-by: Curt Bushko <cbushko@gmail.com>
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
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,
|
|
Upstreams: map[api.CompoundServiceName]*UpstreamData{
|
|
sn: {
|
|
EnvoyID: "eid",
|
|
OutgoingProxyKind: api.ServiceKindTerminatingGateway,
|
|
SNI: map[string]struct{}{
|
|
"sni1": {},
|
|
"sni2": {},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
return rc
|
|
}
|
|
|
|
func TestRuntimeConfig_IsUpstream(t *testing.T) {
|
|
rc := makeTestRuntimeConfig()
|
|
require.True(t, rc.IsUpstream())
|
|
delete(rc.Upstreams, rc.ServiceName)
|
|
require.False(t, rc.IsUpstream())
|
|
}
|
|
|
|
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()
|
|
require.Equal(t, "eid", rc.EnvoyID())
|
|
}
|
|
|
|
func TestRuntimeConfig_OutgoingProxyKind(t *testing.T) {
|
|
rc := makeTestRuntimeConfig()
|
|
require.Equal(t, api.ServiceKindTerminatingGateway, rc.OutgoingProxyKind())
|
|
}
|