mock

package
v0.0.0-...-d88c8b5 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 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 AttachDiskHook

func AttachDiskHook(ctx context.Context, key *meta.Key, req *ga.AttachedDisk, m *cloud.MockInstances) error

AttachDiskHook mocks attaching a disk to an instance

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 DetachDiskHook

func DetachDiskHook(ctx context.Context, key *meta.Key, diskName string, m *cloud.MockInstances) error

DetachDiskHook mocks detaching a disk from an instance

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 SetSslCertificateAlphaRegionTargetHTTPSProxyHook

func SetSslCertificateAlphaRegionTargetHTTPSProxyHook(ctx context.Context, key *meta.Key, req *alpha.TargetHttpsProxiesSetSslCertificatesRequest, m *cloud.MockAlphaRegionTargetHttpsProxies) error

SetSslCertificateAlphaRegionTargetHTTPSProxyHook defines the hook for setting ssl certificates on a TargetHttpsProxy.

func SetSslCertificateAlphaTargetHTTPSProxyHook

func SetSslCertificateAlphaTargetHTTPSProxyHook(ctx context.Context, key *meta.Key, req *alpha.TargetHttpsProxiesSetSslCertificatesRequest, m *cloud.MockAlphaTargetHttpsProxies) error

SetSslCertificateAlphaTargetHTTPSProxyHook defines the hook for setting ssl certificates on a TargetHttpsProxy.

func SetSslCertificateBetaRegionTargetHTTPSProxyHook

func SetSslCertificateBetaRegionTargetHTTPSProxyHook(ctx context.Context, key *meta.Key, req *alpha.TargetHttpsProxiesSetSslCertificatesRequest, m *cloud.MockBetaRegionTargetHttpsProxies) error

SetSslCertificateBetaRegionTargetHTTPSProxyHook defines the hook for setting ssl certificates on a TargetHttpsProxy.

func SetSslCertificateTargetHTTPSProxyHook

func SetSslCertificateTargetHTTPSProxyHook(ctx context.Context, key *meta.Key, req *ga.TargetHttpsProxiesSetSslCertificatesRequest, m *cloud.MockTargetHttpsProxies) error

SetSslCertificateTargetHTTPSProxyHook defines the hook for setting ssl certificates on a TargetHttpsProxy.

func SetTargetAlphaForwardingRuleHook

func SetTargetAlphaForwardingRuleHook(ctx context.Context, key *meta.Key, obj *alpha.TargetReference, m *cloud.MockAlphaForwardingRules) error

SetTargetAlphaForwardingRuleHook defines the hook for setting the target proxy for an Alpha ForwardingRule.

func SetTargetAlphaGlobalForwardingRuleHook

func SetTargetAlphaGlobalForwardingRuleHook(ctx context.Context, key *meta.Key, ref *alpha.TargetReference, m *cloud.MockAlphaGlobalForwardingRules) error

SetTargetAlphaGlobalForwardingRuleHook defines the hook for setting the target proxy for an alpha GlobalForwardingRule.

func SetTargetBetaForwardingRuleHook

func SetTargetBetaForwardingRuleHook(ctx context.Context, key *meta.Key, obj *alpha.TargetReference, m *cloud.MockBetaForwardingRules) error

SetTargetBetaForwardingRuleHook defines the hook for setting the target proxy for an Alpha ForwardingRule.

func SetTargetForwardingRuleHook

func SetTargetForwardingRuleHook(ctx context.Context, key *meta.Key, obj *ga.TargetReference, m *cloud.MockForwardingRules) error

SetTargetForwardingRuleHook defines the hook for setting the target proxy for a ForwardingRule.

func SetTargetGlobalForwardingRuleHook

func SetTargetGlobalForwardingRuleHook(ctx context.Context, key *meta.Key, obj *ga.TargetReference, m *cloud.MockGlobalForwardingRules) error

SetTargetGlobalForwardingRuleHook defines the hook for setting the target proxy for a GlobalForwardingRule.

func SetURLMapAlphaRegionTargetHTTPProxyHook

func SetURLMapAlphaRegionTargetHTTPProxyHook(ctx context.Context, key *meta.Key, ref *alpha.UrlMapReference, m *cloud.MockAlphaRegionTargetHttpProxies) error

