mock

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 63 Imported by: 0

Documentation

Overview

Package mock provides mock implementations for AWS Cognito Provider

Index

Constants

This section is empty.

Variables

View Source
var HandlerMap = map[string]HandlerFunc{
	"test_bulk_container": testBulkContainerHandler,
}
View Source
var LambdaHandlerMap = make(map[string]LambdaHandler)
View Source
var MockLambdaClient = &LambdaMock{}

Functions

func CompareAttributeValues

func CompareAttributeValues(val1, val2 types.AttributeValue) int

CompareAttributeValues compares two DynamoDB attribute values Returns: -1 if val1 < val2, 0 if equal, 1 if val1 > val2

func ExtractKeys

func ExtractKeys(key map[string]types.AttributeValue, primaryKey, sortKey string) (string, string, error)

func IsEqual

func IsEqual(av1, av2 types.AttributeValue) bool

IsEqual checks if two DynamoDB attribute values are equal

func PrintAttributeValueMap

func PrintAttributeValueMap(av map[string]types.AttributeValue)

func PrintMap

func PrintMap(data map[string]interface{}, indent string)

Recursive function to print a map[string]interface{}

func SorN

func SorN(av types.AttributeValue) *string

Types

type AuthSession

type AuthSession struct {
	Username     string
	UserPoolID   string
	ClientID     string
	AccessToken  string
	RefreshToken string
	IDToken      string
	ExpiresAt    time.Time
}

AuthSession represents an active authentication session

type AwsMetadata

type AwsMetadata struct {
	Reported map[string]interface{} `json:"reported,omitempty"`
	Desired  map[string]interface{} `json:"desired,omitempty"`
}

type AwsNodeShadow

type AwsNodeShadow struct {
	State     *AwsShadowState `json:"state,omitempty"`
	Metadata  *AwsMetadata    `json:"metadata,omitempty"`
	Version   *int            `json:"version,omitempty"`
	Timestamp *int            `json:"timestamp,omitempty"`
}

type AwsShadowState

type AwsShadowState struct {
	Reported map[string]interface{} `json:"reported,omitempty"`
	Desired  map[string]interface{} `json:"desired,omitempty"`
}

type Certificate

type Certificate struct {
	Arn    string
	Status types.CertificateStatus
	Cert   string
}

type CognitoIdentityMock

type CognitoIdentityMock struct {

	// Map of Cognito tokens to Identity IDs
	TokenToIdentityMap map[string]string
	// Map of Identity IDs to Credentials
	IdentityToCredentialsMap map[string]*types.Credentials
	// Store the last GetId input for testing
	LastGetIdInput *cognitoidentity.GetIdInput
	// Store the last GetCredentialsForIdentity input for testing
	LastGetCredentialsInput *cognitoidentity.GetCredentialsForIdentityInput
	// contains filtered or unexported fields
}

func NewCognitoIdentityMock

func NewCognitoIdentityMock() *CognitoIdentityMock

func (*CognitoIdentityMock) AddCredentialsMapping

func (m *CognitoIdentityMock) AddCredentialsMapping(identityId string, credentials *types.Credentials)

Helper method to set up identity to credentials mappings for testing

func (*CognitoIdentityMock) AddTokenMapping

func (m *CognitoIdentityMock) AddTokenMapping(token, identityId string)

Helper method to set up token to identity mappings for testing

func (*CognitoIdentityMock) GetId

func (*CognitoIdentityMock) GetLastGetCredentialsInput

func (m *CognitoIdentityMock) GetLastGetCredentialsInput() *cognitoidentity.GetCredentialsForIdentityInput

GetLastGetCredentialsInput returns the last GetCredentialsForIdentityInput used in a GetCredentialsForIdentity call

type CognitoProviderMock

type CognitoProviderMock struct {

	// Pool and client management
	Pools map[string]map[string]cognitoidentityprovider.UpdateUserPoolClientInput // key: user_pool_id -> client_id

	// User state management
	Sessions map[string]map[string]map[string]*AuthSession // key: user_pool_id -> client_id -> access_token

	// Alias indexes for O(1) lookups (supporting Cognito aliases)
	Users        map[string]map[string]*UserState // key: user_pool_id -> username
	UsersByEmail map[string]map[string]*UserState // key: user_pool_id -> email -> user
	UsersByPhone map[string]map[string]*UserState // key: user_pool_id -> phone -> user

	// Error injection for testing
	DescribeUserPoolClientError    error
	UpdateUserPoolClientError      error
	SignUpError                    error
	ConfirmSignUpError             error
	InitiateAuthError              error
	IDTokenMinter                  func(user *UserState) string
	RespondToAuthChallengeError    error
	ForgotPasswordError            error
	ConfirmForgotPasswordError     error
	ChangePasswordError            error
	RevokeTokenError               error
	GetUserError                   error
	GlobalSignOutError             error
	AdminGetUserError              error
	AdminCreateUserError           error
	AdminSetUserPasswordError      error
	AdminUpdateUserAttributesError error
	ResendConfirmationCodeError    error

	// Configuration
	DefaultConfirmationCode string
	DefaultResetCode        string
	TokenExpirationMinutes  int
	DefaultUserPoolID       string
	// contains filtered or unexported fields
}

func NewCognitoProviderMock

func NewCognitoProviderMock() *CognitoProviderMock

NewCognitoProviderMock creates a new stateful Cognito provider mock

func (*CognitoProviderMock) AddTestUserDirect

func (m *CognitoProviderMock) AddTestUserDirect(userPoolID, username, email, password string, confirmed bool) *UserState

AddTestUserDirect adds a pre-configured user for testing

func (*CognitoProviderMock) AddTestUserPoolDirect

func (m *CognitoProviderMock) AddTestUserPoolDirect(userPoolID, clientID string)

func (*CognitoProviderMock) AdminCreateUser

AdminCreateUser creates a new user in Cognito user pool using admin privileges

func (*CognitoProviderMock) AdminGetUser

AdminGetUser retrieves user information using admin privileges

func (*CognitoProviderMock) AdminSetUserPassword

AdminSetUserPassword sets a permanent password for a user using admin privileges

