testutil

package
v1.17.7 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testutil provides shared test helpers. client.go provides thin wrappers around controller-runtime client.Client to inject errors for tests. controller-runtime's fake client does not support error injection (see https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/client/fake).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientWithGetErr added in v1.17.1

func ClientWithGetErr(c client.Client, getErr error) client.Client

ClientWithGetErr wraps c and returns getErr on every Get().

func ClientWithGetErrorFunc added in v1.17.1

func ClientWithGetErrorFunc(c client.Client, fn GetErrorFunc) client.Client

ClientWithGetErrorFunc wraps c and returns error on Get when fn(key) returns non-nil.

func ClientWithStatusUpdateErr added in v1.17.1

func ClientWithStatusUpdateErr(c client.Client, statusUpdateErr error) client.Client

ClientWithStatusUpdateErr wraps c and returns statusUpdateErr on Status().Update().

func ClientWithUpdateErr added in v1.17.1

func ClientWithUpdateErr(c client.Client, updateErr error) client.Client

ClientWithUpdateErr wraps c and returns updateErr on Update().

func CreateResource

func CreateResource(ctx context.Context, cli client.Client, obj client.Object) error

CreateResource updates the status of a resource. It first gets a fresh copy of the resource, then deep copies the status, and finally updates it.

func CreateTestPod

func CreateTestPod(name, namespace, nodeName string) *corev1.Pod

func NewManager added in v1.17.1

func NewManager(rest *rest.Config, openAPI aliyun.OpenAPI, directClient client.Client) (manager.Manager, *register.ControllerCtx)

Types

type GetErrorFunc added in v1.17.1

type GetErrorFunc func(key client.ObjectKey) error

GetErrorFunc returns an error for a given key; if non-nil, Get will return that error instead of delegating.

type K8sNodeBuilder

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

K8sNodeBuilder builds corev1.Node objects for testing

func NewK8sNodeBuilder

func NewK8sNodeBuilder(name string) *K8sNodeBuilder

NewK8sNodeBuilder creates a new K8sNodeBuilder with default values

func (*K8sNodeBuilder) Build

func (b *K8sNodeBuilder) Build() *corev1.Node

func (*K8sNodeBuilder) WithAnnotation

func (b *K8sNodeBuilder) WithAnnotation(key, value string) *K8sNodeBuilder

func (*K8sNodeBuilder) WithEFLO

func (b *K8sNodeBuilder) WithEFLO() *K8sNodeBuilder

func (*K8sNodeBuilder) WithExclusiveENIMode

func (b *K8sNodeBuilder) WithExclusiveENIMode() *K8sNodeBuilder

func (*K8sNodeBuilder) WithInstanceType

func (b *K8sNodeBuilder) WithInstanceType(instanceType string) *K8sNodeBuilder

func (*K8sNodeBuilder) WithLabel

func (b *K8sNodeBuilder) WithLabel(key, value string) *K8sNodeBuilder

func (*K8sNodeBuilder) WithProviderID

func (b *K8sNodeBuilder) WithProviderID(providerID string) *K8sNodeBuilder

func (*K8sNodeBuilder) WithRegion

func (b *K8sNodeBuilder) WithRegion(region string) *K8sNodeBuilder

func (*K8sNodeBuilder) WithZone

func (b *K8sNodeBuilder) WithZone(zone string) *K8sNodeBuilder

type NodeCRDBuilder

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

NodeCRDBuilder builds networkv1beta1.Node objects for testing

func NewNodeCRDBuilder

func NewNodeCRDBuilder(name string) *NodeCRDBuilder

NewNodeCRDBuilder creates a new NodeCRDBuilder with default values

func (*NodeCRDBuilder) Build

func (b *NodeCRDBuilder) Build() *networkv1beta1.Node

func (*NodeCRDBuilder) WithAnnotation

func (b *NodeCRDBuilder) WithAnnotation(key, value string) *NodeCRDBuilder

func (*NodeCRDBuilder) WithEFLO

func (b *NodeCRDBuilder) WithEFLO() *NodeCRDBuilder

func (*NodeCRDBuilder) WithENISpec

func (b *NodeCRDBuilder) WithENISpec(vswitch, securityGroup string) *NodeCRDBuilder

func (*NodeCRDBuilder) WithEnableTrunk

func (b *NodeCRDBuilder) WithEnableTrunk(enable bool) *NodeCRDBuilder

func (*NodeCRDBuilder) WithExclusiveENIMode

func (b *NodeCRDBuilder) WithExclusiveENIMode() *NodeCRDBuilder

func (*NodeCRDBuilder) WithFlavor

func (b *NodeCRDBuilder) WithFlavor(flavors ...networkv1beta1.Flavor) *NodeCRDBuilder

func (*NodeCRDBuilder) WithLabel

func (b *NodeCRDBuilder) WithLabel(key, value string) *NodeCRDBuilder

func (*NodeCRDBuilder) WithNetworkCardsCount

func (b *NodeCRDBuilder) WithNetworkCardsCount(count int) *NodeCRDBuilder

func (*NodeCRDBuilder) WithNetworkInterface

func (b *NodeCRDBuilder) WithNetworkInterface(eniID string, nic *networkv1beta1.Nic) *NodeCRDBuilder

func (*NodeCRDBuilder) WithNodeCap

func (b *NodeCRDBuilder) WithNodeCap(adapters, totalAdapters, ipv4PerAdapter int) *NodeCRDBuilder

func (*NodeCRDBuilder) WithNodeMetadata

func (b *NodeCRDBuilder) WithNodeMetadata(regionID, instanceType, instanceID, zoneID string) *NodeCRDBuilder

func (*NodeCRDBuilder) WithVSwitchSelectPolicy

func (b *NodeCRDBuilder) WithVSwitchSelectPolicy(policy networkv1beta1.SelectionPolicy) *NodeCRDBuilder

type PodENIBuilder

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

PodENIBuilder builds networkv1beta1.PodENI objects for testing

func NewPodENIBuilder

func NewPodENIBuilder(name, namespace string) *PodENIBuilder

NewPodENIBuilder creates a new PodENIBuilder

func (*PodENIBuilder) Build

func (b *PodENIBuilder) Build() *networkv1beta1.PodENI

func (*PodENIBuilder) WithAllocation

func (b *PodENIBuilder) WithAllocation(allocation networkv1beta1.Allocation) *PodENIBuilder

func (*PodENIBuilder) WithAnnotation

func (b *PodENIBuilder) WithAnnotation(key, value string) *PodENIBuilder

func (*PodENIBuilder) WithENI

func (b *PodENIBuilder) WithENI(eniID string, trunk bool) *PodENIBuilder

func (*PodENIBuilder) WithFinalizer

func (b *PodENIBuilder) WithFinalizer(finalizer string) *PodENIBuilder

func (*PodENIBuilder) WithInstanceID

func (b *PodENIBuilder) WithInstanceID(instanceID string) *PodENIBuilder

func (*PodENIBuilder) WithLabel

func (b *PodENIBuilder) WithLabel(key, value string) *PodENIBuilder

func (*PodENIBuilder) WithPhase

func (b *PodENIBuilder) WithPhase(phase networkv1beta1.Phase) *PodENIBuilder

func (*PodENIBuilder) WithTrunkENIID

func (b *PodENIBuilder) WithTrunkENIID(trunkID string) *PodENIBuilder

func (*PodENIBuilder) WithZone

func (b *PodENIBuilder) WithZone(zone string) *PodENIBuilder

Jump to

Keyboard shortcuts

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