test

package
v1.30.2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: Apache-2.0 Imports: 26 Imported by: 1

Documentation

Index

Constants

View Source
const (
	FinalizerAddFlag          = flag("enable-finalizer-add")
	FinalizerRemoveFlag       = flag("enable-finalizer-remove")
	EnableV2FrontendNamerFlag = flag("enable-v2-frontend-namer")
)
View Source
const (
	FwIPAddress = "10.0.0.1"
)

Variables

View Source
var (
	FrontendConfig = &frontendconfigv1beta1.FrontendConfig{
		ObjectMeta: meta_v1.ObjectMeta{
			Name:      "config-test",
			Namespace: "test",
		},
	}

	IngressWithoutFrontendConfig = &v1.Ingress{
		ObjectMeta: meta_v1.ObjectMeta{
			Name:      "ing-no-config",
			Namespace: "test",
		},
	}

	IngressWithFrontendConfig = &v1.Ingress{
		ObjectMeta: meta_v1.ObjectMeta{
			Name:      "ing-with-config",
			Namespace: "test",
			Annotations: map[string]string{
				annotations.FrontendConfigKey: "config-test",
			},
		},
	}

	IngressWithFrontendConfigOtherNamespace = &v1.Ingress{
		ObjectMeta: meta_v1.ObjectMeta{
			Name:      "ing-with-config",
			Namespace: "other-namespace",
			Annotations: map[string]string{
				annotations.FrontendConfigKey: "config-test",
			},
		},
	}

	IngressWithOtherFrontendConfig = &v1.Ingress{
		ObjectMeta: meta_v1.ObjectMeta{
			Name:      "ing-with-config",
			Namespace: "test",
			Annotations: map[string]string{
				annotations.FrontendConfigKey: "other-config",
			},
		},
	}
)

The below vars are used for sharing unit testing types with multiple packages.

View Source
var (
	BackendPort      = networkingv1.ServiceBackendPort{Number: 80}
	DefaultBeSvcPort = utils.ServicePort{
		ID:       utils.ServicePortID{Service: types.NamespacedName{Namespace: "system", Name: "default"}, Port: BackendPort},
		NodePort: 30000,
		Protocol: annotations.ProtocolHTTP,
	}
)

Functions

func AddInstancesErrorHook added in v1.15.0

func AddInstancesErrorHook(context.Context, *meta.Key, *compute.InstanceGroupsAddInstancesRequest, *cloud.MockInstanceGroups, ...cloud.Option) error

func Backend

Backend returns an IngressBackend with the given service name/port.

func CheckEvent added in v1.9.0

func CheckEvent(recorder *record.FakeRecorder, expected string, shouldMatch bool) error

CheckEvent watches for events in the given FakeRecorder and checks if it matches the given string. It will be used in the l4 firewall XPN tests once TestEnsureLoadBalancerDeletedSucceedsOnXPN and others are uncommented.

func CreateAndInsertNodes added in v1.9.0

func CreateAndInsertNodes(gce *gce.Cloud, nodeNames []string, zoneName string) ([]*api_v1.Node, error)

CreateAndInsertNodes adds the given nodeNames in the given zone as GCE instances, so they can be looked up in tests.

func DecodeIngress

func DecodeIngress(data []byte) (*networkingv1.Ingress, error)

DecodeIngress deserializes an Ingress object.

func DeleteAddressErrorHook added in v1.15.0

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

func DeleteBackendServicesErrorHook added in v1.15.0

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

func DeleteFirewallsErrorHook added in v1.15.0

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

func DeleteForwardingRulesErrorHook added in v1.15.0

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

func DeleteHealthCheckErrorHook added in v1.15.0

func DeleteHealthCheckErrorHook(ctx context.Context, key *meta.Key, m *cloud.MockRegionHealthChecks, options ...cloud.Option) (bool, error)

func DeleteHealthCheckResourceInUseErrorHook added in v1.15.0

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

