mock

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package mock encapsulates mocks for testing GCE provider functionality. These methods are used to override the mock objects' methods in order to intercept the standard processing and to add custom logic for test purposes.

// Example usage:

cloud := cloud.NewMockGCE() cloud.MockTargetPools.AddInstanceHook = mock.AddInstanceHook

Index

Constants

This section is empty.

Variables

View Source
var (
	// InUseError is a shared variable with error code StatusBadRequest for error verification.
	InUseError = &googleapi.Error{Code: http.StatusBadRequest, Message: "It's being used by god."}
	// InternalServerError is shared variable with error code StatusInternalServerError for error verification.
	InternalServerError = &googleapi.Error{Code: http.StatusInternalServerError}
	// UnauthorizedErr wraps a Google API error with code StatusForbidden.
	UnauthorizedErr = &googleapi.Error{Code: http.StatusForbidden}
)

Functions

func AddInstanceHook

func AddInstanceHook(ctx context.Context, key *meta.Key, req *ga.TargetPoolsAddInstanceRequest, m *cloud.MockTargetPools) error

AddInstanceHook mocks adding a Instance to MockTargetPools

func AddInstancesHook

AddInstancesHook mocks adding instances from an InstanceGroup

func DeleteAddressesInternalErrHook

func DeleteAddressesInternalErrHook(ctx context.Context, key *meta.Key, m *cloud.MockAddresses) (bool, error)

DeleteAddressesInternalErrHook mocks deleting address and returns an internal server error.

func DeleteAddressesNotFoundErrHook

func DeleteAddressesNotFoundErrHook(ctx context.Context, key *meta.Key, m *cloud.MockAddresses) (bool, error)

DeleteAddressesNotFoundErrHook mocks deleting network address and returns a not found error.

func DeleteFirewallsUnauthorizedErrHook

func DeleteFirewallsUnauthorizedErrHook(ctx context.Context, key *meta.Key, m *cloud.MockFirewalls) (bool, error)

DeleteFirewallsUnauthorizedErrHook mocks firewall deletion. A forbidden error will be thrown as return.

func DeleteForwardingRuleErrHook

func DeleteForwardingRuleErrHook(ctx context.Context, key *meta.Key, m *cloud.MockForwardingRules) (bool, error)

DeleteForwardingRuleErrHook mocks deleting forwarding rule and returns an internal server error.

func DeleteHealthChecksInternalErrHook

func DeleteHealthChecksInternalErrHook(ctx context.Context, key *meta.Key, m *cloud.MockHealthChecks) (bool, error)

DeleteHealthChecksInternalErrHook mocks deleting health check and returns an internal server error.

func DeleteHealthChecksInuseErrHook

func DeleteHealthChecksInuseErrHook(ctx context.Context, key *meta.Key, m *cloud.MockHealthChecks) (bool, error)

DeleteHealthChecksInuseErrHook mocks deleting health check and returns an in use error.

func DeleteInstanceGroupInternalErrHook

func DeleteInstanceGroupInternalErrHook(ctx context.Context, key *meta.Key, m *cloud.MockInstanceGroups) (bool, error)

DeleteInstanceGroupInternalErrHook mocks deleting instance group and returns an internal server error.

func DeleteRegionBackendServicesErrHook

func DeleteRegionBackendServicesErrHook(ctx context.Context, key *meta.Key, m *cloud.MockRegionBackendServices) (bool, error)

DeleteRegionBackendServicesErrHook mocks deleting region backend service and returns an internal server error.

func DeleteRegionBackendServicesInUseErrHook

func DeleteRegionBackendServicesInUseErrHook(ctx context.Context, key *meta.Key, m *cloud.MockRegionBackendServices) (bool, error)

DeleteRegionBackendServicesInUseErrHook mocks deleting region backend service and returns an InUseError.

func GetAddressesInternalErrHook

func GetAddressesInternalErrHook(ctx context.Context, key *meta.Key, m *cloud.MockAddresses) (bool, *ga.Address, error)

GetAddressesInternalErrHook mocks getting network address and returns an internal server error.

func GetFirewallsUnauthorizedErrHook

func GetFirewallsUnauthorizedErrHook(ctx context.Context, key *meta.Key, m *cloud.MockFirewalls) (bool, *ga.Firewall, error)

GetFirewallsUnauthorizedErrHook mocks firewall information retrival. A forbidden error will be thrown as return.

func GetForwardingRulesInternalErrHook

func GetForwardingRulesInternalErrHook(ctx context.Context, key *meta.Key, m *cloud.MockForwardingRules) (bool, *ga.ForwardingRule, error)

GetForwardingRulesInternalErrHook mocks getting forwarding rules and returns an internal server error.

func GetHTTPHealthChecksInternalErrHook

