testing

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

testing package provides structure and functions useful for create test and have predictable outcome or avoid to call real external dependencies

Index

Constants

This section is empty.

Variables

View Source
var (
	// Scheme is the default instance of runtime.Scheme to which types in the Kubernetes API are already registered
	Scheme = runtime.NewScheme()
	// Codecs provides access to encoding and decoding for the scheme
	Codecs = serializer.NewCodecFactory(Scheme)
)

Functions

func DefaultHeaders

func DefaultHeaders() http.Header

DefaultHeaders return a base http.Header configured to mimik an api-server response headers

func ReadBytesFromFile

func ReadBytesFromFile(t *testing.T, path string) []byte

ReadBytesFromFile wrap the login of reading raw bytes from a file at path

func UnstructuredFromFile

func UnstructuredFromFile(t *testing.T, path string) *unstructured.Unstructured

UnstructuredFromFile returns an Unstructured resource reading it from file at path

Types

type TestClientFactory

type TestClientFactory struct {
	util.ClientFactory

	// Client custom RESTClient implementation to return in UnstructuredClientForMapping and used in KubernetesClientSet
	Client resource.RESTClient
	// UnstructuredClientForMappingFunc custom function to call when UnstructuredClientForMapping is invoked
	UnstructuredClientForMappingFunc resource.FakeClientFunc
	// RESTMapper custom RESTMapper implementation that can be used to augment the supported default types
	RESTMapper meta.RESTMapper

	// FakeDynamicClient custom fake dynamic client implementation to return in DynamicClient
	FakeDynamicClient *fakedynamic.FakeDynamicClient
	// contains filtered or unexported fields
}

TestClientFactory extends Factory and provides fake implementation, and affordances for working with kubernetes packages

func NewTestClientFactory

func NewTestClientFactory() *TestClientFactory

NewTestClientFactory return a new TestFactory with a clientgetter that doesn't read from on disk data

func (*TestClientFactory) DynamicClient

func (f *TestClientFactory) DynamicClient() (dynamic.Interface, error)

DynamicClient reimplement the method for returning a simple fake Dynamic client or a custom one if available

func (*TestClientFactory) KubernetesClientSet

func (f *TestClientFactory) KubernetesClientSet() (kubernetes.Interface, error)

KubernetesClientSet reimplement the method for returning only selected kubernetes clients with fake client

func (*TestClientFactory) ToRESTConfig

func (f *TestClientFactory) ToRESTConfig() (*rest.Config, error)

ToRESTConfig reimplement the method for returning a fake clientConfig

func (*TestClientFactory) ToRESTMapper added in v0.4.0

func (f *TestClientFactory) ToRESTMapper() (meta.RESTMapper, error)

ToRESTMapper reimplement the method for returning a custom mapper

func (*TestClientFactory) UnstructuredClientForMapping

func (f *TestClientFactory) UnstructuredClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error)

UnstructuredClientForMapping reimplement the method for returning the custom client set on the test factory

func (*TestClientFactory) WithNamespace

func (f *TestClientFactory) WithNamespace(ns string) *TestClientFactory

WithNamespace is used to mention namespace reactively

Jump to

Keyboard shortcuts

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