func DeleteRegionalHealthCheckResourceInUseErrorHook added in v1.15.0

func DeleteRegionalHealthCheckResourceInUseErrorHook(ctx context.Context, key *meta.Key, m *cloud.MockRegionHealthChecks, options ...cloud.Option) (bool, error)

func FakeGoogleAPIConflictErr added in v1.16.0

func FakeGoogleAPIConflictErr() *googleapi.Error

FakeGoogleAPIConflictErr creates a StatusConflict error with type googleapi.Error

func FakeGoogleAPIForbiddenErr added in v1.16.0

func FakeGoogleAPIForbiddenErr() *googleapi.Error

FakeGoogleAPIForbiddenErr creates a Forbidden error with type googleapi.Error

func FakeGoogleAPINotFoundErr added in v1.16.0

func FakeGoogleAPINotFoundErr() *googleapi.Error

FakeGoogleAPINotFoundErr creates a NotFound error with type googleapi.Error

func FakeGoogleAPIRequestEntityTooLargeError added in v1.17.0

func FakeGoogleAPIRequestEntityTooLargeError() *googleapi.Error

FakeGoogleAPIRequestEntityTooLargeError creates a StatusRequestEntityTooLarge error with type googleapi.Error

func FakeGoogleAPIRequestServerError added in v1.30.0

func FakeGoogleAPIRequestServerError() *googleapi.Error

FakeGoogleAPIRequestServerError creates a StatusInternalServerError error with type googleapi.Error

func Float64ToPtr added in v1.9.1

func Float64ToPtr(val float64) *float64

Float64ToPtr returns float ptr for given float.

func GCEInstanceExists added in v1.9.0

func GCEInstanceExists(name string, g *gce.Cloud) (bool, error)

GCEInstanceExists returns if a given instance name exists.

func GetErrorInstanceGroupHook added in v1.15.0

func GetErrorInstanceGroupHook(ctx context.Context, key *meta.Key, m *cloud.MockInstanceGroups, options ...cloud.Option) (bool, *compute.InstanceGroup, error)

func GetLegacyForwardingRule added in v1.15.0

func GetLegacyForwardingRule(ctx context.Context, key *meta.Key, m *cloud.MockForwardingRules, options ...cloud.Option) (bool, *compute.ForwardingRule, error)

func GetRBSForwardingRule added in v1.16.0

func GetRBSForwardingRule(ctx context.Context, key *meta.Key, m *cloud.MockForwardingRules, options ...cloud.Option) (bool, *compute.ForwardingRule, error)

func GetRBSForwardingRuleInStandardTier added in v1.17.0

func GetRBSForwardingRuleInStandardTier(ctx context.Context, key *meta.Key, m *cloud.MockForwardingRules, options ...cloud.Option) (bool, *compute.ForwardingRule, error)

func InsertAddressErrorHook added in v1.15.0

func InsertAddressErrorHook(ctx context.Context, key *meta.Key, obj *compute.Address, m *cloud.MockAddresses, options ...cloud.Option) (bool, error)

func InsertAddressNetworkErrorHook added in v1.17.0

func InsertAddressNetworkErrorHook(ctx context.Context, key *meta.Key, obj *compute.Address, m *cloud.MockAddresses, options ...cloud.Option) (bool, error)

func InsertAddressNotAllocatedToProjectErrorHook added in v1.20.3

func InsertAddressNotAllocatedToProjectErrorHook(ctx context.Context, key *meta.Key, obj *compute.Address, m *cloud.MockAddresses, options ...cloud.Option) (bool, error)

func InsertErrorHook added in v1.15.0

func InsertErrorHook(ctx context.Context, key *meta.Key, obj *compute.InstanceGroup, m *cloud.MockInstanceGroups, options ...cloud.Option) (bool, error)

func InsertForwardingRuleErrorHook added in v1.20.3