func (*CognitoProviderMock) AdminUpdateUserAttributes

AdminUpdateUserAttributes updates user attributes using admin privileges

func (*CognitoProviderMock) ChangePassword

ChangePassword changes user password with stateful validation

func (*CognitoProviderMock) ConfirmForgotPassword

ConfirmForgotPassword completes password reset with stateful validation

func (*CognitoProviderMock) ConfirmSignUp

ConfirmSignUp confirms user signup with stateful validation Supports username, email, or phone as identifier (alias support)

func (*CognitoProviderMock) ForgotPassword

ForgotPassword initiates password reset with stateful code generation

func (*CognitoProviderMock) GetSessionByRefreshToken

func (m *CognitoProviderMock) GetSessionByRefreshToken(refreshToken string) *AuthSession

GetSessionByRefreshToken retrieves a session by refresh token

func (*CognitoProviderMock) GetSessionByToken

func (m *CognitoProviderMock) GetSessionByToken(token string) *AuthSession

GetSessionByToken retrieves a session by access token

func (*CognitoProviderMock) GetUser

GetUser retrieves user information using access token with stateful validation

func (*CognitoProviderMock) GetUserByUsername

func (m *CognitoProviderMock) GetUserByUsername(userPoolID, username string) *UserState

GetUserByUsername retrieves a user by username from a specific user pool

func (*CognitoProviderMock) GlobalSignOut

GlobalSignOut signs out user from all devices by deleting all their sessions

func (*CognitoProviderMock) InitiateAuth

InitiateAuth handles authentication with stateful session management Supports both USER_PASSWORD_AUTH and REFRESH_TOKEN_AUTH flows

func (*CognitoProviderMock) RegisterSessionForToken

func (m *CognitoProviderMock) RegisterSessionForToken(accessToken, userPoolID, clientID, username string) error

RegisterSessionForToken creates a session for a given access token This is useful for test scenarios where JWT tokens are created directly without going through InitiateAuth

func (*CognitoProviderMock) RespondToAuthChallenge

RespondToAuthChallenge handles authentication challenges with stateful tracking

func (*CognitoProviderMock) RevokeToken

RevokeToken revokes a refresh token by deleting the session

func (*CognitoProviderMock) SetErrorForMethod

func (m *CognitoProviderMock) SetErrorForMethod(method string, err error)

SetErrorForMethod sets an error to be returned by a specific method

func (*CognitoProviderMock) SignUp

SignUp creates a new user in the mock with stateful tracking

type DBItem

type DBItem map[string]types.AttributeValue

type DynamoDBMock

type DynamoDBMock struct {
	PutItemErr error
	// MaxPageItems caps how many items one Query returns, standing in for the service's 1 MB
	// page cap so tests can exercise a multi-page read. Zero (the default) means unlimited.
	MaxPageItems int

	// Returned once on the next matching call, then cleared.
	NextDescribeError error
	NextUpdateError   error
	NextGetItemError  error
	// If > 0, the next BatchGetItem call returns the last N keys as UnprocessedKeys
	// instead of processing them, then resets to 0.
	NextBatchGetUnprocessedCount int
	// If > 0, the next BatchWriteItem call returns the last N requests as UnprocessedItems
	// instead of applying them, then decrements by one so a caller that retries eventually
	// drains. The real service answers 200 with UnprocessedItems when it throttles part of a
	// batch, so without this the mock cannot express a partially-applied batch write and a
	// caller that discards the response looks correct.
	NextBatchWriteUnprocessedCount int
	// contains filtered or unexported fields
}

DynamoDBMock is a mock implementation of the DynamoDB interface

func NewDynamoDBMock

func NewDynamoDBMock() *DynamoDBMock

func (*DynamoDBMock) AddSecondaryIndex

func (m *DynamoDBMock) AddSecondaryIndex(indexName, tableName, primaryKey, sortKey string) error

func (*DynamoDBMock) AddTable

func (m *DynamoDBMock) AddTable(name, primaryKey string, sortKey string)

func (*DynamoDBMock) BatchGetItem

func (m *DynamoDBMock) BatchGetItem(ctx context.Context, params *dynamodb.BatchGetItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.BatchGetItemOutput, error)

func (*DynamoDBMock) BatchWriteItem

func (m *DynamoDBMock) BatchWriteItem(ctx context.Context, params *dynamodb.BatchWriteItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.BatchWriteItemOutput, error)

func (*DynamoDBMock) DeleteItem

func (m *DynamoDBMock) DeleteItem(ctx context.Context, params *dynamodb.DeleteItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.DeleteItemOutput, error)

func (*DynamoDBMock) DescribeTable

func (*DynamoDBMock) ForEachRow

func (m *DynamoDBMock) ForEachRow(table string, fn func(map[string]types.AttributeValue) error) error

ForEachRow iterates over all the rows in the DynamoDBMock and executes the closure fn

func (*DynamoDBMock) GSIStatus

func (m *DynamoDBMock) GSIStatus(table, indexName string) types.IndexStatus

func (*DynamoDBMock) GetDirect

func (m *DynamoDBMock) GetDirect(tableName, pkey, skey string, out interface{}) error

GetDirect returns the item from the DynamoDBMock without going through the GetItem API

func (*DynamoDBMock) GetItem

func (m *DynamoDBMock) GetItem(ctx context.Context, params *dynamodb.GetItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.GetItemOutput, error)

func (*DynamoDBMock) GetKeys

func (m *DynamoDBMock) GetKeys(item interface{}) (string, string, string, error)

func (*DynamoDBMock) HasGSI

func (m *DynamoDBMock) HasGSI(table, indexName string) bool

func (*DynamoDBMock) Print

func (m *DynamoDBMock) Print()

Print the contents of the DynamoDBMock

func (*DynamoDBMock) ProfileGet

func (m *DynamoDBMock) ProfileGet() Profile

func (*DynamoDBMock) ProfileReset

func (m *DynamoDBMock) ProfileReset()

func (*DynamoDBMock) PutDirect

func (m *DynamoDBMock) PutDirect(tableName, pkey, skey string, item interface{}) error

PutDirect puts the item into the DynamoDBMock without going through the PutItem API

