mock

package
v0.0.0-...-69a3ef4 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: Apache-2.0 Imports: 17 Imported by: 1

Documentation

Overview

Package mock provides mock implementations of interfaces for testing purposes.

Index

Constants

This section is empty.

Variables

View Source
var GlobalSecretCache map[string]StoredSecret

GlobalSecretCache is a global secret storage cache that provides a simplified in-memory implementation of a secrets storage service. This can be used indirectly with the SecretsManagerClient to access and modify secrets, or used directly.

Functions

func ResetGlobalECSService

func ResetGlobalECSService()

ResetGlobalECSService resets the global fake ECS service back to an initialized but clean state.

func ResetGlobalSecretCache

func ResetGlobalSecretCache()

ResetGlobalSecretCache resets the global fake secret storage cache to an initialized but clean state.

Types

type ECSClient

type ECSClient struct {
	RegisterTaskDefinitionInput  *awsECS.RegisterTaskDefinitionInput
	RegisterTaskDefinitionOutput *awsECS.RegisterTaskDefinitionOutput
	RegisterTaskDefinitionError  error

	DescribeTaskDefinitionInput  *awsECS.DescribeTaskDefinitionInput
	DescribeTaskDefinitionOutput *awsECS.DescribeTaskDefinitionOutput
	DescribeTaskDefinitionError  error

	ListTaskDefinitionsInput  *awsECS.ListTaskDefinitionsInput
	ListTaskDefinitionsOutput *awsECS.ListTaskDefinitionsOutput
	ListTaskDefinitionsError  error

	DeregisterTaskDefinitionInput  *awsECS.DeregisterTaskDefinitionInput
	DeregisterTaskDefinitionOutput *awsECS.DeregisterTaskDefinitionOutput
	DeregisterTaskDefinitionError  error

	RunTaskInput  *awsECS.RunTaskInput
	RunTaskOutput *awsECS.RunTaskOutput
	RunTaskError  error

	DescribeTasksInput  *awsECS.DescribeTasksInput
	DescribeTasksOutput *awsECS.DescribeTasksOutput
	DescribeTasksError  error

	ListTasksInput  *awsECS.ListTasksInput
	ListTasksOutput *awsECS.ListTasksOutput
	ListTasksError  error

	StopTaskInput  *awsECS.StopTaskInput
	StopTaskOutput *awsECS.StopTaskOutput
	StopTaskError  error

	TagResourceInput  *awsECS.TagResourceInput
	TagResourceOutput *awsECS.TagResourceOutput
	TagResourceError  error

	CloseError error
}

ECSClient provides a mock implementation of a cocoa.ECSClient. This makes it possible to introspect on inputs to the client and control the client's output. It provides some default implementations where possible. By default, it will issue the API calls to the fake GlobalECSService.

func (*ECSClient) Close

func (c *ECSClient) Close(ctx context.Context) error

Close closes the mock client. The mock output can be customized. By default, it is a no-op that returns no error.

func (*ECSClient) DeregisterTaskDefinition

DeregisterTaskDefinition saves the input and deletes an existing mock task definition. The mock output can be customized. By default, it will delete a cached task definition if it exists.

func (*ECSClient) DescribeTaskDefinition

DescribeTaskDefinition saves the input and returns information about the matching task definition. The mock output can be customized. By default, it will return the task definition information if it exists.

func (*ECSClient) DescribeTasks

DescribeTasks saves the input and returns information about the existing tasks. The mock output can be customized. By default, it will describe all cached tasks that match.

func (*ECSClient) ListTaskDefinitions

ListTaskDefinitions saves the input and lists all matching task definitions. The mock output can be customized. By default, it will list all cached task definitions that match the input filters.

func (*ECSClient) ListTasks

ListTasks saves the input and lists all matching tasks. The mock output can be customized. By default, it will list all cached task definitions that match the input filters.

func (*ECSClient) RegisterTaskDefinition

RegisterTaskDefinition saves the input and returns a new mock task definition. The mock output can be customized. By default, it will create a cached task definition based on the input.

