mocks

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

Kubernetes API Mocks

This folder contains all mocks and machinery to interact with a fake Kubernetes API.

Usage

1. Instantiate Fake

Inside a testing function, instantiate Fake by sharing the test context t and namespace name:

import "github.com/redhat-developer/service-binding-operator/test/mocks"

f := mocks.NewFake(t, "namespace")
2. Add Mocked Objects

Add mocked objects are you need.

f.AddMockedUnstructuredSecret("db-credentials")
3. Instantiate API Clients

Instantiate a fake API client, with:

fakeClient := f.FakeClient()
fakeDynamicClient := f.FakeDynClient()

Unstructured List vs. Typed Resource

As you may notice, in mocks.go we have methods returning typed Kubernetes objects, and sometimes returning unstructured.Unstructured. That happens because when using List with the dynamic client, it fails on parsing objects inside:

item[0]: can't assign or convert v1alpha1.ClusterServiceVersion into unstructured.Unstructured

However, using Unstructured it does not fail during testing.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigMapMock

func ConfigMapMock(ns, name string) *corev1.ConfigMap

ConfigMapMock returns a dummy config-map object.

func SecretMock

func SecretMock(ns, name string, data map[string][]byte) *corev1.Secret

SecretMock returns a Secret based on PostgreSQL operator usage.

func SecretMockRV added in v0.3.0

func SecretMockRV(ns, name string) *corev1.Secret

SecretMockRV returns a Secret with a resourceVersion.

func UnstructuredSecretMock added in v0.1.1

func UnstructuredSecretMock(ns, name string) (*unstructured.Unstructured, error)

func UnstructuredSecretMockRV added in v0.3.0

func UnstructuredSecretMockRV(ns, name string) (*unstructured.Unstructured, error)

Types

type Fake

type Fake struct {
	S *runtime.Scheme // runtime client scheme
	// contains filtered or unexported fields
}

Fake defines all the elements to fake a kubernetes api client.

func NewFake

func NewFake(t *testing.T, ns string) *Fake

NewFake instantiate Fake type.

func (*Fake) AddMockResource added in v0.0.21

func (f *Fake) AddMockResource(resource runtime.Object)

func (*Fake) AddMockedUnstructuredConfigMap added in v0.1.1

func (f *Fake) AddMockedUnstructuredConfigMap(name string)

AddMockedUnstructuredConfigMap add mocked object from ConfigMapMock.

func (*Fake) AddMockedUnstructuredSecret added in v0.1.1

func (f *Fake) AddMockedUnstructuredSecret(name string) *unstructured.Unstructured

AddMockedUnstructuredSecret add mocked object from SecretMock.

func (*Fake) AddMockedUnstructuredSecretRV added in v0.3.0

func (f *Fake) AddMockedUnstructuredSecretRV(name string) *unstructured.Unstructured

AddMockedUnstructuredSecret add mocked object from SecretMock. This secret is created with a resourceVersion

func (*Fake) AddNamespacedMockedSecret added in v0.1.1

func (f *Fake) AddNamespacedMockedSecret(name string, namespace string, data map[string][]byte)

AddNamespacedMockedSecret add mocked object from SecretMock in a namespace which isn't necessarily same as that of the ServiceBinding namespace.

func (*Fake) FakeDynClient

func (f *Fake) FakeDynClient() *fakedynamic.FakeDynamicClient

FakeDynClient returns fake dynamic api client.

Jump to

Keyboard shortcuts

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