func (*DynamoDBMock) PutItem

func (m *DynamoDBMock) PutItem(ctx context.Context, params *dynamodb.PutItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.PutItemOutput, error)

func (*DynamoDBMock) Query

func (m *DynamoDBMock) Query(ctx context.Context, params *dynamodb.QueryInput, optFns ...func(*dynamodb.Options)) (*dynamodb.QueryOutput, error)

func (*DynamoDBMock) QueryInternal

func (m *DynamoDBMock) QueryInternal(input *dynamodb.QueryInput) (*dynamodb.QueryOutput, error)

func (*DynamoDBMock) Scan

func (m *DynamoDBMock) Scan(ctx context.Context, params *dynamodb.ScanInput, optFns ...func(*dynamodb.Options)) (*dynamodb.ScanOutput, error)

func (*DynamoDBMock) ScanInternal

func (m *DynamoDBMock) ScanInternal(input *dynamodb.ScanInput) (*dynamodb.ScanOutput, error)

The real service leaves Scan order unspecified, but a cursor needs a stable position to resume from, so the mock scans in key order. Treat that order as an implementation detail: assert on the set a Scan returns, never on its sequence.

func (*DynamoDBMock) SetIndexProjection

func (m *DynamoDBMock) SetIndexProjection(indexName string, projection types.ProjectionType, nonKeyAttributes ...string) error

SetIndexProjection narrows what a query through the index returns. Indexes default to ALL, so a test only calls this when the real index is KEYS_ONLY or INCLUDE and the code under test must not see the unprojected attributes.

func (*DynamoDBMock) UpdateItem

func (m *DynamoDBMock) UpdateItem(ctx context.Context, input *dynamodb.UpdateItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.UpdateItemOutput, error)

func (*DynamoDBMock) UpdateTable

func (*DynamoDBMock) WithGSI

func (m *DynamoDBMock) WithGSI(table, indexName, hashKey, sortKey string, status types.IndexStatus) *DynamoDBMock

WithGSI: sortKey == "" for hash-only; projection is ALL. Use WithGSIDescription for non-default projection / NonKeyAttributes.

func (*DynamoDBMock) WithGSIDescription

func (m *DynamoDBMock) WithGSIDescription(table string, gsi types.GlobalSecondaryIndexDescription) *DynamoDBMock

func (*DynamoDBMock) WithTable

func (m *DynamoDBMock) WithTable(name string, status types.TableStatus) *DynamoDBMock

type ECSClientMock

type ECSClientMock struct{}

func NewECSClientMock

func NewECSClientMock() *ECSClientMock

func (*ECSClientMock) RunTask

func (m *ECSClientMock) RunTask(ctx context.Context, params *ecs.RunTaskInput, optFns ...func(*ecs.Options)) (*ecs.RunTaskOutput, error)

type HandlerFunc

type HandlerFunc func() error

type IndexDetails

type IndexDetails struct {
	TableName  string
	PrimaryKey string
	SortKey    string
	// Projection defaults to ALL; SetIndexProjection narrows it to what the real index would carry.
	Projection       types.ProjectionType
	NonKeyAttributes []string
}

IndexDetails is the key schema of a secondary index. The sort key can differ from the base table's, so a query through the index has to order and paginate by these, not by the table's.

type IoTClientMock

type IoTClientMock struct {
	// Key is the thing name
	Things map[string]Things
	// Key is the certificate ID
	Certificates map[string]Certificate
	// Track thing group memberships - Key is group name, value is list of thing names
	ThingGroups map[string][]string
	// Track thing group parent relationships - Key is child group name, value is parent group name
	ThingGroupParents map[string]string
	// Track policy attachments - Key is target (cert ARN), value is list of policy names
	AttachedPolicies map[string][]string
	// Track topic-rule payloads for the GetTopicRule / ReplaceTopicRule mock — Key is rule name
	TopicRules map[string]*types.TopicRulePayload

	// Error forcing flags
	ForceThingCreationError    bool
	ForcePolicyAttachmentError bool
	ForceGroupAdditionError    bool
	ForceGroupCreationError    bool
	ForceCertificateError      bool
	ForceCertAttachmentError   bool
	// contains filtered or unexported fields
}

func NewIoTClientMock

func NewIoTClientMock() *IoTClientMock

func (*IoTClientMock) AddThingToThingGroup

func (m *IoTClientMock) AddThingToThingGroup(ctx context.Context, params *iot.AddThingToThingGroupInput, optFns ...func(*iot.Options)) (*iot.AddThingToThingGroupOutput, error)

func (*IoTClientMock) AttachPolicy

func (m *IoTClientMock) AttachPolicy(ctx context.Context, params *iot.AttachPolicyInput, optFns ...func(*iot.Options)) (*iot.AttachPolicyOutput, error)

func (*IoTClientMock) AttachThingPrincipal

func (m *IoTClientMock) AttachThingPrincipal(ctx context.Context, params *iot.AttachThingPrincipalInput, optFns ...func(*iot.Options)) (*iot.AttachThingPrincipalOutput, error)

func (*IoTClientMock) CreateThing

func (m *IoTClientMock) CreateThing(ctx context.Context, params *iot.CreateThingInput, optFns ...func(*iot.Options)) (*iot.CreateThingOutput, error)

func (*IoTClientMock) CreateThingGroup

func (m *IoTClientMock) CreateThingGroup(ctx context.Context, params *iot.CreateThingGroupInput, optFns ...func(*iot.Options)) (*iot.CreateThingGroupOutput, error)

func (*IoTClientMock) DeleteCertificate

func (m *IoTClientMock) DeleteCertificate(ctx context.Context, params *iot.DeleteCertificateInput, optFns ...func(*iot.Options)) (*iot.DeleteCertificateOutput, error)

func (*IoTClientMock) DeleteThing

func (m *IoTClientMock) DeleteThing(ctx context.Context, params *iot.DeleteThingInput, optFns ...func(*iot.Options)) (*iot.DeleteThingOutput, error)

func (*IoTClientMock) DescribeCertificate