func (*ECSClient) RunTask

RunTask saves the input options and returns the mock result of running a task definition. The mock output can be customized. By default, it will create mock output based on the input.

func (*ECSClient) StopTask

StopTask saves the input and stops a mock task. The mock output can be customized. By default, it will mark a cached task as stopped if it exists and is running.

func (*ECSClient) TagResource

TagResource saves the input and tags a mock task or task definition. The mock output can be customized. By default, it will add the tag to the resource if it exists.

type ECSCluster

type ECSCluster map[string]ECSTask

ECSCluster represents a mock ECS cluster running tasks in the global ECS service.

type ECSContainer

type ECSContainer struct {
	ARN        string
	TaskARN    *string
	Name       *string
	Image      *string
	CPU        *int32
	MemoryMB   *int32
	Status     string
	GoalStatus string
}

ECSContainer represents a mock running ECS container within a task.

type ECSContainerDefinition

type ECSContainerDefinition struct {
	Name     *string
	Image    *string
	Command  []string
	MemoryMB *int32
	CPU      int32
	EnvVars  map[string]string
	Secrets  map[string]string
}

ECSContainerDefinition represents a mock ECS container definition in a mock ECS task definition.

type ECSPod

type ECSPod struct {
	cocoa.ECSPod

	ResourcesOutput *cocoa.ECSPodResources

	StatusInfoOutput *cocoa.ECSPodStatusInfo

	LatestStatusInfoOutput *cocoa.ECSPodStatusInfo
	LatestStatusInfoError  error

	StopError error

	DeleteError error
}

ECSPod provides a mock implementation of a cocoa.ECSPod backed by another ECS pod implementation.

func NewECSPod

func NewECSPod(p cocoa.ECSPod) *ECSPod

NewECSPod creates a mock ECS Pod backed by the given ECSPod.

func (*ECSPod) Delete

func (p *ECSPod) Delete(ctx context.Context) error

Delete deletes the mock pod and all of its underlying resources. The mock output can be customized. By default, it will return the result of the deleting the backing ECS pod.

func (*ECSPod) LatestStatusInfo

func (p *ECSPod) LatestStatusInfo(ctx context.Context) (*cocoa.ECSPodStatusInfo, error)

LatestStatusInfo returns the mock latest status information about the pod. The mock output can be customized. By default, it will return the result of the backing ECS pod.

func (*ECSPod) Resources

func (p *ECSPod) Resources() cocoa.ECSPodResources

Resources returns mock resource information about the pod. The mock output can be customized. By default, it will return the result of the backing ECS pod.

func (*ECSPod) StatusInfo

func (p *ECSPod) StatusInfo() cocoa.ECSPodStatusInfo

StatusInfo returns mock cached status information about the pod. The mock output can be customized. By default, it will return the result of the backing ECS pod.

func (*ECSPod) Stop

func (p *ECSPod) Stop(ctx context.Context) error

Stop stops the mock pod. The mock output can be customized. By default, it will return the result of stopping the backing ECS pod.

type ECSPodCreator

type ECSPodCreator struct {
	cocoa.ECSPodCreator

	CreatePodInput  []cocoa.ECSPodCreationOptions
	CreatePodOutput *cocoa.ECSPod
	CreatePodError  error

	CreatePodFromExistingDefinitionInput  []cocoa.ECSPodExecutionOptions
	CreatePodFromExistingDefinitionOutput *cocoa.ECSPod
	CreatePodFromExistingDefinitionError  error
}

ECSPodCreator provides a mock implementation of a cocoa.ECSPodCreator backed by another ECS pod creator implementation.

func NewECSPodCreator

func NewECSPodCreator(c cocoa.ECSPodCreator) *ECSPodCreator

NewECSPodCreator creates a mock ECS pod creator backed by the given pod creator.

func (*ECSPodCreator) CreatePod

func (m *ECSPodCreator) CreatePod(ctx context.Context, opts ...cocoa.ECSPodCreationOptions) (cocoa.ECSPod, error)

