|
|
|
@ -94,6 +94,121 @@ func TestConnectProxyConfig_ToAPI(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestConnectProxyConfig_MarshalJSON(t *testing.T) {
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
in ConnectProxyConfig
|
|
|
|
|
want string
|
|
|
|
|
wantErr bool
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
name: "direct proxy",
|
|
|
|
|
in: ConnectProxyConfig{
|
|
|
|
|
DestinationServiceName: "api",
|
|
|
|
|
DestinationServiceID: "api-1",
|
|
|
|
|
LocalServiceAddress: "127.0.0.1",
|
|
|
|
|
LocalServicePort: 8080,
|
|
|
|
|
Mode: ProxyModeDirect,
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
|
"connect_timeout_ms": 5000,
|
|
|
|
|
},
|
|
|
|
|
Upstreams: Upstreams{
|
|
|
|
|
Upstream{
|
|
|
|
|
DestinationType: UpstreamDestTypeService,
|
|
|
|
|
DestinationName: "db",
|
|
|
|
|
Datacenter: "dc1",
|
|
|
|
|
LocalBindPort: 1234,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
MeshGateway: MeshGatewayConfig{Mode: MeshGatewayModeLocal},
|
|
|
|
|
Expose: ExposeConfig{Checks: true},
|
|
|
|
|
|
|
|
|
|
// No transparent proxy config, since proxy is set to "direct" mode.
|
|
|
|
|
// Field should be omitted from json output.
|
|
|
|
|
// TransparentProxy: TransparentProxyConfig{},
|
|
|
|
|
},
|
|
|
|
|
want: `{
|
|
|
|
|
"DestinationServiceName": "api",
|
|
|
|
|
"DestinationServiceID": "api-1",
|
|
|
|
|
"LocalServiceAddress": "127.0.0.1",
|
|
|
|
|
"LocalServicePort": 8080,
|
|
|
|
|
"Mode": "direct",
|
|
|
|
|
"Config": {
|
|
|
|
|
"connect_timeout_ms": 5000
|
|
|
|
|
},
|
|
|
|
|
"Upstreams": [
|
|
|
|
|
{
|
|
|
|
|
"DestinationType": "service",
|
|
|
|
|
"DestinationName": "db",
|
|
|
|
|
"Datacenter": "dc1",
|
|
|
|
|
"LocalBindPort": 1234,
|
|
|
|
|
"MeshGateway": {}
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"MeshGateway": {
|
|
|
|
|
"Mode": "local"
|
|
|
|
|
},
|
|
|
|
|
"Expose": {
|
|
|
|
|
"Checks": true
|
|
|
|
|
}
|
|
|
|
|
}`,
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "transparent proxy",
|
|
|
|
|
in: ConnectProxyConfig{
|
|
|
|
|
DestinationServiceName: "billing",
|
|
|
|
|
DestinationServiceID: "billing-1",
|
|
|
|
|
LocalServiceAddress: "127.0.0.1",
|
|
|
|
|
LocalServicePort: 8080,
|
|
|
|
|
Mode: ProxyModeTransparent,
|
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
|
"connect_timeout_ms": 5000,
|
|
|
|
|
},
|
|
|
|
|
MeshGateway: MeshGatewayConfig{Mode: MeshGatewayModeLocal},
|
|
|
|
|
Expose: ExposeConfig{Checks: true},
|
|
|
|
|
TransparentProxy: TransparentProxyConfig{
|
|
|
|
|
DialedDirectly: true,
|
|
|
|
|
OutboundListenerPort: 16001,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
want: `{
|
|
|
|
|
"DestinationServiceName": "billing",
|
|
|
|
|
"DestinationServiceID": "billing-1",
|
|
|
|
|
"LocalServiceAddress": "127.0.0.1",
|
|
|
|
|
"LocalServicePort": 8080,
|
|
|
|
|
"Mode": "transparent",
|
|
|
|
|
"Config": {
|
|
|
|
|
"connect_timeout_ms": 5000
|
|
|
|
|
},
|
|
|
|
|
"TransparentProxy": {
|
|
|
|
|
"DialedDirectly": true,
|
|
|
|
|
"OutboundListenerPort": 16001
|
|
|
|
|
},
|
|
|
|
|
"MeshGateway": {
|
|
|
|
|
"Mode": "local"
|
|
|
|
|
},
|
|
|
|
|
"Expose": {
|
|
|
|
|
"Checks": true
|
|
|
|
|
}
|
|
|
|
|
}`,
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
require := require.New(t)
|
|
|
|
|
got, err := tt.in.MarshalJSON()
|
|
|
|
|
if tt.wantErr {
|
|
|
|
|
require.Error(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
require.NoError(err)
|
|
|
|
|
require.JSONEq(tt.want, string(got))
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestUpstream_MarshalJSON(t *testing.T) {
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|