func (m *IoTClientMock) DescribeCertificate(ctx context.Context, params *iot.DescribeCertificateInput, optFns ...func(*iot.Options)) (*iot.DescribeCertificateOutput, error)

func (*IoTClientMock) DescribeThing

func (m *IoTClientMock) DescribeThing(ctx context.Context, params *iot.DescribeThingInput, optFns ...func(*iot.Options)) (*iot.DescribeThingOutput, error)

func (*IoTClientMock) DescribeThingGroup

func (m *IoTClientMock) DescribeThingGroup(ctx context.Context, params *iot.DescribeThingGroupInput, optFns ...func(*iot.Options)) (*iot.DescribeThingGroupOutput, error)

func (*IoTClientMock) DetachThingPrincipal

func (m *IoTClientMock) DetachThingPrincipal(ctx context.Context, params *iot.DetachThingPrincipalInput, optFns ...func(*iot.Options)) (*iot.DetachThingPrincipalOutput, error)

func (*IoTClientMock) FindCertificateByPEMDirect

func (m *IoTClientMock) FindCertificateByPEMDirect(certPEM string) (*Certificate, string, bool)

FindCertificateByPEMDirect finds a certificate by its PEM content

func (*IoTClientMock) GetAttachedPolicies

func (m *IoTClientMock) GetAttachedPolicies(target string) []string

GetAttachedPolicies returns the list of policy names attached to a target (cert ARN).

func (*IoTClientMock) GetCertificateDirect

func (m *IoTClientMock) GetCertificateDirect(certID string) (*Certificate, bool)

GetCertificateDirect retrieves a certificate by ID directly from the mock

func (*IoTClientMock) GetCertificatesDirect

func (m *IoTClientMock) GetCertificatesDirect() map[string]Certificate

GetCertificatesDirect returns all certificates in the mock

func (*IoTClientMock) GetThingAttributeDirect

func (m *IoTClientMock) GetThingAttributeDirect(thingName, attributeKey string) (string, bool)

GetThingAttributeDirect retrieves a specific attribute value for a thing

func (*IoTClientMock) GetThingDirect

func (m *IoTClientMock) GetThingDirect(thingName string) (*Things, bool)

GetThingDirect retrieves a thing directly from the mock

func (*IoTClientMock) GetThingGroupsDirect

func (m *IoTClientMock) GetThingGroupsDirect(thingName string) []string

GetThingGroupsDirect returns the groups that a thing belongs to

func (*IoTClientMock) GetThingsDirect

func (m *IoTClientMock) GetThingsDirect() map[string]Things

GetThingsDirect returns all things in the mock

func (*IoTClientMock) GetTopicRule

func (m *IoTClientMock) GetTopicRule(ctx context.Context, params *iot.GetTopicRuleInput, optFns ...func(*iot.Options)) (*iot.GetTopicRuleOutput, error)

func (*IoTClientMock) GetTopicRuleDirect

func (m *IoTClientMock) GetTopicRuleDirect(ruleName string) (*types.TopicRulePayload, bool)

GetTopicRuleDirect retrieves a stored topic rule payload by name.

func (*IoTClientMock) ListThingGroups

func (m *IoTClientMock) ListThingGroups(ctx context.Context, params *iot.ListThingGroupsInput, optFns ...func(*iot.Options)) (*iot.ListThingGroupsOutput, error)

func (*IoTClientMock) ListThingPrincipals

func (m *IoTClientMock) ListThingPrincipals(ctx context.Context, params *iot.ListThingPrincipalsInput, optFns ...func(*iot.Options)) (*iot.ListThingPrincipalsOutput, error)

func (*IoTClientMock) Print

func (m *IoTClientMock) Print()

func (*IoTClientMock) RegisterCertificateWithoutCA

func (m *IoTClientMock) RegisterCertificateWithoutCA(ctx context.Context, params *iot.RegisterCertificateWithoutCAInput, optFns ...func(*iot.Options)) (*iot.RegisterCertificateWithoutCAOutput, error)

func (*IoTClientMock) ReplaceTopicRule

func (m *IoTClientMock) ReplaceTopicRule(ctx context.Context, params *iot.ReplaceTopicRuleInput, optFns ...func(*iot.Options)) (*iot.ReplaceTopicRuleOutput, error)

func (*IoTClientMock) SetTopicRuleDirect

func (m *IoTClientMock) SetTopicRuleDirect(ruleName string, payload *types.TopicRulePayload)

SetTopicRuleDirect stores a topic rule payload by name for tests of the IoT-event-mode admin API.

func (*IoTClientMock) UpdateCertificate

func (m *IoTClientMock) UpdateCertificate(ctx context.Context, params *iot.UpdateCertificateInput, optFns ...func(*iot.Options)) (*iot.UpdateCertificateOutput, error)

func (*IoTClientMock) UpdateThing

func (m *IoTClientMock) UpdateThing(ctx context.Context, params *iot.UpdateThingInput, optFns ...func(*iot.Options)) (*iot.UpdateThingOutput, error)

func (*IoTClientMock) VerifyCertificateActive

func (m *IoTClientMock) VerifyCertificateActive(certPEM string) bool

VerifyCertificateActive checks if a certificate is active in the mock by PEM content

func (*IoTClientMock) VerifyCertificateExists

func (m *IoTClientMock) VerifyCertificateExists(certPEM string) bool

VerifyCertificateExists checks if a certificate exists in the mock by PEM content

func (*IoTClientMock) VerifyThingExists

func (m *IoTClientMock) VerifyThingExists(thingName string) bool

VerifyThingExists checks if a thing exists in the mock

func (*IoTClientMock) VerifyThingHasCertificate

func (m *IoTClientMock) VerifyThingHasCertificate(thingName string, certPEM string) bool

VerifyThingHasCertificate checks if a thing has a certificate attached

func (*IoTClientMock) VerifyThingInGroup

func (m *IoTClientMock) VerifyThingInGroup(thingName string, groupName string) bool

VerifyThingInGroup checks if a thing is in a specific group

func (*IoTClientMock) VerifyThingInGroups

func (m *IoTClientMock) VerifyThingInGroups(thingName string, groupNames []string) bool

VerifyThingInGroups checks if a thing is in all the specified groups

