test

package
v0.0.0-...-549b0da Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DBUser       = `k8s_01h97g9exfs6bw874x0k567jr7`
	DBApp        = "testapp"
	DBAccount    = "testaccount"
	DBGroup      = "dbo.dosquad.github.io"
	DBAPIVersion = DBGroup + "/v1"
	DBKind       = "DatabaseAccount"
	DBUUID       = "a6533e70-9716-4c68-91a1-851a6fef074f"
	DBJSONData   = `{
		"apiVersion": "` + DBAPIVersion + `",
		"kind": "` + DBKind + `",
		"metadata": {
			"annotations": {},
			"creationTimestamp": "2023-04-03T05:06:07Z",
			"generation": 1,
			"labels": {
				"app": "` + DBApp + `"
			},
			"name": "` + DBAccount + `",
			"namespace": "default",
			"resourceVersion": "10",
			"uid": "` + DBUUID + `"
		},
		"status": {
			"name": "` + DBUser + `",
			"ready": true,
			"stage": "Ready"
		}
	}`
)
View Source
const (
	SecretApp        = "dosquad.github.io/database-account"
	SecretName       = "testaccount"
	SecretAPIVersion = "v1"
	SecretUUID       = "0923871f-c9db-4317-b97c-3099bc3cf84f"
	SecretJSONData   = `{
		"apiVersion": "` + SecretAPIVersion + `",
		"data": {},
		"immutable": true,
		"kind": "Secret",
		"metadata": {
			"creationTimestamp": "2023-04-03T05:06:07Z",
			"name": "` + SecretName + `",
			"namespace": "default",
			"resourceVersion": "123",
			"uid": "` + SecretUUID + `"
		},
		"type": "` + SecretApp + `"
	}`
)

Variables

This section is empty.

Functions

func NewDatabaseAccount

func NewDatabaseAccount() v1.DatabaseAccount

func NewInitDatabaseAccount

func NewInitDatabaseAccount() v1.DatabaseAccount

func NewSecret

func NewSecret() corev1.Secret

Types

type MockClient

type MockClient struct {
	MockClientReader
	MockClientWriter
	MockStatusClient
	MockSubResourceClientConstructor

	OnScheme              func() *runtime.Scheme
	OnRESTMapper          func() meta.RESTMapper
	OnGroupVersionKindFor func(obj runtime.Object) (schema.GroupVersionKind, error)
	OnIsObjectNamespaced  func(obj runtime.Object) (bool, error)
	// contains filtered or unexported fields
}

func NewMockClient

func NewMockClient() *MockClient

func (*MockClient) CallCount

func (m *MockClient) CallCount(name string) (int, bool)

func (*MockClient) CallCountMap

func (m *MockClient) CallCountMap() map[string]int

func (*MockClient) CallCountReset

func (m *MockClient) CallCountReset()

func (*MockClient) GroupVersionKindFor

func (m *MockClient) GroupVersionKindFor(obj runtime.Object) (schema.GroupVersionKind, error)

GroupVersionKindFor returns the GroupVersionKind for the given object.

func (*MockClient) IsObjectNamespaced

func (m *MockClient) IsObjectNamespaced(obj runtime.Object) (bool, error)

IsObjectNamespaced returns true if the GroupVersionKind of the object is namespaced.

func (*MockClient) RESTMapper

func (m *MockClient) RESTMapper() meta.RESTMapper

RESTMapper returns the rest this client is using.

func (*MockClient) Scheme

func (m *MockClient) Scheme() *runtime.Scheme

Scheme returns the scheme this client is using.

type MockClientReader

