2022-03-15 14:07:40 +00:00
|
|
|
//go:build !consulent
|
|
|
|
// +build !consulent
|
|
|
|
|
|
|
|
package xdscommon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/proxycfg"
|
2022-05-05 20:39:39 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2022-03-15 14:07:40 +00:00
|
|
|
"github.com/hashicorp/consul/api"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMakePluginConfiguration_TerminatingGateway(t *testing.T) {
|
2022-04-13 15:45:25 +00:00
|
|
|
snap := proxycfg.TestConfigSnapshotTerminatingGatewayWithLambdaServiceAndServiceResolvers(t)
|
2022-03-15 14:07:40 +00:00
|
|
|
|
|
|
|
webService := api.CompoundServiceName{
|
|
|
|
Name: "web",
|
|
|
|
Namespace: "default",
|
|
|
|
Partition: "default",
|
|
|
|
}
|
|
|
|
dbService := api.CompoundServiceName{
|
|
|
|
Name: "db",
|
|
|
|
Namespace: "default",
|
|
|
|
Partition: "default",
|
|
|
|
}
|
|
|
|
cacheService := api.CompoundServiceName{
|
|
|
|
Name: "cache",
|
|
|
|
Namespace: "default",
|
|
|
|
Partition: "default",
|
|
|
|
}
|
|
|
|
apiService := api.CompoundServiceName{
|
|
|
|
Name: "api",
|
|
|
|
Namespace: "default",
|
|
|
|
Partition: "default",
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := PluginConfiguration{
|
|
|
|
Kind: api.ServiceKindTerminatingGateway,
|
|
|
|
ServiceConfigs: map[api.CompoundServiceName]ServiceConfig{
|
|
|
|
webService: {
|
|
|
|
Kind: api.ServiceKindTerminatingGateway,
|
2022-03-31 20:24:46 +00:00
|
|
|
Meta: map[string]string{
|
|
|
|
"serverless.consul.hashicorp.com/v1alpha1/lambda/enabled": "true",
|
|
|
|
"serverless.consul.hashicorp.com/v1alpha1/lambda/arn": "lambda-arn",
|
|
|
|
"serverless.consul.hashicorp.com/v1alpha1/lambda/payload-passthrough": "true",
|
|
|
|
"serverless.consul.hashicorp.com/v1alpha1/lambda/region": "us-east-1",
|
|
|
|
},
|
2022-03-15 14:07:40 +00:00
|
|
|
},
|
|
|
|
apiService: {
|
|
|
|
Kind: api.ServiceKindTerminatingGateway,
|
|
|
|
},
|
|
|
|
cacheService: {
|
|
|
|
Kind: api.ServiceKindTerminatingGateway,
|
|
|
|
},
|
|
|
|
dbService: {
|
|
|
|
Kind: api.ServiceKindTerminatingGateway,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SNIToServiceName: map[string]api.CompoundServiceName{
|
2022-04-13 15:45:25 +00:00
|
|
|
"api.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul": apiService,
|
|
|
|
"cache.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul": cacheService,
|
|
|
|
"db.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul": dbService,
|
|
|
|
"web.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul": webService,
|
|
|
|
"canary1.web.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul": webService,
|
|
|
|
"canary2.web.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul": webService,
|
2022-03-15 14:07:40 +00:00
|
|
|
},
|
|
|
|
EnvoyIDToServiceName: map[string]api.CompoundServiceName{
|
|
|
|
"web": webService,
|
|
|
|
"db": dbService,
|
|
|
|
"cache": cacheService,
|
|
|
|
"api": apiService,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Equal(t, expected, MakePluginConfiguration(snap))
|
|
|
|
}
|
2022-05-05 20:39:39 +00:00
|
|
|
|
|
|
|
func TestMakePluginConfiguration_ConnectProxy(t *testing.T) {
|
|
|
|
dbService := api.CompoundServiceName{
|
|
|
|
Name: "db",
|
|
|
|
Partition: "default",
|
|
|
|
Namespace: "default",
|
|
|
|
}
|
|
|
|
lambdaMeta := map[string]string{
|
|
|
|
"serverless.consul.hashicorp.com/v1alpha1/lambda/enabled": "true",
|
|
|
|
"serverless.consul.hashicorp.com/v1alpha1/lambda/arn": "lambda-arn",
|
|
|
|
"serverless.consul.hashicorp.com/v1alpha1/lambda/payload-passthrough": "true",
|
|
|
|
"serverless.consul.hashicorp.com/v1alpha1/lambda/region": "us-east-1",
|
|
|
|
}
|
|
|
|
serviceDefaults := &structs.ServiceConfigEntry{
|
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "db",
|
|
|
|
Protocol: "http",
|
|
|
|
Meta: lambdaMeta,
|
|
|
|
}
|
|
|
|
|
|
|
|
snap := proxycfg.TestConfigSnapshotDiscoveryChain(t, "default", nil, nil, serviceDefaults)
|
|
|
|
expected := PluginConfiguration{
|
|
|
|
Kind: api.ServiceKindConnectProxy,
|
|
|
|
ServiceConfigs: map[api.CompoundServiceName]ServiceConfig{
|
|
|
|
dbService: {
|
|
|
|
Kind: api.ServiceKindConnectProxy,
|
|
|
|
Meta: lambdaMeta,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SNIToServiceName: map[string]api.CompoundServiceName{
|
|
|
|
"db.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul": dbService,
|
|
|
|
},
|
|
|
|
EnvoyIDToServiceName: map[string]api.CompoundServiceName{
|
|
|
|
"db": dbService,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Equal(t, expected, MakePluginConfiguration(snap))
|
|
|
|
}
|