type IoTDataPlaneMock

type IoTDataPlaneMock struct {

	// Shadows stores the shadow data for each thing
	// The first key is the thing name, the second key is the shadow name
	Shadows map[string]map[string][]byte
	// PublishCalls stores the parameters of Publish calls
	PublishCalls []iotdataplane.PublishInput
	// contains filtered or unexported fields
}

IoTDataPlaneMock is a mock implementation of the IoT Data Plane client

func NewIoTDataPlaneMock

func NewIoTDataPlaneMock() *IoTDataPlaneMock

NewIoTDataPlaneMock creates a new IoTDataPlaneMock

func (*IoTDataPlaneMock) AddDirect

func (m *IoTDataPlaneMock) AddDirect(thingName, shadowName string, payload []byte)

AddDirect directly adds a shadow to the mock storage

func (*IoTDataPlaneMock) DeleteThingShadow

func (*IoTDataPlaneMock) GetDirect

func (m *IoTDataPlaneMock) GetDirect(thingName, shadowName string) ([]byte, error)

GetDirect directly retrieves a shadow from the mock storage

func (*IoTDataPlaneMock) GetNamedShadowNames

func (m *IoTDataPlaneMock) GetNamedShadowNames(thingName string) []string

func (*IoTDataPlaneMock) GetThingShadow

GetThingShadow mocks the GetThingShadow operation

func (*IoTDataPlaneMock) Print

func (m *IoTDataPlaneMock) Print()

func (*IoTDataPlaneMock) Publish

Publish mocks the Publish operation

func (*IoTDataPlaneMock) UpdateThingShadow

UpdateThingShadow mocks the UpdateThingShadow operation

func (*IoTDataPlaneMock) VerifyTags

func (m *IoTDataPlaneMock) VerifyTags(nodeID string, adminTags, deviceTags, userTags map[string]string) bool

type KVSClientMock

type KVSClientMock struct {
	// Key is the channel name
	Channels map[string]SignalingChannel

	// Error forcing flags
	ForceCreateError   bool
	ForceDescribeError bool
	// contains filtered or unexported fields
}

func NewKVSClientMock

func NewKVSClientMock() *KVSClientMock

func (*KVSClientMock) CreateSignalingChannel

func (*KVSClientMock) GetChannelDirect

func (m *KVSClientMock) GetChannelDirect(channelName string) (*SignalingChannel, bool)

GetChannelDirect retrieves a channel directly from the mock for testing

type LambdaHandler

type LambdaHandler func(ctx context.Context, payload []byte) ([]byte, error)

type LambdaMock

type LambdaMock struct {
	AddPermissionError    error
	RemovePermissionError error
	Permissions           map[string]lambda.AddPermissionInput
	InvokeError           error
	InvokeCalls           []lambda.InvokeInput
}

func NewLambdaMock

func NewLambdaMock() *LambdaMock

func (*LambdaMock) AddPermission

func (m *LambdaMock) AddPermission(ctx context.Context, params *lambda.AddPermissionInput, optFns ...func(*lambda.Options)) (*lambda.AddPermissionOutput, error)

func (*LambdaMock) Invoke

func (m *LambdaMock) Invoke(ctx context.Context, params *lambda.InvokeInput, optFns ...func(*lambda.Options)) (*lambda.InvokeOutput, error)

func (*LambdaMock) RemovePermission

func (m *LambdaMock) RemovePermission(ctx context.Context, params *lambda.RemovePermissionInput, optFns ...func(*lambda.Options)) (*lambda.RemovePermissionOutput, error)

type Mexpression

type Mexpression struct {
	// This could be a KeyCondition, Filter, UpdateExpr or a Projection :-/ maybe we need to split this up
	Expr   *string
	Names  map[string]string
	Values map[string]types.AttributeValue
	// contains filtered or unexported fields
}

We simply need to define ways to 'evaluate' the expression for a given AttributeValue

func NewMexpression

func NewMexpression(Expr *string,
	Names map[string]string,
	Values map[string]types.AttributeValue) *Mexpression

NewMexpression creates a new mock expression

func (*Mexpression) Evaluate

func (e *Mexpression) Evaluate(av map[string]types.AttributeValue) (bool, error)

Evaluate reports whether the item satisfies the condition. An expression the parser cannot handle is an error, never a silent true: a predicate that matches every row turns a filtered read into an unfiltered one that still looks successful.

func (*Mexpression) GetNamesList

func (e *Mexpression) GetNamesList() []string

GetNamesList returns the list of names in the expression, if the expression is a NamesList

func (*Mexpression) PinsPartitionKey

func (e *Mexpression) PinsPartitionKey(partitionKey string) bool

PinsPartitionKey reports whether the key condition fixes the partition key with "=", which DynamoDB requires of every Query. Without it a Query would be a scan, and the service rejects the request rather than running it.

func (*Mexpression) ProcessUpdate

func (e *Mexpression) ProcessUpdate(f func(UpdateOp, string, types.AttributeValue)) error

ProcessUpdate processes the update expression, if the expression is an UpdateExpr The function f is called for each update operation, with the operation type, the name of the attribute and the value In the case of 'Set', the function is repeatedly called for every attribute being set, and a 'SetDone' is called to indicate that all 'Set' operations are done

syntax:

update-expression ::=

[ SET action [, action] ... ]
[ REMOVE action [, action] ...]
[ ADD action [, action] ... ]
[ DELETE action [, action] ...]

type MockHTTPClient

type MockHTTPClient struct {
	Requests []*http.Request
	// contains filtered or unexported fields
}

MockHTTPClient is a mock implementation of the HTTPClient interface

func NewMockHTTPClient

func NewMockHTTPClient() *MockHTTPClient

NewMockHTTPClient creates a new instance of MockHTTPClient with an empty response map

func (*MockHTTPClient) Do

func (c *MockHTTPClient) Do(req *http.Request) (*http.Response, error)

Do is a dummy implementation for the Do method

func (*MockHTTPClient) Get

func (c *MockHTTPClient) Get(url string) (*http.Response, error)

Get is a dummy implementation for the Get method

func (*MockHTTPClient) Head