func GetHTTPHealthChecksInternalErrHook(ctx context.Context, key *meta.Key, m *cloud.MockHttpHealthChecks) (bool, *ga.HttpHealthCheck, error)

GetHTTPHealthChecksInternalErrHook mocks getting http health check and returns an internal server error.

func GetHealthChecksInternalErrHook

func GetHealthChecksInternalErrHook(ctx context.Context, key *meta.Key, m *cloud.MockHealthChecks) (bool, *ga.HealthCheck, error)

GetHealthChecksInternalErrHook mocks getting health check and returns an internal server erorr.

func GetInstanceGroupInternalErrHook

func GetInstanceGroupInternalErrHook(ctx context.Context, key *meta.Key, m *cloud.MockInstanceGroups) (bool, *ga.InstanceGroup, error)

GetInstanceGroupInternalErrHook mocks getting instance group and returns an internal server error.

func GetRegionBackendServicesErrHook

func GetRegionBackendServicesErrHook(ctx context.Context, key *meta.Key, m *cloud.MockRegionBackendServices) (bool, *ga.BackendService, error)

GetRegionBackendServicesErrHook mocks getting region backend service and returns an internal server error.

func GetTargetPoolInternalErrHook

func GetTargetPoolInternalErrHook(ctx context.Context, key *meta.Key, m *cloud.MockTargetPools) (bool, *ga.TargetPool, error)

GetTargetPoolInternalErrHook mocks getting target pool. It returns a internal server error.

func InsertAddressHook

func InsertAddressHook(ctx context.Context, key *meta.Key, obj *ga.Address, m *cloud.MockAddresses) (bool, error)

InsertAddressHook mocks inserting an Address.

func InsertAlphaAddressHook

func InsertAlphaAddressHook(ctx context.Context, key *meta.Key, obj *alpha.Address, m *cloud.MockAlphaAddresses) (bool, error)

InsertAlphaAddressHook mocks inserting an Address. Addresses are expected to default to Premium tier if no NetworkTier is specified.

func InsertAlphaBackendServiceUnauthorizedErrHook

func InsertAlphaBackendServiceUnauthorizedErrHook(ctx context.Context, key *meta.Key, obj *alpha.BackendService, m *cloud.MockAlphaBackendServices) (bool, error)

InsertAlphaBackendServiceUnauthorizedErrHook mocks inserting an alpha BackendService and returns a forbidden error.

func InsertAlphaFwdRuleHook

func InsertAlphaFwdRuleHook(ctx context.Context, key *meta.Key, obj *alpha.ForwardingRule, m *cloud.MockForwardingRules) (bool, error)

InsertAlphaFwdRuleHook mocks inserting an AlphaForwardingRule.

func InsertBetaAddressHook

func InsertBetaAddressHook(ctx context.Context, key *meta.Key, obj *beta.Address, m *cloud.MockAddresses) (bool, error)

InsertBetaAddressHook mocks inserting a BetaAddress.

func InsertBetaFwdRuleHook

func InsertBetaFwdRuleHook(ctx context.Context, key *meta.Key, obj *beta.ForwardingRule, m *cloud.MockForwardingRules) (bool, error)

InsertBetaFwdRuleHook mocks inserting a BetaForwardingRule.

func InsertFirewallsUnauthorizedErrHook

func InsertFirewallsUnauthorizedErrHook(ctx context.Context, key *meta.Key, obj *ga.Firewall, m *cloud.MockFirewalls) (bool, error)

InsertFirewallsUnauthorizedErrHook mocks firewall insertion. A forbidden error will be thrown as return.

func InsertForwardingRulesInternalErrHook

func InsertForwardingRulesInternalErrHook(ctx context.Context, key *meta.Key, obj *ga.ForwardingRule, m *cloud.MockForwardingRules) (bool, error)

InsertForwardingRulesInternalErrHook mocks getting forwarding rule and returns an internal server error.

func InsertFwdRuleHook

func InsertFwdRuleHook(ctx context.Context, key *meta.Key, obj *ga.ForwardingRule, m *cloud.MockForwardingRules) (bool, error)

InsertFwdRuleHook mocks inserting a ForwardingRule. ForwardingRules are expected to default to Premium tier if no NetworkTier is specified.

func InsertTargetPoolsInternalErrHook

func InsertTargetPoolsInternalErrHook(ctx context.Context, key *meta.Key, obj *ga.TargetPool, m *cloud.MockTargetPools) (bool, error)

InsertTargetPoolsInternalErrHook mocks getting target pool and returns an internal server error.

func ListInstancesHook

ListInstancesHook mocks listing instances from an InstanceGroup

func ListZonesInternalErrHook

func ListZonesInternalErrHook(ctx context.Context, fl *filter.F, m *cloud.MockZones) (bool, []*ga.Zone, error)

ListZonesInternalErrHook mocks listing zone and returns an internal server error.