SetURLMapAlphaRegionTargetHTTPProxyHook defines the hook for setting the url map for a TargetHttpProxy.

func SetURLMapAlphaRegionTargetHTTPSProxyHook

func SetURLMapAlphaRegionTargetHTTPSProxyHook(ctx context.Context, key *meta.Key, ref *alpha.UrlMapReference, m *cloud.MockAlphaRegionTargetHttpsProxies) error

SetURLMapTargetHTTPProxyHook defines the hook for setting the url map for a TargetHttpProxy.

func SetURLMapAlphaTargetHTTPProxyHook

func SetURLMapAlphaTargetHTTPProxyHook(ctx context.Context, key *meta.Key, ref *alpha.UrlMapReference, m *cloud.MockAlphaTargetHttpProxies) error

SetURLMapAlphaTargetHTTPProxyHook defines the hook for setting the url map for a TargetHttpProxy.

func SetURLMapBetaRegionTargetHTTPProxyHook

func SetURLMapBetaRegionTargetHTTPProxyHook(ctx context.Context, key *meta.Key, ref *alpha.UrlMapReference, m *cloud.MockBetaRegionTargetHttpProxies) error

SetURLMapBetaRegionTargetHTTPProxyHook defines the hook for setting the url map for a TargetHttpProxy.

func SetURLMapBetaRegionTargetHTTPSProxyHook

func SetURLMapBetaRegionTargetHTTPSProxyHook(ctx context.Context, key *meta.Key, ref *alpha.UrlMapReference, m *cloud.MockBetaRegionTargetHttpsProxies) error

SetURLMapBetaRegionTargetHTTPProxyHook defines the hook for setting the url map for a TargetHttpProxy.

func SetURLMapTargetHTTPProxyHook

func SetURLMapTargetHTTPProxyHook(ctx context.Context, key *meta.Key, ref *ga.UrlMapReference, m *cloud.MockTargetHttpProxies) error

SetURLMapTargetHTTPProxyHook defines the hook for setting the url map for a TargetHttpProxy.

func SetURLMapTargetHTTPSProxyHook

func SetURLMapTargetHTTPSProxyHook(ctx context.Context, key *meta.Key, ref *ga.UrlMapReference, m *cloud.MockTargetHttpsProxies) error

SetURLMapTargetHTTPProxyHook defines the hook for setting the url map for a TargetHttpProxy.

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 UpdateAlphaHealthCheckHook

func UpdateAlphaHealthCheckHook(ctx context.Context, key *meta.Key, obj *alpha.HealthCheck, m *cloud.MockAlphaHealthChecks) error

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

func UpdateAlphaRegionBackendServiceHook

func UpdateAlphaRegionBackendServiceHook(ctx context.Context, key *meta.Key, obj *ga.BackendService, m *cloud.MockAlphaRegionBackendServices) 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 UpdateAlphaRegionHealthCheckHook

func UpdateAlphaRegionHealthCheckHook(ctx context.Context, key *meta.Key, obj *alpha.HealthCheck, m *cloud.MockAlphaRegionHealthChecks) error

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

func UpdateAlphaRegionURLMapHook

func UpdateAlphaRegionURLMapHook(ctx context.Context, key *meta.Key, obj *alpha.UrlMap, m *cloud.MockAlphaRegionUrlMaps) error

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

func UpdateAlphaURLMapHook

func UpdateAlphaURLMapHook(ctx context.Context, key *meta.Key, obj *alpha.UrlMap, m *cloud.MockAlphaUrlMaps) error

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

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 UpdateBetaHealthCheckHook

func UpdateBetaHealthCheckHook(ctx context.Context, key *meta.Key, obj *beta.HealthCheck, m *cloud.MockBetaHealthChecks) error

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

func UpdateBetaRegionBackendServiceHook

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

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

func UpdateBetaRegionHealthCheckHook

func UpdateBetaRegionHealthCheckHook(ctx context.Context, key *meta.Key, obj *beta.HealthCheck, m *cloud.MockBetaRegionHealthChecks) error

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

func UpdateBetaRegionURLMapHook

func UpdateBetaRegionURLMapHook(ctx context.Context, key *meta.Key, obj *alpha.UrlMap, m *cloud.MockBetaRegionUrlMaps) error

UpdateBetaRegionURLMapHook defines the hook for updating an alpha UrlMap. 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