func (c *MockHTTPClient) Head(url string) (*http.Response, error)

Head is a dummy implementation for the Head method

func (*MockHTTPClient) Post

func (c *MockHTTPClient) Post(url string, bodyType string, body io.Reader) (*http.Response, error)

Post is a dummy implementation for the Post method

func (*MockHTTPClient) PostForm

func (c *MockHTTPClient) PostForm(url string, values url.Values) (*http.Response, error)

PostForm is a dummy implementation for the PostForm method

func (*MockHTTPClient) RegisterResponse

func (c *MockHTTPClient) RegisterResponse(url, method string, statusCode int, responseBody interface{}) error

RegisterResponse registers a response for a specific URL and HTTP method

type MockKMS

type MockKMS struct {

	// Call capture, so tests can assert the signing parameters rather than
	// trusting that the right algorithm was requested.
	SignCalls []kms.SignInput

	SignError         error
	GetPublicKeyError error
	// contains filtered or unexported fields
}

MockKMS emulates the two KMS calls the signers use, backed by a real in-memory key per key ID: P-256 for certificates, RSA for tokens.

It signs for real rather than returning a canned blob: the issuer's output is an X.509 certificate, and a certificate signed with a fake signature cannot be verified. Real signing lets tests assert what actually matters — that the issued chain verifies — instead of only that some bytes were produced.

func NewMockKMS

func NewMockKMS() *MockKMS

func NewMockRSAKMS

func NewMockRSAKMS(keyID string) (*MockKMS, *rsa.PrivateKey)

NewMockRSAKMS returns a mock holding one freshly generated RSA key under keyID, alongside the key itself so a caller can build the JWKS this mock will sign against.

func (*MockKMS) AddKey

func (m *MockKMS) AddKey(keyID string) *ecdsa.PrivateKey

AddKey creates an ECDSA P-256 key under keyID and returns it, so a test can independently verify signatures the mock produced.

func (*MockKMS) AddRSAKeyWith

func (m *MockKMS) AddRSAKeyWith(keyID string, key *rsa.PrivateKey) *rsa.PrivateKey

AddRSAKeyWith registers an RSA key under keyID, generating one when key is nil. A caller that passes its own key can verify signatures against a JWKS it already holds.

func (*MockKMS) GetPublicKey

func (m *MockKMS) GetPublicKey(ctx context.Context, params *kms.GetPublicKeyInput, optFns ...func(*kms.Options)) (*kms.GetPublicKeyOutput, error)

func (*MockKMS) Sign

func (m *MockKMS) Sign(ctx context.Context, params *kms.SignInput, optFns ...func(*kms.Options)) (*kms.SignOutput, error)

type MockS3PresignClient

type MockS3PresignClient struct {
}

MockS3PresignClient is a mock implementation of the S3PresignClientInterface

func NewS3PresignClientMock

func NewS3PresignClientMock() *MockS3PresignClient

func (*MockS3PresignClient) PresignGetObject

func (m *MockS3PresignClient) PresignGetObject(ctx context.Context, input *s3.GetObjectInput, optFns ...func(*s3.PresignOptions)) (*v4.PresignedHTTPRequest, error)

PresignGetObject mocks the PresignGetObject method. Unlike the put path it does not touch the object store — signing a download URL is a read-only operation and does not require the object to already exist in the mock.

func (*MockS3PresignClient) PresignPutObject

func (m *MockS3PresignClient) PresignPutObject(ctx context.Context, input *s3.PutObjectInput, optFns ...func(*s3.PresignOptions)) (*v4.PresignedHTTPRequest, error)

PresignPutObject mocks the PresignPutObject method

type MockSES

type MockSES struct {
	Identities              map[string]types.IdentityInfo
	SentEmails              []*sesv2.SendEmailInput
	ProductionAccessEnabled bool
	ReviewPending           bool

	SendEmailError           error
	CreateEmailIdentityError error
	GetEmailIdentityError    error
	ListEmailIdentitiesError error
	DeleteEmailIdentityError error
	GetAccountError          error
	PutAccountDetailsError   error
	// contains filtered or unexported fields
}

MockSES is an in-memory SESClientInterface for tests; SendEmail is a no-op recorder.

func NewMockSES

func NewMockSES() *MockSES

func (*MockSES) CreateEmailIdentity

func (m *MockSES) CreateEmailIdentity(ctx context.Context, params *sesv2.CreateEmailIdentityInput, optFns ...func(*sesv2.Options)) (*sesv2.CreateEmailIdentityOutput, error)

func (*MockSES) DeleteEmailIdentity

func (m *MockSES) DeleteEmailIdentity(ctx context.Context, params *sesv2.DeleteEmailIdentityInput, optFns ...func(*sesv2.Options)) (*sesv2.DeleteEmailIdentityOutput, error)

func (*MockSES) GetAccount

func (m *MockSES) GetAccount(ctx context.Context, params *sesv2.GetAccountInput, optFns ...func(*sesv2.Options)) (*sesv2.GetAccountOutput, error)

func (*MockSES) GetEmailIdentity

func (m *MockSES) GetEmailIdentity(ctx context.Context, params *sesv2.GetEmailIdentityInput, optFns ...func(*sesv2.Options)) (*sesv2.GetEmailIdentityOutput, error)

func (*MockSES) ListEmailIdentities

func (m *MockSES) ListEmailIdentities(ctx context.Context, params *sesv2.ListEmailIdentitiesInput, optFns ...func(*sesv2.Options)) (*sesv2.ListEmailIdentitiesOutput, error)

func (*MockSES) PutAccountDetails

func (m *MockSES) PutAccountDetails(ctx context.Context, params *sesv2.PutAccountDetailsInput, optFns ...func(*sesv2.Options)) (*sesv2.PutAccountDetailsOutput, error)

func (*MockSES) SendEmail

func (m *MockSES) SendEmail(ctx context.Context, params *sesv2.SendEmailInput, optFns ...func(*sesv2.Options)) (*sesv2.SendEmailOutput, error)

func (*MockSES) SetVerified

func (m *MockSES) SetVerified(identity string)

SetVerified simulates the owner following SES's verification link.

type MockSSM

