lambdatest

package
v1.76.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package lambdatest is a container-free end-to-end harness for the Lambda functions: an httptest server that speaks the Lambda Invoke API and routes FunctionName plus Qualifier to in-process lambdaapp.Function handlers.

The qualifier is what a deployment makes it: the alias `live-<class>` is the caller's identity (internal/modcall/lambdacall), so the emulator hands the handler an invoked-function ARN ending in the qualifier and the function derives the caller class from it exactly as it does on the platform. Nothing else about the caller reaches the function.

For tests only. State is the in-memory port, secrets are a small SSM fake (SSM), and GitHub is internal/githubapp/githubfake; no container runs.

Index

Constants

View Source
const (
	Region  = "test-region-1"
	Account = "111122223333"
)

Region and Account are what the emulator's ARNs carry.

View Source
const Instance = "acme"

Instance is the instance name the fixture's SSM root and functions carry.

View Source
const RecoveryPasswordParam = "/sluis/" + Instance + "/internal/oidc/recovery-password"

RecoveryPasswordParam is where layout v5 keeps the recovery password.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

type Call struct {
	Function  string
	Qualifier string
	// Class is the caller class the qualifier names (`live-issuer` is "issuer");
	// empty for `live` and for a qualifier that is no class.
	Class   string
	Payload []byte
}

Call is one invocation the emulator served.

type Emulator

type Emulator struct {
	// contains filtered or unexported fields
}

Emulator is the Lambda Invoke API over httptest.

func New

func New(t testing.TB) *Emulator

New starts an emulator with no function registered.

func (*Emulator) Calls

func (e *Emulator) Calls() []Call

Calls is every invocation served so far, in order.

func (*Emulator) Client

func (e *Emulator) Client() *awslambda.Client

Client is a Lambda client for the emulator: what the production transport (lambdacall.Caller, the run-now trigger) is given as its API.

func (*Emulator) Invoke

func (e *Emulator) Invoke(ctx context.Context, function, qualifier string, event []byte) (Result, error)

Invoke invokes function through qualifier with the event, over the wire.

func (*Emulator) Register

func (e *Emulator) Register(name string, fn *lambdaapp.Function)

Register makes fn the function name answers to. A name is the function's bare name; invoking by ARN reaches the same function.

func (*Emulator) URL

func (e *Emulator) URL() string

URL is the emulator's endpoint.

type Harness

type Harness struct {
	Emulator *Emulator
	SSM      *SSM
	// GitHub is the organisation githubfake serves. It points the GitHub client
	// at itself for the test's duration, so a test using the harness must not
	// run in parallel with another that does.
	GitHub *githubfake.Org
}

Harness is one installation, in process: the emulator, the SSM its functions read secrets from, and the GitHub organisation they talk to. State and blobs are the in-memory port.

func NewHarness

func NewHarness(t *testing.T) *Harness

NewHarness starts the emulator, the SSM fake (holding the fixture's declared secret) and the GitHub fake. It sets the environment the AWS SDK reads so that nothing reaches a real endpoint.

func (*Harness) IssuerDocument

func (h *Harness) IssuerDocument(t *testing.T) string

IssuerDocument writes the issuer's service document: layout v5 secrets in the harness's SSM, state and blobs in memory, and the run-now trigger in memory (the v1.76 scenarios replace it with the invoke trigger aimed at the emulator). It returns the file's path.

func (*Harness) OpenIssuer

func (h *Harness) OpenIssuer(t *testing.T) string

OpenIssuer assembles the issuer function from its document, as a cold start does, and registers it with the emulator as sluis-<instance>-issuer.

type Result

type Result struct {
	Payload       []byte
	FunctionError string
}

Result is what an invocation answered: the payload, and FunctionError when the function failed (the platform answers 200 with the error set).

type SSM

type SSM struct {
	// contains filtered or unexported fields
}

SSM is SSM Parameter Store over its wire protocol (JSON 1.1, the operation in X-Amz-Target), enough for the secrets reads a function makes: the real client, with its retryer, talks to it. Parameters are by full name.

func NewSSM

func NewSSM(t testing.TB, params map[string]string) *SSM

NewSSM starts a fake holding params.

func (*SSM) Delete

func (f *SSM) Delete(name string)

Delete removes a parameter.

func (*SSM) Put

func (f *SSM) Put(name, value string)

Put sets a parameter.

func (*SSM) Reads

func (f *SSM) Reads() []string

Reads are the parameters and paths asked for so far, in order, by whatever reached this fake: a test that gives each function its own fake can say what that function never read.

func (*SSM) ServeHTTP

func (f *SSM) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

func (*SSM) URL

func (f *SSM) URL() string

URL is the endpoint to put in a document's `secrets.endpoint`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL