fakes

package
v3.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: Apache-2.0 Imports: 14 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 Pod

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

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

Types

type FakeOpa

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

FakeOpa is an OpaDataClient for testing.

func (*FakeOpa) AddData

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

func (*FakeOpa) Contains

func (f *FakeOpa) Contains(expected map[OpaKey]interface{}) bool

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

func (*FakeOpa) HasGVK

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

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

func (*FakeOpa) Len

func (f *FakeOpa) Len() int

Len returns the number of items in the cache.

func (*FakeOpa) RemoveData

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

func (*FakeOpa) SetErroring

func (f *FakeOpa) SetErroring(enabled bool)

SetErroring will error out on AddObject or RemoveObject.

type OpaKey

type OpaKey struct {
	Gvk schema.GroupVersionKind
	Key string
}

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.

Jump to

Keyboard shortcuts

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