type MockSSM struct {
	Parameters        map[string]*types.Parameter
	DeletedParameters []string

	PutParameterError error
	// GetParameterError fails every read; GetParameterErrors fails only the named parameters, for
	// tests that must break one read while leaving the rest of a handler's SSM reads working.
	GetParameterError        error
	GetParameterErrors       map[string]error
	GetParametersByPathError error
	DeleteParameterError     error
	// contains filtered or unexported fields
}

func NewMockSSM

func NewMockSSM() *MockSSM

func (*MockSSM) DeleteParameter

func (m *MockSSM) DeleteParameter(ctx context.Context, params *ssm.DeleteParameterInput, optFns ...func(*ssm.Options)) (*ssm.DeleteParameterOutput, error)

func (*MockSSM) GetParameter

func (m *MockSSM) GetParameter(ctx context.Context, params *ssm.GetParameterInput, optFns ...func(*ssm.Options)) (*ssm.GetParameterOutput, error)

func (*MockSSM) GetParametersByPath

func (m *MockSSM) GetParametersByPath(ctx context.Context, params *ssm.GetParametersByPathInput, optFns ...func(*ssm.Options)) (*ssm.GetParametersByPathOutput, error)

func (*MockSSM) PutParameter

func (m *MockSSM) PutParameter(ctx context.Context, params *ssm.PutParameterInput, optFns ...func(*ssm.Options)) (*ssm.PutParameterOutput, error)

type Profile

type Profile struct {

	// For every table, the read/write counts and the operations performed on it
	Accesses map[string]struct {
		ReadCount  int
		WriteCount int
		Operations []ProfileOperation
	}
	// contains filtered or unexported fields
}

func NewProfile

func NewProfile() *Profile

func (*Profile) AddAction

func (p *Profile) AddAction(table string, action string, operation string, details string, size int)

func (*Profile) AddRead

func (p *Profile) AddRead(table string, operation string, details string, size int)

func (*Profile) AddWrite

func (p *Profile) AddWrite(table string, operation string, details string, size int)

func (*Profile) Print

func (p *Profile) Print(w io.Writer)

func (*Profile) Reset

func (p *Profile) Reset()

func (*Profile) TotalCounts

func (p *Profile) TotalCounts() (int, int)

type ProfileOperation

type ProfileOperation struct {
	Name    string
	Details string
	Size    int
}

type S3ClientMock

type S3ClientMock struct {
	PresignClient awscommon.S3PresignClientInterface
	Buckets       map[string]map[string]any //map of bucket name to map of key to object
	// ForcePutObjectErr, when non-nil, makes every PutObject return it.
	// Lets tests exercise write-failure paths (e.g. the container's
	// non-fatal failed-nodes CSV write) without an HTTP layer.
	ForcePutObjectErr error
}

func NewS3ClientMock

func NewS3ClientMock() *S3ClientMock

func (*S3ClientMock) CreateBucketDirect

func (m *S3ClientMock) CreateBucketDirect(bucketName string)

func (*S3ClientMock) GetObject

func (m *S3ClientMock) GetObject(ctx context.Context, input *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)

func (*S3ClientMock) GetPresignClient

func (m *S3ClientMock) GetPresignClient() awscommon.S3PresignClientInterface

GetPresignClient returns a mock presign client

func (*S3ClientMock) ListBuckets

func (m *S3ClientMock) ListBuckets(ctx context.Context, input *s3.ListBucketsInput, optFns ...func(*s3.Options)) (*s3.ListBucketsOutput, error)

func (*S3ClientMock) PutObject

func (m *S3ClientMock) PutObject(ctx context.Context, input *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)

type SNSMock

type SNSMock struct {
	PublishedMessages                     []*sns.PublishInput
	CreatePlatformApplicationCalls        []*sns.CreatePlatformApplicationInput
	CreatedPlatformEndpointCalls          []*sns.CreatePlatformEndpointInput
	DeleteEndpointCalls                   []*sns.DeleteEndpointInput
	ListPlatformApplicationsCalls         []*sns.ListPlatformApplicationsInput
	SetPlatformApplicationAttributesCalls []*sns.SetPlatformApplicationAttributesInput
	DeletePlatformApplicationCalls        []*sns.DeletePlatformApplicationInput
	GetPlatformApplicationAttributesCalls []*sns.GetPlatformApplicationAttributesInput

	PublishError                          error
	CreatePlatformApplicationError        error
	CreatePlatformEndpointError           error
	DeleteEndpointError                   error
	ListPlatformApplicationsError         error
	SetPlatformApplicationAttributesError error
	DeletePlatformApplicationError        error
	GetPlatformApplicationAttributesError error
	MockPlatformApplications              []types.PlatformApplication
	PlatformAttributes                    map[string]map[string]string
	// contains filtered or unexported fields
}

SNSMock is a mock implementation of the SNS client

func NewSNSMock

func NewSNSMock() *SNSMock

NewSNSMock creates a new SNS mock

func (*SNSMock) ClearPublishedMessages

func (m *SNSMock) ClearPublishedMessages()

ClearPublishedMessages clears all published messages

func (*SNSMock) CreatePlatformApplication

func (m *SNSMock) CreatePlatformApplication(ctx context.Context, params *sns.CreatePlatformApplicationInput, optFns ...func(*sns.Options)) (*sns.CreatePlatformApplicationOutput, error)

CreatePlatformApplication mocks the CreatePlatformApplication method of the SNS client

func (*SNSMock) CreatePlatformEndpoint

func (m *SNSMock) CreatePlatformEndpoint(ctx context.Context, params *sns.CreatePlatformEndpointInput, optFns ...func(*sns.Options)) (*sns.CreatePlatformEndpointOutput, error)

CreatePlatformEndpoint mocks the CreatePlatformEndpoint method of the SNS client

func (*SNSMock) DeleteEndpoint

func (m *SNSMock) DeleteEndpoint(ctx context.Context, params *sns.DeleteEndpointInput, optFns ...func(*sns.Options)) (*sns.DeleteEndpointOutput, error)

DeleteEndpoint mocks the DeleteEndpoint method of the SNS client

func (*SNSMock) DeletePlatformApplication

