mock

package
v1.12.3 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2018 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}
)

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 added in v1.11.0

AddInstancesHook mocks adding instances from an InstanceGroup

func DeleteAddressesInternalErrHook added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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 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 added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

ListInstancesHook mocks listing instances from an InstanceGroup

func ListZonesInternalErrHook added in v1.11.0

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 added in v1.11.0

RemoveInstancesHook mocks removing instances from an InstanceGroup

func UpdateFirewallHook added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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.

Types

type AddressAttributes added in v1.11.0

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 added in v1.11.0

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 added in v1.11.0

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

AddInstances adds a list of Instances passed by InstanceReference

func (*InstanceGroupAttributes) List added in v1.11.0

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

List gets a list of InstanceWithNamedPorts

func (*InstanceGroupAttributes) RemoveInstances added in v1.11.0

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