mocks

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: May 19, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package mocks provides mock implementations for external services and APIs used in testing

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultDropletID1    = 12345
	DefaultDropletID2    = 12346
	DefaultDropletName1  = "test-droplet-1"
	DefaultDropletName2  = "test-droplet-2"
	DefaultDropletIP1    = "192.0.2.1"
	DefaultDropletIP2    = "192.0.2.2"
	DefaultDropletRegion = "nyc1"
	DefaultDropletSize   = "s-1vcpu-1gb"
	DefaultDropletStatus = "active"

	DefaultDropletList = []struct {
		ID   int
		Name string
		IP   string
	}{
		{DefaultDropletID1, DefaultDropletName1, DefaultDropletIP1},
		{DefaultDropletID2, DefaultDropletName2, DefaultDropletIP2},
	}
)

Default test values for droplets

View Source
var (
	DefaultKeyID1        = 67890
	DefaultKeyID2        = 67891
	DefaultKeyName1      = "test-key"
	DefaultKeyName2      = "test-key-2"
	DefaultKeyPublicKey1 = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC..."
	DefaultKeyPublicKey2 = "ssh-rsa BBBBB3NzaC1yc2EAAAADAQABAAABAQC..."

	DefaultKeyList = []struct {
		ID        int
		Name      string
		PublicKey string
	}{
		{DefaultKeyID1, DefaultKeyName1, DefaultKeyPublicKey1},
		{DefaultKeyID2, DefaultKeyName2, DefaultKeyPublicKey2},
	}
)

Default test values for SSH keys

View Source
var (
	ErrDropletNotFound = fmt.Errorf("DO API: droplet not found")
	ErrKeyNotFound     = fmt.Errorf("DO API: SSH key not found")
	ErrVolumeNotFound  = fmt.Errorf("DO API: volume not found")
	ErrRateLimit       = fmt.Errorf("DO API: rate limit exceeded")
	ErrAuthentication  = fmt.Errorf("DO API: authentication failed")
)

Error messages

Functions

This section is empty.

Types

type MockDOClient

type MockDOClient struct {
	MockDropletService *MockDropletService
	MockKeyService     *MockKeyService
	MockStorageService *MockStorageService
	StandardResponses  *StandardResponses
	// contains filtered or unexported fields
}

MockDOClient implements types.DOClient for testing

func NewMockDOClient

func NewMockDOClient() *MockDOClient

NewMockDOClient creates a new MockDOClient with standard responses

func (*MockDOClient) ConfigureProvider

func (c *MockDOClient) ConfigureProvider(_ interface{}) error

ConfigureProvider is a no-op to satisfy the ComputeProvider interface

func (*MockDOClient) CreateInstance

func (c *MockDOClient) CreateInstance(ctx context.Context, config *talisTypes.InstanceRequest) error

CreateInstance is a mock implementation of the CreateInstance method

func (*MockDOClient) DeleteInstance

func (c *MockDOClient) DeleteInstance(ctx context.Context, dropletID int) error

DeleteInstance is a mock implementation of the DeleteInstance method

func (*MockDOClient) Droplets

Droplets returns the mock droplet service

func (*MockDOClient) GetEnvironmentVars

func (c *MockDOClient) GetEnvironmentVars() map[string]string

GetEnvironmentVars is a no-op to satisfy the ComputeProvider interface

func (*MockDOClient) Keys

Keys returns the mock key service

func (*MockDOClient) ResetToStandard

func (c *MockDOClient) ResetToStandard()

ResetToStandard resets all mock services back to their standard success responses

func (*MockDOClient) SimulateAuthenticationFailure

func (c *MockDOClient) SimulateAuthenticationFailure()

SimulateAuthenticationFailure configures all services to return authentication errors

func (*MockDOClient) SimulateNotFound

func (c *MockDOClient) SimulateNotFound()

SimulateNotFound configures all services to return not found errors

func (*MockDOClient) SimulateRateLimit

func (c *MockDOClient) SimulateRateLimit()

SimulateRateLimit configures all services to return rate limit errors

func (*MockDOClient) Storage

Storage returns the mock storage service

func (*MockDOClient) ValidateCredentials

func (c *MockDOClient) ValidateCredentials() error