func (m *SNSMock) DeletePlatformApplication(ctx context.Context, params *sns.DeletePlatformApplicationInput, optFns ...func(*sns.Options)) (*sns.DeletePlatformApplicationOutput, error)

DeletePlatformApplication mocks the DeletePlatformApplication method of the SNS client

func (*SNSMock) GetCreatePlatformApplicationCalls

func (m *SNSMock) GetCreatePlatformApplicationCalls() []*sns.CreatePlatformApplicationInput

GetCreatePlatformApplicationCalls returns all CreatePlatformApplication calls

func (*SNSMock) GetCreatePlatformEndpointCalls

func (m *SNSMock) GetCreatePlatformEndpointCalls() []*sns.CreatePlatformEndpointInput

GetCreatePlatformEndpointCalls returns all CreatePlatformEndpoint calls

func (*SNSMock) GetDeleteEndpointCalls

func (m *SNSMock) GetDeleteEndpointCalls() []*sns.DeleteEndpointInput

GetDeleteEndpointCalls returns all DeleteEndpoint calls

func (*SNSMock) GetDeletePlatformApplicationCalls

func (m *SNSMock) GetDeletePlatformApplicationCalls() []*sns.DeletePlatformApplicationInput

GetDeletePlatformApplicationCalls returns all DeletePlatformApplication calls

func (*SNSMock) GetListPlatformApplicationsCalls

func (m *SNSMock) GetListPlatformApplicationsCalls() []*sns.ListPlatformApplicationsInput

GetListPlatformApplicationsCalls returns all ListPlatformApplications calls

func (*SNSMock) GetPlatformApplicationAttributes

func (m *SNSMock) GetPlatformApplicationAttributes(ctx context.Context, params *sns.GetPlatformApplicationAttributesInput, optFns ...func(*sns.Options)) (*sns.GetPlatformApplicationAttributesOutput, error)

GetPlatformApplicationAttributes mocks the GetPlatformApplicationAttributes method of the SNS client

func (*SNSMock) GetPublishedMessages

func (m *SNSMock) GetPublishedMessages() []*sns.PublishInput

GetPublishedMessages returns all published messages

func (*SNSMock) GetSetPlatformApplicationAttributesCalls

func (m *SNSMock) GetSetPlatformApplicationAttributesCalls() []*sns.SetPlatformApplicationAttributesInput

GetSetPlatformApplicationAttributesCalls returns all SetPlatformApplicationAttributes calls

func (*SNSMock) ListPlatformApplications

func (m *SNSMock) ListPlatformApplications(ctx context.Context, params *sns.ListPlatformApplicationsInput, optFns ...func(*sns.Options)) (*sns.ListPlatformApplicationsOutput, error)

ListPlatformApplications mocks the ListPlatformApplications method of the SNS client

func (*SNSMock) Publish

func (m *SNSMock) Publish(ctx context.Context, params *sns.PublishInput, optFns ...func(*sns.Options)) (*sns.PublishOutput, error)

Publish mocks the Publish method of the SNS client

func (*SNSMock) SetListPlatformApplicationsError

func (m *SNSMock) SetListPlatformApplicationsError(err error)

SetListPlatformApplicationsError sets an error to be returned by ListPlatformApplications

func (*SNSMock) SetMockPlatformApplications

func (m *SNSMock) SetMockPlatformApplications(apps []types.PlatformApplication)

SetMockPlatformApplications sets the mock platform applications to be returned

func (*SNSMock) SetPlatformApplicationAttributes

func (m *SNSMock) SetPlatformApplicationAttributes(ctx context.Context, params *sns.SetPlatformApplicationAttributesInput, optFns ...func(*sns.Options)) (*sns.SetPlatformApplicationAttributesOutput, error)

SetPlatformApplicationAttributes mocks the SetPlatformApplicationAttributes method of the SNS client

func (*SNSMock) SetPublishError

func (m *SNSMock) SetPublishError(err error)

SetPublishError sets an error to be returned by Publish

type STSMock

type STSMock struct {
	AccountID string

	// AssumeRoleError, when set, is returned by AssumeRole instead of creds —
	// used to exercise a handler's AssumeRole error path.
	AssumeRoleError error
	// contains filtered or unexported fields
}

func NewSTSMock

func NewSTSMock() *STSMock

func (*STSMock) AssumeRole

func (m *STSMock) AssumeRole(ctx context.Context, params *sts.AssumeRoleInput, optFns ...func(*sts.Options)) (*sts.AssumeRoleOutput, error)

func (*STSMock) GetCallerIdentity

func (m *STSMock) GetCallerIdentity(ctx context.Context, params *sts.GetCallerIdentityInput, optFns ...func(*sts.Options)) (*sts.GetCallerIdentityOutput, error)

func (*STSMock) GetLastAssumeRoleInput

func (m *STSMock) GetLastAssumeRoleInput() *sts.AssumeRoleInput

GetLastAssumeRoleInput returns the last AssumeRoleInput used in an AssumeRole call

type SignalingChannel

type SignalingChannel struct {
	ChannelName string
	ChannelARN  string
	ChannelType kvs_types.ChannelType
}

type TableDetails

type TableDetails struct {
	PrimaryKey string
	SortKey    string
	Status     types.TableStatus
	GSIs       map[string]*types.GlobalSecondaryIndexDescription
}

type Things

type Things struct {
	Name           string
	CertificateIds []string
	// Track group memberships
	Groups []string
	// Track thing attributes (e.g. "group_id")
	Attributes map[string]string
}

type UpdateOp

type UpdateOp int
const (
	Set UpdateOp = iota + 1
	SetDone
	Delete
	Add
	ListAppend
	ListRemove
)

type UserState

type UserState struct {
	Username         string
	Email            string
	PhoneNumber      string
	Password         string
	UserSub          string
	UserPoolID       string
	IsConfirmed      bool
	IsEnabled        bool
	CreatedAt        time.Time
	LastLoginAt      *time.Time
	Attributes       map[string]string
	ConfirmationCode string
	ResetCode        string
}

UserState represents the current state of a user in the mock

Jump to

Keyboard shortcuts

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