test

package
Version: v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Overview

Copyright the Velero contributors.

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.

Copyright 2018 the Velero contributors.

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.

Copyright 2018 the Velero contributors.

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

This section is empty.

Variables

This section is empty.

Functions

func AssertDeepEqual

func AssertDeepEqual(t *testing.T, expected, actual interface{}) bool

AssertDeepEqual asserts the semantic equality of objects. This function exists in order to make sure time.Time and metav1.Time objects can be compared correctly. See https://github.com/stretchr/testify/issues/502.

func AssertErrorMatches

func AssertErrorMatches(t *testing.T, expected string, actual error) bool

AssertErrorMatches asserts that if expected is the empty string, actual is nil, otherwise, that actual's error string matches expected.

func CompareActions

func CompareActions(t *testing.T, expected, actual []core.Action)

CompareActions checks slices of actual and expected Actions for equality (ignoring order). It checks that the lengths of the slices are the same, that each actual Action has a corresponding expected Action, and that each expected Action has a corresponding actual Action.

func GetAsMap

func GetAsMap(j string) (map[string]interface{}, error)

func NewFakeControllerRuntimeClient added in v1.6.0

func NewFakeControllerRuntimeClient(t *testing.T, initObjs ...runtime.Object) client.Client

func NewLogger

func NewLogger() logrus.FieldLogger

func TimesAreEqual

func TimesAreEqual(t1, t2 time.Time) bool

TimesAreEqual compares two times for equality. This function is used by equality.Semantic.DeepEqual to compare two time objects without having to call a method.

func UnstructuredOrDie

func UnstructuredOrDie(data string) *unstructured.Unstructured

func ValidatePatch

func ValidatePatch(t *testing.T, action core.Action, expected interface{}, decodeFunc func(*json.Decoder) (interface{}, error))

ValidatePatch tests the validity of an action. It checks that the action is a PatchAction, that the patch decodes from JSON with the provided decode func and has no extraneous fields, and that the decoded patch matches the expected.

Types

type APIResource

type APIResource struct {
	Group      string
	Version    string
	Name       string
	ShortName  string
	Namespaced bool
	Items      []metav1.Object
}

APIResource stores information about a specific Kubernetes API resource.

func CRDs added in v1.2.0

func CRDs(items ...metav1.Object) *APIResource

func Deployments

func Deployments(items ...metav1.Object) *APIResource

func ExtensionsDeployments

func ExtensionsDeployments(items ...metav1.Object) *APIResource

func Namespaces

func Namespaces(items ...metav1.Object) *APIResource

func PVCs

func PVCs(items ...metav1.Object) *APIResource

func PVs

func PVs(items ...metav1.Object) *APIResource

func Pods

func Pods(items ...metav1.Object) *APIResource

Pods returns an APIResource describing core/v1's Pods.

func Secrets

func Secrets(items ...metav1.Object) *APIResource

func ServiceAccounts

func ServiceAccounts(items ...metav1.Object) *APIResource

func VSLs added in v1.2.0

func VSLs(items ...metav1.Object) *APIResource

func (*APIResource) GVR

GVR returns a GroupVersionResource representing the resource.

type APIServer

type APIServer struct {
	VeleroClient    *fake.Clientset
	KubeClient      *kubefake.Clientset
	DynamicClient   *dynamicfake.FakeDynamicClient
	DiscoveryClient *DiscoveryClient
}

APIServer contains in-memory fakes for all of the relevant Kubernetes API server clients.

func NewAPIServer

func NewAPIServer(t *testing.T) *APIServer

NewAPIServer constructs an APIServer with all of its clients initialized.

type DiscoveryClient

type DiscoveryClient struct {
	*discoveryfake.FakeDiscovery
}

DiscoveryClient is a wrapper for the client-go FakeDiscovery struct. It adds some extra functionality that's necessary/useful for Velero tests.

func (*DiscoveryClient) ServerPreferredResources

func (c *DiscoveryClient) ServerPreferredResources() ([]*metav1.APIResourceList, error)

func (*DiscoveryClient) WithAPIResource

func (c *DiscoveryClient) WithAPIResource(resource *APIResource) *DiscoveryClient

WithAPIResource adds the API resource to the discovery client.

type FakeDiscoveryHelper

type FakeDiscoveryHelper struct {
	ResourceList       []*metav1.APIResourceList
	Mapper             meta.RESTMapper
	AutoReturnResource bool
	APIGroupsList      []metav1.APIGroup
	ServerVersionData  *version.Info
}

func NewFakeDiscoveryHelper

