Files
floci/compatibility-tests/sdk-test-go/tests/lambda_test.go
T
TiM 38eb0125a9 refactor(test): narrow Lambda dispatch probe to transport-level exceptions (#395)
* refactor: narrow exception handling to transport-level failures only

The broad catch(Exception) in the Lambda dispatch probe and warmup
swallowed all errors, masking real service regressions as skipped tests.
Narrow to specific transport-level exceptions so only environment
unavailability (timeout, connection refused) triggers a skip:

- Java probe: SdkClientException + ConnectException (not all Exception)
- APIGW warmup: HttpTimeoutException + ConnectException
- Go invoke: net.Error via errors.As (not any error)

Unexpected service errors now propagate as test failures.

* fix: remove unreachable ConnectException catch in lambda probe

AWS SDK wraps all transport-level failures (ConnectException,
ApiCallTimeoutException, etc.) in SdkClientException, so the
separate ConnectException catch was unreachable and broke compilation.

* fix(compat): use unique_name in s3-notifications.bats to avoid parallel collisions

Parallel bats workers could share the same $(date +%s) timestamp,
producing identical bucket/queue/topic names. One worker's
put-bucket-notification-configuration would overwrite another's,
and the round-trip read would return zero filter rules. Switch to
unique_name which appends the shell PID.

* fix(compat): use unique_name in kms and ses bats to avoid parallel collisions

Same class of flake as s3-notifications.bats. Under --jobs 4, parallel
bats workers sharing a $(date +%s) timestamp produce identical alias
names (kms) and identity names (ses), causing cross-worker interference.
2026-04-13 21:49:26 -05:00

76 lines
2.2 KiB
Go

package tests
import (
"context"
"encoding/json"
"errors"
"net"
"testing"
"floci-sdk-test-go/internal/testutil"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/lambda"
lambdatypes "github.com/aws/aws-sdk-go-v2/service/lambda/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLambda(t *testing.T) {
ctx := context.Background()
svc := testutil.LambdaClient()
funcName := "go-test-func"
roleARN := "arn:aws:iam::000000000000:role/test-role"
t.Cleanup(func() {
svc.DeleteFunction(ctx, &lambda.DeleteFunctionInput{FunctionName: aws.String(funcName)})
})
t.Run("CreateFunction", func(t *testing.T) {
_, err := svc.CreateFunction(ctx, &lambda.CreateFunctionInput{
FunctionName: aws.String(funcName),
Runtime: lambdatypes.RuntimeNodejs18x,
Role: aws.String(roleARN),
Handler: aws.String("index.handler"),
Code: &lambdatypes.FunctionCode{ZipFile: testutil.MinimalZip()},
})
require.NoError(t, err)
})
t.Run("GetFunction", func(t *testing.T) {
r, err := svc.GetFunction(ctx, &lambda.GetFunctionInput{FunctionName: aws.String(funcName)})
require.NoError(t, err)
assert.Equal(t, funcName, aws.ToString(r.Configuration.FunctionName))
})
t.Run("ListFunctions", func(t *testing.T) {
r, err := svc.ListFunctions(ctx, &lambda.ListFunctionsInput{})
require.NoError(t, err)
assert.NotEmpty(t, r.Functions)
})
t.Run("Invoke", func(t *testing.T) {
payload, _ := json.Marshal(map[string]string{"name": "GoTest"})
r, err := svc.Invoke(ctx, &lambda.InvokeInput{
FunctionName: aws.String(funcName),
Payload: payload,
})
if err != nil {
// Only skip on transport-level failures (timeout, connection refused).
// Let unexpected service errors fail the test.
var netErr net.Error
if errors.As(err, &netErr) {
t.Skipf("Lambda REQUEST_RESPONSE dispatch unavailable (transport error): %v", err)
}
require.NoError(t, err)
}
assert.Equal(t, int32(200), r.StatusCode)
assert.Nil(t, r.FunctionError)
})
t.Run("DeleteFunction", func(t *testing.T) {
_, err := svc.DeleteFunction(ctx, &lambda.DeleteFunctionInput{FunctionName: aws.String(funcName)})
require.NoError(t, err)
})
}