type MockClientReader struct {
	OnGet  func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error
	OnList func(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
	// contains filtered or unexported fields
}

func (*MockClientReader) Get

func (m *MockClientReader) Get(
	ctx context.Context, key client.ObjectKey,
	obj client.Object, opts ...client.GetOption,
) error

Get retrieves an obj for the given object key from the Kubernetes Cluster. obj must be a struct pointer so that obj can be updated with the response returned by the Server.

func (*MockClientReader) List

List retrieves list of objects for a given namespace and list options. On a successful call, Items field in the list will be populated with the result returned from the server.

type MockClientWriter

type MockClientWriter struct {
	OnCreate      func(ctx context.Context, obj client.Object, opts ...client.CreateOption) error
	OnDelete      func(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error
	OnUpdate      func(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error
	OnPatch       func(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error
	OnDeleteAllOf func(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error
	// contains filtered or unexported fields
}

func (*MockClientWriter) Create

func (m *MockClientWriter) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error

Create saves the object obj in the Kubernetes cluster. obj must be a struct pointer so that obj can be updated with the content returned by the Server.

func (*MockClientWriter) Delete

func (m *MockClientWriter) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error

Delete deletes the given obj from Kubernetes cluster.

func (*MockClientWriter) DeleteAllOf

func (m *MockClientWriter) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error

DeleteAllOf deletes all objects of the given type matching the given options.

func (*MockClientWriter) Patch

func (m *MockClientWriter) Patch(
	ctx context.Context, obj client.Object,
	patch client.Patch, opts ...client.PatchOption,
) error

Patch client.patches the given obj in the Kubernetes cluster. obj must be a struct pointer so that obj can be updated with the content returned by the Server.

func (*MockClientWriter) Update

func (m *MockClientWriter) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error

Update updates the given obj in the Kubernetes cluster. obj must be a struct pointer so that obj can be updated with the content returned by the Server.

type MockRecorder

type MockRecorder struct {
	OnNormalEvent  func(*v1.DatabaseAccount, controller.RecorderReason, string)
	OnWarningEvent func(*v1.DatabaseAccount, controller.RecorderReason, string)
	// contains filtered or unexported fields
}

func NewRecorder

func NewRecorder() *MockRecorder

func (*MockRecorder) CallCount

func (m *MockRecorder) CallCount(name string) (int, bool)

func (*MockRecorder) CallCountMap

func (m *MockRecorder) CallCountMap() map[string]int

func (*MockRecorder) CallCountReset

func (m *MockRecorder) CallCountReset()

func (*MockRecorder) EventReset

func (m *MockRecorder) EventReset()

func (*MockRecorder) GetNormalEvents

func (m *MockRecorder) GetNormalEvents() []MockRecorderMessage

func (*MockRecorder) GetWarningEvents

func (m *MockRecorder) GetWarningEvents() []MockRecorderMessage

func (*MockRecorder) NormalEvent

func (m *MockRecorder) NormalEvent(dbAccount *v1.DatabaseAccount, reason controller.RecorderReason, message string)

func (*MockRecorder) WarningEvent

func (m *MockRecorder) WarningEvent(dbAccount *v1.DatabaseAccount, reason controller.RecorderReason, message string)

type MockRecorderMessage

type MockRecorderMessage struct {
	Reason  controller.RecorderReason
	Message string
}

func NewMockRecorderMessage

func NewMockRecorderMessage(reason controller.RecorderReason, message string) MockRecorderMessage

func (*MockRecorderMessage) GetMessage

func (m *MockRecorderMessage) GetMessage() string

func (*MockRecorderMessage) GetReason

type MockStatusClient

type MockStatusClient struct {
	TestStatusWriter *MockSubResourceWriter
	OnStatus         func() client.SubResourceWriter
	// contains filtered or unexported fields
}

func (*MockStatusClient) CallCount

func (m *MockStatusClient) CallCount(name string) (int, bool)

func (*MockStatusClient) CallCountMap

func (m *MockStatusClient) CallCountMap() map[string]int

func (*MockStatusClient) CallCountReset

func (m *MockStatusClient) CallCountReset()

func (*MockStatusClient) Status

type MockSubResourceClientConstructor

type MockSubResourceClientConstructor struct {
	OnSubResource func(subResource string) client.SubResourceClient
	// contains filtered or unexported fields
}

func (*MockSubResourceClientConstructor) SubResource

SubResourceClientConstructor returns a subresource client for the named subResource. Known upstream subResources usages are:

  • ServiceAccount token creation: sa := &corev1.ServiceAccount{ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"}} token := &authenticationv1.TokenRequest{} c.SubResourceClient("token").Create(ctx, sa, token)

  • Pod eviction creation: pod := &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"}} c.SubResourceClient("eviction").Create(ctx, pod, &policyv1.Eviction{})

  • Pod binding creation: pod := &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"}} binding := &corev1.Binding{Target: corev1.ObjectReference{Name: "my-node"}} c.SubResourceClient("binding").Create(ctx, pod, binding)

  • CertificateSigningRequest approval: csr := &certificatesv1.CertificateSigningRequest{ ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"}, Status: certificatesv1.CertificateSigningRequestStatus{ Conditions: []certificatesv1.[]CertificateSigningRequestCondition{{ Type: certificatesv1.CertificateApproved, Status: corev1.ConditionTrue, }}, }, } c.SubResourceClient("approval").Update(ctx, csr)

  • Scale retrieval: dep := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"}} scale := &autoscalingv1.Scale{} c.SubResourceClient("scale").Get(ctx, dep, scale)

  • Scale update: dep := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Namespace: "foo", Name: "bar"}} scale := &autoscalingv1.Scale{Spec: autoscalingv1.ScaleSpec{Replicas: 2}} c.SubResourceClient("scale").Update(ctx, dep, client.WithSubResourceBody(scale))

type MockSubResourceWriter

type MockSubResourceWriter struct {
	OnCreate func(context.Context, client.Object, client.Object, ...client.SubResourceCreateOption) error
	OnUpdate func(context.Context, client.Object, ...client.SubResourceUpdateOption) error
	OnPatch  func(context.Context, client.Object, client.Patch, ...client.SubResourcePatchOption) error
	// contains filtered or unexported fields
}

func NewMockSubResourceWriter

func NewMockSubResourceWriter() *MockSubResourceWriter

func (*MockSubResourceWriter) CallCount

func (m *MockSubResourceWriter) CallCount(name string) (int, bool)

func (*MockSubResourceWriter) CallCountMap

func (m *MockSubResourceWriter) CallCountMap() map[string]int

func (*MockSubResourceWriter) CallCountReset

func (m *MockSubResourceWriter) CallCountReset()

func (*MockSubResourceWriter) Create

func (m *MockSubResourceWriter) Create(
	ctx context.Context, obj client.Object,
	subResource client.Object, opts ...client.SubResourceCreateOption,
) error

Create saves the subResource object in the Kubernetes cluster. obj must be a struct pointer so that obj can be updated with the content returned by the Server.

func (*MockSubResourceWriter) Patch

Patch patches the given object's subresource. obj must be a struct pointer so that obj can be updated with the content returned by the Server.

func (*MockSubResourceWriter) Update

Update updates the fields corresponding to the status subresource for the given obj. obj must be a struct pointer so that obj can be updated with the content returned by the Server.

Jump to

Keyboard shortcuts

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