2022-03-31 20:24:46 +00:00
|
|
|
package serverlessplugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-12-21 06:26:20 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2022-03-31 20:24:46 +00:00
|
|
|
"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
|
|
|
|
}{
|
|
|
|
{
|
2022-12-19 20:19:37 +00:00
|
|
|
name: "no extension",
|
|
|
|
ok: false,
|
2022-03-31 20:24:46 +00:00
|
|
|
},
|
|
|
|
{
|
2022-12-19 20:19:37 +00:00
|
|
|
name: "missing arn",
|
|
|
|
region: "blah",
|
|
|
|
ok: false,
|
2022-03-31 20:24:46 +00:00
|
|
|
},
|
|
|
|
{
|
2022-12-19 20:19:37 +00:00
|
|
|
name: "missing region",
|
|
|
|
arn: "arn",
|
|
|
|
ok: false,
|
2022-03-31 20:24:46 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "including payload passthrough",
|
|
|
|
arn: "arn",
|
|
|
|
region: "blah",
|
|
|
|
payloadPassthrough: true,
|
|
|
|
expected: lambdaPatcher{
|
2022-12-19 20:19:37 +00:00
|
|
|
ARN: "arn",
|
|
|
|
PayloadPassthrough: true,
|
|
|
|
Region: "blah",
|
|
|
|
Kind: kind,
|
2022-03-31 20:24:46 +00:00
|
|
|
},
|
|
|
|
ok: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2022-12-21 06:26:20 +00:00
|
|
|
ext := api.EnvoyExtension{
|
|
|
|
Name: structs.BuiltinAWSLambdaExtension,
|
|
|
|
Arguments: map[string]interface{}{
|
|
|
|
"ARN": tc.arn,
|
|
|
|
"Region": tc.region,
|
|
|
|
"PayloadPassthrough": tc.payloadPassthrough,
|
2022-03-31 20:24:46 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-12-21 06:26:20 +00:00
|
|
|
patcher, ok := makeLambdaPatcher(ext, kind)
|
2022-03-31 20:24:46 +00:00
|
|
|
|
|
|
|
require.Equal(t, tc.ok, ok)
|
|
|
|
|
2022-12-19 20:19:37 +00:00
|
|
|
if tc.ok {
|
|
|
|
require.Equal(t, tc.expected, patcher)
|
|
|
|
}
|
2022-03-31 20:24:46 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|