func InsertForwardingRuleErrorHook(err error) func(ctx context.Context, key *meta.Key, obj *compute.ForwardingRule, m *cloud.MockForwardingRules, options ...cloud.Option) (b bool, e error)

func InsertForwardingRuleHook added in v1.15.0

func InsertForwardingRuleHook(ctx context.Context, key *meta.Key, obj *compute.ForwardingRule, m *cloud.MockForwardingRules, options ...cloud.Option) (b bool, e error)

func InstancesListToNameSet added in v1.16.0

func InstancesListToNameSet(instancesList []*compute.InstanceWithNamedPorts) (sets.String, error)

func Int64ToPtr added in v1.10.0

func Int64ToPtr(val int64) *int64

Int64ToPtr returns int ptr for given int.

func ListErrorHook added in v1.15.0

func ListErrorHook(ctx context.Context, zone string, fl *filter.F, m *cloud.MockInstanceGroups, options ...cloud.Option) (bool, []*compute.InstanceGroup, error)

func ListInstancesWithErrorHook added in v1.15.0

func ListInstancesWithErrorHook(context.Context, *meta.Key, *compute.InstanceGroupsListInstancesRequest, *filter.F, *cloud.MockInstanceGroups, ...cloud.Option) ([]*compute.InstanceWithNamedPorts, error)

func MustCreateDualStackClusterSubnet added in v1.25.0

func MustCreateDualStackClusterSubnet(t *testing.T, gcecloud *gce.Cloud, ipv6AccessType string)

func MustCreateDualStackSubnet added in v1.25.0

func MustCreateDualStackSubnet(t *testing.T, gcecloud *gce.Cloud, subnetName, ipv6AccessType string)

func NewBackendConfig

NewBackendConfig returns a BackendConfig with the given spec.

func NewIngress

NewIngress returns an Ingress with the given spec.

func NewL4ILBDualStackService added in v1.21.0

func NewL4ILBDualStackService(port int, protocol api_v1.Protocol, ipFamilies []api_v1.IPFamily, externalTrafficPolicy api_v1.ServiceExternalTrafficPolicyType) *api_v1.Service

NewL4ILBDualStackService creates a Service of type LoadBalancer with the Internal annotation and provided ipFamilies and ipFamilyPolicy

func NewL4ILBService added in v1.9.0

func NewL4ILBService(onlyLocal bool, port int) *api_v1.Service

NewL4ILBService creates a Service of type LoadBalancer with the Internal annotation.

func NewL4LegacyNetLBService added in v1.16.0

func NewL4LegacyNetLBService(port int, nodePort int32) *api_v1.Service

NewL4LegacyNetLBService creates a Legacy Service of type LoadBalancer without the RBS Annotation

func NewL4LegacyNetLBServiceWithoutPorts added in v1.16.0

func NewL4LegacyNetLBServiceWithoutPorts() *api_v1.Service

func NewL4NetLBRBSDualStackService added in v1.22.0

func NewL4NetLBRBSDualStackService(protocol api_v1.Protocol, ipFamilies []api_v1.IPFamily, externalTrafficPolicy api_v1.ServiceExternalTrafficPolicyType) *api_v1.Service

NewL4NetLBRBSDualStackService creates a Service of type LoadBalancer with RBS Annotation and provided ipFamilies and ipFamilyPolicy

func NewL4NetLBRBSService added in v1.16.0

func NewL4NetLBRBSService(port int) *api_v1.Service

NewL4NetLBRBSService creates a Service of type LoadBalancer with RBS Annotation

func NewL4NetLBRBSServiceMultiplePorts added in v1.16.0

func NewL4NetLBRBSServiceMultiplePorts(name string, ports []int32) *api_v1.Service

NewL4NetLBRBSServiceMultiplePorts creates a Service of type LoadBalancer with multiple named ports.

func NewService

