sdk

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package sdk provides an in-process AWS mock that routes AWS SDK v2 calls directly to CloudMock's gateway handler without any HTTP/TCP overhead.

Usage:

cm := sdk.New()
defer cm.Close()
cfg := cm.Config()
s3Client := s3.NewFromConfig(cfg, func(o *s3.Options) { o.UsePathStyle = true })

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChaosOption

type ChaosOption func(*chaosOpts)

ChaosOption configures a fault injection rule.

func WithLatency

func WithLatency(ms int) ChaosOption

WithLatency sets the added latency in milliseconds for "latency" faults.

func WithMessage

func WithMessage(msg string) ChaosOption

WithMessage sets the error message returned with the fault.

func WithPercentage

func WithPercentage(pct int) ChaosOption

WithPercentage sets the probability (0-100) that the fault fires on any given request.

func WithStatusCode

func WithStatusCode(code int) ChaosOption

WithStatusCode sets the HTTP status code returned for "error" faults.

type CloudMock

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

CloudMock is an in-process AWS mock. All AWS SDK calls routed through its Config() go directly to the gateway handler with zero network overhead.

func New

func New(opts ...Option) *CloudMock

New creates a new in-process CloudMock instance. By default it uses a minimal profile (S3, STS, DynamoDB, SQS) with IAM disabled for speed.

func (*CloudMock) ClearFaults

func (cm *CloudMock) ClearFaults() error

ClearFaults disables all chaos rules on the in-process engine.

func (*CloudMock) Close

func (cm *CloudMock) Close()

Close releases resources held by this CloudMock instance, including stopping background goroutines such as the DynamoDB TTL reaper. Safe to call multiple times; the underlying service closers are idempotent.

func (*CloudMock) Config

func (cm *CloudMock) Config() aws.Config

Config returns an aws.Config that routes all SDK calls through CloudMock in-process.

func (*CloudMock) InjectFault

func (cm *CloudMock) InjectFault(service, action, faultType string, opts ...ChaosOption) error

InjectFault adds a fault injection rule to the in-process chaos engine. faultType is one of "error", "latency", "timeout", "blackhole", or "throttle".

func (*CloudMock) TraceStore

func (cm *CloudMock) TraceStore() *gateway.TraceStore

TraceStore returns the trace store if tracing is enabled, or nil otherwise.

type Option

type Option func(*options)

Option configures a CloudMock instance.

func WithAccountID

func WithAccountID(id string) Option

WithAccountID sets the AWS account ID for the mock.

func WithIAMMode

func WithIAMMode(m string) Option

WithIAMMode sets the IAM enforcement mode ("none", "log", "enforce").

func WithProfile

func WithProfile(p string) Option

WithProfile sets the service profile ("minimal" or "standard").

func WithRegion

func WithRegion(r string) Option

WithRegion sets the AWS region for the mock.

func WithTracing

func WithTracing() Option

WithTracing enables always-on distributed tracing with W3C traceparent propagation. When enabled, a TraceStore is created and wired to the gateway, and the in-process transport propagates trace context from the Go context as traceparent headers.

type Recorder

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

Recorder is an http.RoundTripper that wraps another RoundTripper and captures all request/response pairs as traffic.CapturedEntry values. It is intended to be used with the AWS SDK v2 HTTP client for recording real AWS traffic.

func NewRecorder

func NewRecorder() *Recorder

NewRecorder creates a Recorder that wraps http.DefaultTransport.

func (*Recorder) Entries

func (r *Recorder) Entries() []*traffic.CapturedEntry

Entries returns a copy of the captured entries.

func (*Recorder) Recording

func (r *Recorder) Recording() *traffic.Recording

Recording converts the captured entries into a traffic.Recording.

func (*Recorder) RoundTrip

func (r *Recorder) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper. It captures the request and response as a CapturedEntry, then returns the original response unchanged.

func (*Recorder) SaveToFile

func (r *Recorder) SaveToFile(path string) error

SaveToFile marshals the recording to JSON and writes it to the given path.

func (*Recorder) Wrap

func (r *Recorder) Wrap(inner http.RoundTripper) *Recorder

Wrap sets the inner RoundTripper and returns the Recorder for chaining.

Directories

Path Synopsis
Package sdk provides helpers for building CloudMock plugins in Go.
Package sdk provides helpers for building CloudMock plugins in Go.

Jump to

Keyboard shortcuts

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