consul/agent/xds/serverlessplugin/lambda_patcher_test.go
Nitya Dhanushkodi c7ef04c597
[OSS] extensions: refactor PluginConfiguration into a more generic type ExtensionConfiguration (#15846)
* extensions: refactor PluginConfiguration into a more generic type
ExtensionConfiguration

Also:
* adds endpoints configuration to lambda golden tests
* uses string constant for builtin/aws/lambda
Co-authored-by: Eric <eric@haberkorn.co>
2022-12-20 22:26:20 -08:00

72 lines
1.4 KiB
Go

package serverlessplugin
import (
"testing"
"github.com/hashicorp/consul/agent/structs"
"github.com/stretchr/testify/require"
"github.com/hashicorp/consul/api"
)
func TestMakeLambdaPatcher(t *testing.T) {
kind := api.ServiceKindTerminatingGateway
cases := []struct {
name string
arn string
payloadPassthrough bool
region string
expected lambdaPatcher
ok bool
}{
{
name: "no extension",
ok: false,
},
{
name: "missing arn",
region: "blah",
ok: false,
},
{
name: "missing region",
arn: "arn",
ok: false,
},
{
name: "including payload passthrough",
arn: "arn",
region: "blah",
payloadPassthrough: true,
expected: lambdaPatcher{
ARN: "arn",
PayloadPassthrough: true,
Region: "blah",
Kind: kind,
},
ok: true,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
ext := api.EnvoyExtension{
Name: structs.BuiltinAWSLambdaExtension,
Arguments: map[string]interface{}{
"ARN": tc.arn,
"Region": tc.region,
"PayloadPassthrough": tc.payloadPassthrough,
},
}
patcher, ok := makeLambdaPatcher(ext, kind)
require.Equal(t, tc.ok, ok)
if tc.ok {
require.Equal(t, tc.expected, patcher)
}
})
}
}