func NewFakeDiscoveryHelper(autoReturnResource bool, resources map[schema.GroupVersionResource]schema.GroupVersionResource) *FakeDiscoveryHelper

func (*FakeDiscoveryHelper) APIGroups

func (dh *FakeDiscoveryHelper) APIGroups() []metav1.APIGroup

func (*FakeDiscoveryHelper) KindFor added in v1.5.0

func (*FakeDiscoveryHelper) Refresh

func (dh *FakeDiscoveryHelper) Refresh() error

func (*FakeDiscoveryHelper) ResourceFor

func (*FakeDiscoveryHelper) Resources

func (dh *FakeDiscoveryHelper) Resources() []*metav1.APIResourceList

func (*FakeDiscoveryHelper) ServerVersion added in v1.4.0

func (dh *FakeDiscoveryHelper) ServerVersion() *version.Info

type FakeDynamicClient

type FakeDynamicClient struct {
	mock.Mock
}

func (*FakeDynamicClient) Create

func (*FakeDynamicClient) Delete added in v1.6.0

func (c *FakeDynamicClient) Delete(name string, opts metav1.DeleteOptions) error

func (*FakeDynamicClient) Get

func (*FakeDynamicClient) List

func (*FakeDynamicClient) Patch

func (c *FakeDynamicClient) Patch(name string, data []byte) (*unstructured.Unstructured, error)

func (*FakeDynamicClient) Watch

type FakeDynamicFactory

type FakeDynamicFactory struct {
	mock.Mock
}

func (*FakeDynamicFactory) ClientForGroupVersionResource

func (df *FakeDynamicFactory) ClientForGroupVersionResource(gv schema.GroupVersion, resource metav1.APIResource, namespace string) (client.Dynamic, error)

type FakeFileSystem

type FakeFileSystem struct {
	ReadDirCalls []string
	// contains filtered or unexported fields
}

func NewFakeFileSystem

func NewFakeFileSystem() *FakeFileSystem

func (*FakeFileSystem) Create

func (fs *FakeFileSystem) Create(name string) (io.WriteCloser, error)

func (*FakeFileSystem) DirExists

func (fs *FakeFileSystem) DirExists(path string) (bool, error)

func (*FakeFileSystem) MkdirAll

func (fs *FakeFileSystem) MkdirAll(path string, perm os.FileMode) error

func (*FakeFileSystem) OpenFile added in v1.6.0

func (fs *FakeFileSystem) OpenFile(name string, flag int, perm os.FileMode) (io.WriteCloser, error)

func (*FakeFileSystem) ReadDir

func (fs *FakeFileSystem) ReadDir(dirname string) ([]os.FileInfo, error)

func (*FakeFileSystem) ReadFile

func (fs *FakeFileSystem) ReadFile(filename string) ([]byte, error)

func (*FakeFileSystem) RemoveAll

func (fs *FakeFileSystem) RemoveAll(path string) error

func (*FakeFileSystem) Stat

func (fs *FakeFileSystem) Stat(path string) (os.FileInfo, error)

func (*FakeFileSystem) TempDir

func (fs *FakeFileSystem) TempDir(dir, prefix string) (string, error)

func (*FakeFileSystem) TempFile

func (fs *FakeFileSystem) TempFile(dir, prefix string) (filesystem.NameWriteCloser, error)

func (*FakeFileSystem) WithDirectories

func (fs *FakeFileSystem) WithDirectories(path ...string) *FakeFileSystem

func (*FakeFileSystem) WithDirectory

func (fs *FakeFileSystem) WithDirectory(path string) *FakeFileSystem

func (*FakeFileSystem) WithFile

func (fs *FakeFileSystem) WithFile(path string, data []byte) *FakeFileSystem

func (*FakeFileSystem) WithFileAndMode

func (fs *FakeFileSystem) WithFileAndMode(path string, data []byte, mode os.FileMode) *FakeFileSystem

type FakeMapper

type FakeMapper struct {
	meta.RESTMapper
	AutoReturnResource bool
	Resources          map[schema.GroupVersionResource]schema.GroupVersionResource
}

func (*FakeMapper) ResourceFor

type FakeNamespaceClient

type FakeNamespaceClient struct {
	mock.Mock
}

func (*FakeNamespaceClient) Create

func (*FakeNamespaceClient) Delete