ValidateCredentials is a no-op to satisfy the ComputeProvider interface

type MockDropletService

type MockDropletService struct {
	CreateFunc func(_ context.Context, _ *godo.DropletCreateRequest) (*godo.Droplet, *godo.Response, error)
	GetFunc    func(_ context.Context, _ int) (*godo.Droplet, *godo.Response, error)
	DeleteFunc func(_ context.Context, _ int) (*godo.Response, error)
	ListFunc   func(_ context.Context, opt *godo.ListOptions) ([]godo.Droplet, *godo.Response, error)
	// contains filtered or unexported fields
}

MockDropletService implements types.DropletService for testing

func NewMockDropletService

func NewMockDropletService(std *StandardResponses) *MockDropletService

NewMockDropletService creates a new MockDropletService with standard responses

func (*MockDropletService) Create

Create calls the mocked Create function

func (*MockDropletService) Delete

func (s *MockDropletService) Delete(ctx context.Context, id int) (*godo.Response, error)

Delete calls the mocked Delete function

func (*MockDropletService) Get

Get calls the mocked Get function

func (*MockDropletService) GetAttemptCount

func (s *MockDropletService) GetAttemptCount() int

GetAttemptCount returns the current attempt count

func (*MockDropletService) List

List calls the mocked List function

func (*MockDropletService) ResetAttemptCount

func (s *MockDropletService) ResetAttemptCount()

ResetAttemptCount resets the attempt counter

func (*MockDropletService) ResetToStandard

func (s *MockDropletService) ResetToStandard()

ResetToStandard resets the droplet service back to standard success responses

func (*MockDropletService) SimulateAuthenticationFailure

func (s *MockDropletService) SimulateAuthenticationFailure()

SimulateAuthenticationFailure configures the service to return authentication errors

func (*MockDropletService) SimulateDelayedSuccess

func (s *MockDropletService) SimulateDelayedSuccess(successAfterAttempts int)

SimulateDelayedSuccess configures the service to succeed after a specific number of attempts

func (*MockDropletService) SimulateMaxRetries

func (s *MockDropletService) SimulateMaxRetries()

SimulateMaxRetries configures the service to always fail until max retries are hit

func (*MockDropletService) SimulateNotFound

func (s *MockDropletService) SimulateNotFound()

SimulateNotFound configures the service to return not found errors

func (*MockDropletService) SimulateRateLimit

func (s *MockDropletService) SimulateRateLimit()

SimulateRateLimit configures the service to return rate limit errors

type MockKeyService

type MockKeyService struct {
	ListFunc func(_ context.Context, _ *godo.ListOptions) ([]godo.Key, *godo.Response, error)
	// contains filtered or unexported fields
}

MockKeyService implements types.KeyService for testing

func NewMockKeyService

func NewMockKeyService(std *StandardResponses) *MockKeyService

NewMockKeyService creates a new MockKeyService with standard responses

func (*MockKeyService) List

List calls the mocked List function

func (*MockKeyService) ResetToStandard

func (s *MockKeyService) ResetToStandard()

ResetToStandard resets the key service back to standard success responses

func (*MockKeyService) SimulateAuthenticationFailure

func (s *MockKeyService) SimulateAuthenticationFailure()

SimulateAuthenticationFailure configures the service to return authentication errors

func (*MockKeyService) SimulateNotFound

func (s *MockKeyService) SimulateNotFound()

SimulateNotFound configures the service to return not found errors

func (*MockKeyService) SimulateRateLimit

func (s *MockKeyService) SimulateRateLimit()

SimulateRateLimit configures the service to return rate limit errors

type MockStorageService

type MockStorageService struct {
	CreateVolumeFunc    func(_ context.Context, _ *godo.VolumeCreateRequest) (*godo.Volume, *godo.Response, error)
	DeleteVolumeFunc    func(_ context.Context, _ string) (*godo.Response, error)
	ListVolumesFunc     func(_ context.Context, _ *godo.ListVolumeParams) ([]godo.Volume, *godo.Response, error)
	GetVolumeFunc       func(_ context.Context, _ string) (*godo.Volume, *godo.Response, error)
	GetVolumeActionFunc func(_ context.Context, _ string, _ int) (*godo.Action, *godo.Response, error)
	AttachVolumeFunc    func(_ context.Context, _ string, _ int) (*godo.Response, error)
	DetachVolumeFunc    func(_ context.Context, _ string, _ int) (*godo.Response, error)
	// contains filtered or unexported fields
}

