fakes

package
v3.15.1 Latest Latest
Warning

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

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

Documentation

Overview

Package fakes defines methods for instantiating objects which act like resources on a Kubernetes cluster, but are not intended to actually be instantiated on a real, production cluster.

The primary purpose of these objects is to aid writing tests, but that is not this package's only purpose. These objects are also used in debugging logic which is compiled in to production code.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// Name is the default name given to fake objects.
	Name = "foo"

	// Namespace is the default namespace given to fake namespace-scoped objects.
	Namespace = "bar"

	// UID is the default UID given to fake objects.
	UID = "abcd"
)
View Source
const (
	// ExternalDataProviderName is the name of the fake external data provider.
	ExternalDataProviderName = "test-provider"
)

Variables

View Source
var ExternalDataProviderCache = frameworksexternaldata.NewCache()

ExternalDataProviderCache is the cache of external data providers.

Functions

func ConstraintFor added in v3.13.4

func ConstraintFor(kind string) *unstructured.Unstructured

func DenyAllConstraint added in v3.13.4

func DenyAllConstraint() *unstructured.Unstructured

func DenyAllRegoTemplate added in v3.13.4

func DenyAllRegoTemplate() *templates.ConstraintTemplate

func GetTestScheme added in v3.15.0

func GetTestScheme() *runtime.Scheme

func Pod

func Pod(opts ...Opt) *corev1.Pod

Pod creates a Pod for use in testing or debugging logic.

func SyncSetFor added in v3.15.0

func SyncSetFor(name string, kinds []schema.GroupVersionKind) *syncsetv1alpha1.SyncSet

SyncSetFor returns a syncset resource with the given name for the requested set of resources.

func UnstructuredFor added in v3.15.0

func UnstructuredFor(gvk schema.GroupVersionKind, namespace, name string) *unstructured.Unstructured

Types

type CfDataKey added in v3.14.0

type CfDataKey struct {
	Gvk schema.GroupVersionKind
	Key string
}

func KeyFor added in v3.14.0

func KeyFor(obj interface{}) (CfDataKey, error)

KeyFor returns a CfDataKey for the provided resource. Returns error if the resource is not a runtime.Object w/ metadata.

type FailureInjector added in v3.14.0

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

FailureInjector can be used in combination with the SpyReader to simulate transient failures for network calls.

func NewFailureInjector added in v3.14.0

func NewFailureInjector() *FailureInjector

func (*FailureInjector) CheckFailures added in v3.14.0

func (f *FailureInjector) CheckFailures(kind string) bool

CheckFailures looks at the count of failures and returns true if there are still failures for the kind to consume, false otherwise.

func (*FailureInjector) SetFailures added in v3.14.0

func (f *FailureInjector) SetFailures(kind string, failures int)

type FakeCfClient added in v3.14.0

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

FakeCfClient is an CfDataClient for testing.

func (*FakeCfClient) AddData added in v3.14.0

func (f *FakeCfClient) AddData(_ context.Context, data interface{}) (*constraintTypes.Responses, error)

func (*FakeCfClient) Contains added in v3.14.0

func (f *FakeCfClient) Contains(expected map[CfDataKey]interface{}) bool

Contains returns true if all expected resources are in the cache.

func (*FakeCfClient) ContainsGVKs added in v3.15.0

func (f *FakeCfClient) ContainsGVKs(gvks []schema.GroupVersionKind) bool

ContainsGVKs returns true if the cache has data for the gvks given and those gvks only.

func (*FakeCfClient) GetData added in v3.14.0

func (f *FakeCfClient) GetData(key CfDataKey) interface{}

GetData returns data for a CfDataKey. It assumes that the key is present in the FakeCfClient. Also the data returned is not copied and it's meant only for assertions not modifications.

func (*FakeCfClient) HasGVK added in v3.14.0

func (f *FakeCfClient) HasGVK(gvk schema.GroupVersionKind) bool

HasGVK returns true if the cache has any data of the requested kind.

func (*FakeCfClient) Len added in v3.14.0

func (f *FakeCfClient) Len() int

Len returns the number of items in the cache.

func (*FakeCfClient) RemoveData added in v3.14.0

func (f *FakeCfClient) RemoveData(_ context.Context, data interface{}) (*constraintTypes.Responses, error)

func (*FakeCfClient) SetErroring added in v3.14.0

func (f *FakeCfClient) SetErroring(enabled bool)

SetErroring will error out on AddObject or RemoveObject.

type Opt

type Opt func(client.Object)

Opt modifies a client.Object during object instantiation. Generally, if there are conflicting opts (such as two WithName calls), the latter should win. This allows objects to have defaults which can easily be overridden.

func WithLabels

func WithLabels(labels map[string]string) Opt

WithLabels sets the metadata.labels of the object. Overwrites any existing labels on the object.

func WithName

func WithName(name string) Opt

WithName sets the metadata.name of the object.

func WithNamespace

func WithNamespace(namespace string) Opt

WithNamespace sets the metadata.namespace of the object.

func WithUID

func WithUID(uid types.UID) Opt

WithUID sets the metadata.uid of the object.

type SpyReader added in v3.14.0

type SpyReader struct {
	client.Reader
	ListFunc func(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
}

func (SpyReader) List added in v3.14.0

func (r SpyReader) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error

Jump to

Keyboard shortcuts

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