CreatePod saves the input and returns a new mock pod. The mock output can be customized. By default, it will return the result of creating the pod in the backing ECS pod creator.

func (*ECSPodCreator) CreatePodFromExistingDefinition

func (m *ECSPodCreator) CreatePodFromExistingDefinition(ctx context.Context, def cocoa.ECSTaskDefinition, opts ...cocoa.ECSPodExecutionOptions) (cocoa.ECSPod, error)

CreatePodFromExistingDefinition saves the input and returns a new mock pod. The mock output can be customized. By default, it will return the result of creating the pod in the backing ECS pod creator.

type ECSPodDefinitionCache

type ECSPodDefinitionCache struct {
	cocoa.ECSPodDefinitionCache

	PutInput *cocoa.ECSPodDefinitionItem
	PutError error

	DeleteInput *string
	DeleteError error

	Tag *string
}

ECSPodDefinitionCache provides a mock implementation of a cocoa.ECSPodDefinitionCache backed by another ECS pod definition cache implementation.

func NewECSPodDefinitionCache

func NewECSPodDefinitionCache(pdc cocoa.ECSPodDefinitionCache) *ECSPodDefinitionCache

NewECSPodDefinitionCache creates a mock ECS pod definition cache backed by the given pod definition cache.

func (*ECSPodDefinitionCache) Delete

func (c *ECSPodDefinitionCache) Delete(ctx context.Context, id string) error

Delete deletes the pod definition matching the identifier from the mock cache. The mock output can be customized. By default, it will return the result of deleting the pod definition from the backing ECS pod definition cache.

func (*ECSPodDefinitionCache) GetTag

func (c *ECSPodDefinitionCache) GetTag() string

GetTag returns the cache tracking tag. The mock output can be customized. By default, it will return the tag from the backing ECS pod definition cache.

func (*ECSPodDefinitionCache) Put

Put adds the item to the mock cache. The mock output can be customized. By default, it will return the result of putting the item in the backing ECS pod definition cache.

type ECSPodDefinitionManager

type ECSPodDefinitionManager struct {
	cocoa.ECSPodDefinitionManager

	CreatePodDefinitionInput  []cocoa.ECSPodDefinitionOptions
	CreatePodDefinitionOutput *cocoa.ECSPodDefinitionItem
	CreatePodDefinitionError  error

	DeletePodDefinitionInput *string
	DeletePodDefinitionError error
}

ECSPodDefinitionManager provides a mock implementation of a cocoa.ECSPodDefinitionManager backed by another ECS pod definition manager implementation.

func NewECSPodDefinitionManager

func NewECSPodDefinitionManager(m cocoa.ECSPodDefinitionManager) *ECSPodDefinitionManager

NewECSPodDefinitionManager creates a mock ECS pod definition manager backed by the given pod definition manager.

func (*ECSPodDefinitionManager) CreatePodDefinition

CreatePodDefinition saves the input and returns a new mock pod definition item. The mock output can be customized. By default, it will return the result of creating the pod definition in the backing ECS pod definition manager.

func (*ECSPodDefinitionManager) DeletePodDefinition

func (m *ECSPodDefinitionManager) DeletePodDefinition(ctx context.Context, id string) error

DeletePodDefinition saves the input and deletes the mock pod definition. The mock output can be customized. By default, it will return the result of deleting the pod definition from the backing ECS pod definition manager.

type ECSService

type ECSService struct {
	Clusters map[string]ECSCluster
	TaskDefs map[string][]ECSTaskDefinition
}

ECSService is a global implementation of ECS that provides a simplified in-memory implementation of the service that only stores metadata and does not orchestrate real containers or container instances. This can be used indirectly with the ECSClient to access or modify ECS resources, or used directly.

var GlobalECSService ECSService

GlobalECSService represents the global fake ECS service state.

type ECSTask