MockStorageService implements types.StorageService for testing

func NewMockStorageService

func NewMockStorageService(std *StandardResponses) *MockStorageService

NewMockStorageService creates a new MockStorageService with standard responses

func (*MockStorageService) AttachVolume

func (s *MockStorageService) AttachVolume(ctx context.Context, id string, dropletID int) (*godo.Response, error)

AttachVolume calls the mocked AttachVolume function

func (*MockStorageService) CreateVolume

CreateVolume calls the mocked CreateVolume function

func (*MockStorageService) DeleteVolume

func (s *MockStorageService) DeleteVolume(ctx context.Context, id string) (*godo.Response, error)

DeleteVolume calls the mocked DeleteVolume function

func (*MockStorageService) DetachVolume

func (s *MockStorageService) DetachVolume(ctx context.Context, id string, dropletID int) (*godo.Response, error)

DetachVolume calls the mocked DetachVolume function

func (*MockStorageService) GetAttemptCount

func (s *MockStorageService) GetAttemptCount() int

GetAttemptCount returns the current attempt count

func (*MockStorageService) GetVolume

func (s *MockStorageService) GetVolume(ctx context.Context, id string) (*godo.Volume, *godo.Response, error)

GetVolume calls the mocked GetVolume function

func (*MockStorageService) GetVolumeAction

func (s *MockStorageService) GetVolumeAction(ctx context.Context, id string, actionID int) (*godo.Action, *godo.Response, error)

GetVolumeAction calls the mocked GetVolumeAction function

func (*MockStorageService) ListVolumes

ListVolumes calls the mocked ListVolumes function

func (*MockStorageService) ResetAttemptCount

func (s *MockStorageService) ResetAttemptCount()

ResetAttemptCount resets the attempt counter

func (*MockStorageService) ResetToStandard

func (s *MockStorageService) ResetToStandard()

ResetToStandard resets the storage service back to standard success responses

func (*MockStorageService) SimulateAuthenticationFailure

func (s *MockStorageService) SimulateAuthenticationFailure()

SimulateAuthenticationFailure configures the service to return authentication errors

func (*MockStorageService) SimulateDelayedSuccess

func (s *MockStorageService) SimulateDelayedSuccess(successAfterAttempts int)

SimulateDelayedSuccess configures the service to succeed after a specific number of attempts

func (*MockStorageService) SimulateMaxRetries

func (s *MockStorageService) SimulateMaxRetries()

SimulateMaxRetries configures the service to always fail until max retries are hit

func (*MockStorageService) SimulateNotFound

func (s *MockStorageService) SimulateNotFound()

SimulateNotFound configures the service to return not found errors

func (*MockStorageService) SimulateRateLimit

func (s *MockStorageService) SimulateRateLimit()

SimulateRateLimit configures the service to return rate limit errors

type StandardDropletResponses

type StandardDropletResponses struct {
	// Single droplet responses
	DefaultDroplet *godo.Droplet

	// Multiple droplet responses
	DefaultDropletList []godo.Droplet

	// Error responses
	NotFoundError       error
	RateLimitError      error
	AuthenticationError error
}

StandardDropletResponses contains all standard mock responses for droplets

type StandardKeyResponses

type StandardKeyResponses struct {
	// Success responses
	DefaultKeyList []godo.Key

	// Error responses
	NotFoundError       error
	RateLimitError      error
	AuthenticationError error
}

StandardKeyResponses contains all standard mock responses for keys

type StandardResponses

type StandardResponses struct {
	Droplets StandardDropletResponses
	Keys     StandardKeyResponses
	Volumes  StandardVolumeResponses
}

StandardResponses contains all standard mock responses

type StandardVolumeResponses

type StandardVolumeResponses struct {
	// Success responses
	DefaultVolume     *godo.Volume
	DefaultVolumeList []godo.Volume

	// Error responses
	NotFoundError       error
	RateLimitError      error
	AuthenticationError error
}

StandardVolumeResponses contains all standard mock responses for volumes

Jump to

Keyboard shortcuts

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