func (c *FakeNamespaceClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error

func (*FakeNamespaceClient) Finalize

func (*FakeNamespaceClient) Get

func (*FakeNamespaceClient) List

func (*FakeNamespaceClient) Patch

func (c *FakeNamespaceClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*corev1api.Namespace, error)

func (*FakeNamespaceClient) Update

func (*FakeNamespaceClient) UpdateStatus

func (c *FakeNamespaceClient) UpdateStatus(ctx context.Context, namespace *corev1api.Namespace, options metav1.UpdateOptions) (*corev1api.Namespace, error)

func (*FakeNamespaceClient) Watch

type FakeServerResourcesInterface

type FakeServerResourcesInterface struct {
	ResourceList []*metav1.APIResourceList
	ApiGroup     []*metav1.APIGroup
	FailedGroups map[schema.GroupVersion]error
	ReturnError  error
}

func NewFakeServerResourcesInterface

func NewFakeServerResourcesInterface(resourceList []*metav1.APIResourceList, apiGroup []*metav1.APIGroup, failedGroups map[schema.GroupVersion]error, returnError error) *FakeServerResourcesInterface

func (*FakeServerResourcesInterface) ServerGroupsAndResources added in v1.4.0

func (di *FakeServerResourcesInterface) ServerGroupsAndResources() ([]*metav1.APIGroup, []*metav1.APIResourceList, error)

func (*FakeServerResourcesInterface) ServerPreferredResources

func (di *FakeServerResourcesInterface) ServerPreferredResources() ([]*metav1.APIResourceList, error)

type FakeVolumeSnapshotter

type FakeVolumeSnapshotter struct {
	// SnapshotID->VolumeID
	SnapshotsTaken sets.String

	// VolumeID -> (SnapshotID, Type, Iops)
	SnapshottableVolumes map[string]VolumeBackupInfo

	// VolumeBackupInfo -> VolumeID
	RestorableVolumes map[VolumeBackupInfo]string

	VolumeID    string
	VolumeIDSet string

	Error error
}

func (*FakeVolumeSnapshotter) CreateSnapshot

func (bs *FakeVolumeSnapshotter) CreateSnapshot(volumeID, volumeAZ string, tags map[string]string) (string, error)

func (*FakeVolumeSnapshotter) CreateVolumeFromSnapshot

func (bs *FakeVolumeSnapshotter) CreateVolumeFromSnapshot(snapshotID, volumeType, volumeAZ string, iops *int64) (string, error)

func (*FakeVolumeSnapshotter) DeleteSnapshot

func (bs *FakeVolumeSnapshotter) DeleteSnapshot(snapshotID string) error

func (*FakeVolumeSnapshotter) GetVolumeID

func (bs *FakeVolumeSnapshotter) GetVolumeID(pv runtime.Unstructured) (string, error)

func (*FakeVolumeSnapshotter) GetVolumeInfo

func (bs *FakeVolumeSnapshotter) GetVolumeInfo(volumeID, volumeAZ string) (string, *int64, error)

func (*FakeVolumeSnapshotter) Init

func (bs *FakeVolumeSnapshotter) Init(config map[string]string) error

func (*FakeVolumeSnapshotter) SetVolumeID

func (bs *FakeVolumeSnapshotter) SetVolumeID(pv runtime.Unstructured, volumeID string) (runtime.Unstructured, error)

type FileStore added in v1.6.0

type FileStore interface {
	// Path returns a path on disk where the secret key defined by
	// the given selector is serialized.
	Path(selector *corev1api.SecretKeySelector) (string, error)
}

FileStore defines operations for interacting with credentials that are stored on a file system.

func NewFakeCredentialsFileStore added in v1.6.0

func NewFakeCredentialsFileStore(path string, err error) FileStore

NewFakeCredentialFileStore creates a FileStore which will return the given path and error when Path is called.

type MockPodCommandExecutor

type MockPodCommandExecutor struct {
	mock.Mock
}

func (*MockPodCommandExecutor) ExecutePodCommand

func (e *MockPodCommandExecutor) ExecutePodCommand(log logrus.FieldLogger, item map[string]interface{}, namespace, name, hookName string, hook *v1.ExecHook) error

type TarWriter added in v1.5.0

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

func NewTarWriter added in v1.5.0

func NewTarWriter(t *testing.T) *TarWriter

func (*TarWriter) Add added in v1.5.0

func (tw *TarWriter) Add(name string, obj interface{}) *TarWriter

func (*TarWriter) AddItems added in v1.5.0

func (tw *TarWriter) AddItems(groupResource string, items ...metav1.Object) *TarWriter

func (*TarWriter) Done added in v1.5.0

func (tw *TarWriter) Done() *bytes.Buffer

type VolumeBackupInfo

type VolumeBackupInfo struct {
	SnapshotID       string
	Type             string
	Iops             *int64
	AvailabilityZone string
}

Jump to

Keyboard shortcuts

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