type ECSTask struct {
	ARN               string
	TaskDef           ECSTaskDefinition
	Cluster           *string
	CapacityProvider  *string
	ContainerInstance *string
	Containers        []ECSContainer
	Overrides         *types.TaskOverride
	Group             *string
	ExecEnabled       bool
	Status            string
	GoalStatus        string
	Created           *time.Time
	StopCode          string
	StopReason        *string
	Stopped           *time.Time
	Tags              map[string]string
}

ECSTask represents a mock running ECS task within a cluster.

type ECSTaskDefinition

type ECSTaskDefinition struct {
	ARN           string
	Family        *string
	Revision      *int64
	ContainerDefs []ECSContainerDefinition
	MemoryMB      *string
	CPU           *string
	TaskRole      *string
	ExecutionRole *string
	Tags          map[string]string
	Status        *string
	Registered    *time.Time
	Deregistered  *time.Time
}

ECSTaskDefinition represents a mock ECS task definition in the global ECS service.

type SecretCache

type SecretCache struct {
	cocoa.SecretCache

	PutInput *cocoa.SecretCacheItem
	PutError error

	DeleteInput *string
	DeleteError error

	Tag *string
}

SecretCache provides a mock implementation of a cocoa.SecretCache backed by another secret cache implementation.

func NewSecretCache

func NewSecretCache(sc cocoa.SecretCache) *SecretCache

NewSecretCache creates a mock secret cache backed by the given secret cache.

func (*SecretCache) Delete

func (c *SecretCache) Delete(ctx context.Context, id string) error

Delete removes the secret from the mock cache. The mock output can be customized. By default, it will return the result of deleting the secret from the backing secret cache.

func (*SecretCache) GetTag

func (c *SecretCache) GetTag() string

GetTag returns the cache tracking tag. The mock output can be customized. By default, it will return the tag from the backing secret cache.

func (*SecretCache) Put

Put adds the secret to the mock cache. The mock output can be customized. By default, it will return the result of putting the secret in the backing secret cache.

type SecretsManagerClient

type SecretsManagerClient struct {
	CreateSecretInput  *secretsmanager.CreateSecretInput
	CreateSecretOutput *secretsmanager.CreateSecretOutput
	CreateSecretError  error

	GetSecretValueInput  *secretsmanager.GetSecretValueInput
	GetSecretValueOutput *secretsmanager.GetSecretValueOutput
	GetSecretValueError  error

	DescribeSecretInput  *secretsmanager.DescribeSecretInput
	DescribeSecretOutput *secretsmanager.DescribeSecretOutput
	DescribeSecretError  error

	ListSecretsInput  *secretsmanager.ListSecretsInput
	ListSecretsOutput *secretsmanager.ListSecretsOutput
	ListSecretsError  error

	UpdateSecretInput  *secretsmanager.UpdateSecretInput
	UpdateSecretOutput *secretsmanager.UpdateSecretOutput
	UpdateSecretError  error

	DeleteSecretInput  *secretsmanager.DeleteSecretInput
	DeleteSecretOutput *secretsmanager.DeleteSecretOutput
	DeleteSecretError  error

	TagResourceInput  *secretsmanager.TagResourceInput
	TagResourceOutput *secretsmanager.TagResourceOutput
	TagResourceError  error

	CloseError error
}

SecretsManagerClient provides a mock implementation of a cocoa.SecretsManagerClient. This makes it possible to introspect on inputs to the client and control the client's output. It provides some default implementations where possible. By default, it will issue the API calls to the fake GlobalSecretCache.

func (*SecretsManagerClient) Close

func (c *SecretsManagerClient) Close(ctx context.Context) error

Close closes the mock client. The mock output can be customized. By default, it is a no-op that returns no error.

func (*SecretsManagerClient) CreateSecret

CreateSecret saves the input options and returns a new mock secret. The mock output can be customized. By default, it will create and save a cached mock secret based on the input in the global secret cache.

func (*SecretsManagerClient) DeleteSecret

DeleteSecret saves the input options and deletes an existing mock secret. The mock output can be customized. By default, it will delete a cached mock secret if it exists.

func (*SecretsManagerClient) DescribeSecret