func NewService(name types.NamespacedName, spec api_v1.ServiceSpec) *api_v1.Service

NewService returns a Service with the given spec.

func SetNamedPortsErrorHook added in v1.15.0

func SetNamedPortsErrorHook(context.Context, *meta.Key, *compute.InstanceGroupsSetNamedPortsRequest, *cloud.MockInstanceGroups) error

func UpdateRegionBackendServiceWithErrorHookUpdate added in v1.17.0

func UpdateRegionBackendServiceWithErrorHookUpdate(context.Context, *meta.Key, *compute.BackendService, *cloud.MockRegionBackendServices, ...cloud.Option) error

Types

type FakeRecorderSource added in v1.10.0

type FakeRecorderSource struct{}

func (*FakeRecorderSource) Recorder added in v1.10.0

type FlagSaver added in v1.8.0

type FlagSaver struct {
	// contains filtered or unexported fields
}

FlagSaver is an utility type to capture the value of a flag and reset back to the saved value.

func NewFlagSaver added in v1.8.0

func NewFlagSaver() FlagSaver

NewFlagSaver returns a flag saver by initializing the map.

func (*FlagSaver) Reset added in v1.8.0

func (s *FlagSaver) Reset(key flag, flagPointer *bool)

Reset resets the value of given flag to a previously saved value. This does nothing if the flag value was not captured.

func (*FlagSaver) Save added in v1.8.0

func (s *FlagSaver) Save(key flag, flagPointer *bool)

Save captures the value of given flag.

type L4LBErrorMetricInfo added in v1.16.0

type L4LBErrorMetricInfo struct {
	ByGCEResource map[string]uint64
	ByErrorType   map[string]uint64
}

L4LBErrorMetricInfo holds the state of the sync_error_count metric for ILB or NetLB.

func GetL4ILBErrorMetric added in v1.11.2

func GetL4ILBErrorMetric() (*L4LBErrorMetricInfo, error)

GetL4ILBErrorMetric gets the current state of the l4_ilb_sync_error_count.

func GetL4NetLBErrorMetric added in v1.16.0

func GetL4NetLBErrorMetric() (*L4LBErrorMetricInfo, error)

GetL4NetLBErrorMetric gets the current state of the l4_netlb_sync_error_count.

func (*L4LBErrorMetricInfo) ValidateDiff added in v1.16.0

func (old *L4LBErrorMetricInfo) ValidateDiff(new, expect *L4LBErrorMetricInfo, t *testing.T)

ValidateDiff ensures that the diff between the old and the new metric is as expected. The test uses diff rather than absolute values since the metrics are cumulative of all test cases.

type L4LBLatencyMetricInfo added in v1.16.0

type L4LBLatencyMetricInfo struct {
	CreateCount       uint64
	DeleteCount       uint64
	UpdateCount       uint64
	UpperBoundSeconds float64
	// contains filtered or unexported fields
}

L4LatencyMetricInfo holds the state of the sync_duration_seconds metric for ILB or NetLB.

func GetL4ILBLatencyMetric added in v1.16.0

func GetL4ILBLatencyMetric() (*L4LBLatencyMetricInfo, error)

GetL4ILBLatencyMetric gets the current state of the l4_ilb_sync_duration_seconds metric.

func GetL4NetLBLatencyMetric added in v1.16.0

func GetL4NetLBLatencyMetric() (*L4LBLatencyMetricInfo, error)

GetL4NetLBLatencyMetric gets the current state of the l4_netlb_sync_duration_seconds metric.

func (*L4LBLatencyMetricInfo) ValidateDiff added in v1.16.0

func (old *L4LBLatencyMetricInfo) ValidateDiff(new, expect *L4LBLatencyMetricInfo, t *testing.T)

ValidateDiff ensures that the diff between the old and the new metric is as expected. The test uses diff rather than absolute values since the metrics are cumulative of all test cases.

Jump to

Keyboard shortcuts

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