func RemoveInstanceHook

func RemoveInstanceHook(ctx context.Context, key *meta.Key, req *ga.TargetPoolsRemoveInstanceRequest, m *cloud.MockTargetPools) error

RemoveInstanceHook mocks removing a Instance from MockTargetPools

func RemoveInstancesHook

RemoveInstancesHook mocks removing instances from an InstanceGroup

func UpdateAlphaBackendServiceHook

func UpdateAlphaBackendServiceHook(ctx context.Context, key *meta.Key, obj *alpha.BackendService, m *cloud.MockAlphaBackendServices) error

UpdateAlphaBackendServiceHook defines the hook for updating an alpha BackendService. It replaces the object with the same key in the mock with the updated object.

func UpdateAlphaBackendServiceUnauthorizedErrHook

func UpdateAlphaBackendServiceUnauthorizedErrHook(ctx context.Context, key *meta.Key, obj *alpha.BackendService, m *cloud.MockAlphaBackendServices) error

UpdateAlphaBackendServiceUnauthorizedErrHook mocks updating an alpha BackendService and returns a forbidden error.

func UpdateBackendServiceHook

func UpdateBackendServiceHook(ctx context.Context, key *meta.Key, obj *ga.BackendService, m *cloud.MockBackendServices) error

UpdateBackendServiceHook defines the hook for updating a BackendService. It replaces the object with the same key in the mock with the updated object.

func UpdateBetaBackendServiceHook

func UpdateBetaBackendServiceHook(ctx context.Context, key *meta.Key, obj *beta.BackendService, m *cloud.MockBetaBackendServices) error

UpdateBetaBackendServiceHook defines the hook for updating an beta BackendService. It replaces the object with the same key in the mock with the updated object.

func UpdateFirewallHook

func UpdateFirewallHook(ctx context.Context, key *meta.Key, obj *ga.Firewall, m *cloud.MockFirewalls) error

UpdateFirewallHook defines the hook for updating a Firewall. It replaces the object with the same key in the mock with the updated object.

func UpdateFirewallsUnauthorizedErrHook

func UpdateFirewallsUnauthorizedErrHook(ctx context.Context, key *meta.Key, obj *ga.Firewall, m *cloud.MockFirewalls) error

UpdateFirewallsUnauthorizedErrHook mocks firewall updating. A forbidden error will be thrown as return.

func UpdateHealthCheckHook

func UpdateHealthCheckHook(ctx context.Context, key *meta.Key, obj *ga.HealthCheck, m *cloud.MockHealthChecks) error

UpdateHealthCheckHook defines the hook for updating a HealthCheck. It replaces the object with the same key in the mock with the updated object.

func UpdateRegionBackendServiceHook

func UpdateRegionBackendServiceHook(ctx context.Context, key *meta.Key, obj *ga.BackendService, m *cloud.MockRegionBackendServices) error

UpdateRegionBackendServiceHook defines the hook for updating a Region BackendsService. It replaces the object with the same key in the mock with the updated object.

func UpdateRegionBackendServicesErrHook

func UpdateRegionBackendServicesErrHook(ctx context.Context, key *meta.Key, svc *ga.BackendService, m *cloud.MockRegionBackendServices) error

UpdateRegionBackendServicesErrHook mocks updating a reegion backend service and returns an internal server error.

func UpdateURLMapHook

func UpdateURLMapHook(ctx context.Context, key *meta.Key, obj *ga.UrlMap, m *cloud.MockUrlMaps) error

UpdateURLMapHook defines the hook for updating a UrlMap. It replaces the object with the same key in the mock with the updated object.

Types

type AddressAttributes

type AddressAttributes struct {
	IPCounter int // Used to assign Addresses with no IP a unique IP address
}

AddressAttributes maps from Address key to a map of Instances

type InstanceGroupAttributes

type InstanceGroupAttributes struct {
	InstanceMap map[meta.Key]map[string]*ga.InstanceWithNamedPorts
	Lock        *sync.Mutex
}

InstanceGroupAttributes maps from InstanceGroup key to a map of Instances

func (*InstanceGroupAttributes) AddInstances

func (igAttrs *InstanceGroupAttributes) AddInstances(key *meta.Key, instanceRefs []*ga.InstanceReference) error

AddInstances adds a list of Instances passed by InstanceReference

func (*InstanceGroupAttributes) List

func (igAttrs *InstanceGroupAttributes) List(key *meta.Key) []*ga.InstanceWithNamedPorts

List gets a list of InstanceWithNamedPorts

func (*InstanceGroupAttributes) RemoveInstances

func (igAttrs *InstanceGroupAttributes) RemoveInstances(key *meta.Key, instanceRefs []*ga.InstanceReference) error

RemoveInstances removes a list of Instances passed by InstanceReference

Jump to

Keyboard shortcuts

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