DescribeSecret saves the input options and returns an existing mock secret's metadata information. The mock output can be customized. By default, it will return information about the cached mock secret if it exists in the global secret cache.

func (*SecretsManagerClient) GetSecretValue

GetSecretValue saves the input options and returns an existing mock secret's value. The mock output can be customized. By default, it will return a cached mock secret if it exists in the global secret cache.

func (*SecretsManagerClient) ListSecrets

ListSecrets saves the input options and returns all matching mock secrets' metadata information. The mock output can be customized. By default, it will return any matching cached mock secrets in the global secret cache.

func (*SecretsManagerClient) TagResource

TagResource saves the input options and tags an existing mock secret. The mock output can be customized. By default, it will tag the cached mock secret if it exists.

func (*SecretsManagerClient) UpdateSecretValue

UpdateSecretValue saves the input options and returns an updated mock secret value. The mock output can be customized. By default, it will update a cached mock secret if it exists in the global secret cache.

type StoredSecret

type StoredSecret struct {
	// For the sake of simplicity, the secret ARN is synonymous with the secret
	// name.
	Name         string
	Value        string
	BinaryValue  []byte
	IsDeleted    bool
	Created      time.Time
	LastUpdated  time.Time
	LastAccessed time.Time
	Deleted      time.Time
	Tags         map[string]string
}

StoredSecret is a representation of a secret kept in the global secret storage cache.

type TagClient

type TagClient struct {
	GetResourcesInput  *resourcegroupstaggingapi.GetResourcesInput
	GetResourcesOutput *resourcegroupstaggingapi.GetResourcesOutput
	GetResourcesError  error

	CloseError error
}

TagClient provides a mock implementation of a cocoa.TagClient. This makes it possible to introspect on inputs to the client and control the client's output. It provides some default implementations where possible. By default, it will issue the API calls to either the fake GlobalECSService for ECS or fake GlobalSecretCache for Secrets Manager.

func (*TagClient) Close

func (c *TagClient) Close(ctx context.Context) error

Close closes the mock client. The mock output can be customized. By default, it is a no-op that returns no error.

func (*TagClient) GetResources

GetResources saves the input and filters for the resources matching the input filters. The mock output can be customized. By default, it will search for matching secrets in Secrets Manager and task definitions in ECS.

type Vault

type Vault struct {
	cocoa.Vault

	CreateSecretInput  *cocoa.NamedSecret
	CreateSecretOutput *string
	CreateSecretError  error

	GetValueInput  *string
	GetValueOutput *string
	GetValueError  error

	UpdateValueInput *cocoa.NamedSecret
	UpdateValueError error

	DeleteSecretInput *string
	DeleteSecretError error
}

Vault provides a mock implementation of a cocoa.Vault backed by any vault by default. This makes it possible to introspect on inputs to the vault and control the vault's output. It provides some default implementations where possible.

func NewVault

func NewVault(v cocoa.Vault) *Vault

NewVault creates a mock Vault backed by the given Vault.

func (*Vault) CreateSecret

func (m *Vault) CreateSecret(ctx context.Context, s cocoa.NamedSecret) (id string, err error)

CreateSecret saves the input options and returns a mock secret ID. The mock output can be customized. By default, it will call the backing Vault implementation's CreateSecret.

func (*Vault) DeleteSecret

func (m *Vault) DeleteSecret(ctx context.Context, id string) error

DeleteSecret saves the input options and deletes an existing mock secret. The mock output can be customized. By default, it will call the backing Vault implementation's DeleteSecret.

func (*Vault) GetValue

func (m *Vault) GetValue(ctx context.Context, id string) (val string, err error)

GetValue saves the input options and returns an existing mock secret's value. The mock output can be customized. By default, it will call the backing Vault implementation's GetValue.

func (*Vault) UpdateValue

func (m *Vault) UpdateValue(ctx context.Context, s cocoa.NamedSecret) error

UpdateValue saves the input options and updates an existing mock secret. The mock output can be customized. By default, it will call the backing Vault implementation's UpdateValue.

Jump to

Keyboard shortcuts

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