test

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2020 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Overview

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.

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 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
}

func NewFakeDiscoveryHelper

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

func (*FakeDiscoveryHelper) APIGroups

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

func (*FakeDiscoveryHelper) Refresh

func (dh *FakeDiscoveryHelper) Refresh() error

func (*FakeDiscoveryHelper) ResourceFor

func (*FakeDiscoveryHelper) Resources

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

type FakeDynamicClient

type FakeDynamicClient struct {
	mock.Mock
}

func (*FakeDynamicClient) Create

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) 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 (c *FakeNamespaceClient) Create(obj *v1.Namespace) (*v1.Namespace, error)

func (*FakeNamespaceClient) Delete

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

func (*FakeNamespaceClient) Finalize

func (c *FakeNamespaceClient) Finalize(item *v1.Namespace) (*v1.Namespace, error)

func (*FakeNamespaceClient) Get

func (c *FakeNamespaceClient) Get(name string, opts metav1.GetOptions) (*v1.Namespace, error)

func (*FakeNamespaceClient) List

func (*FakeNamespaceClient) Patch

func (c *FakeNamespaceClient) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*v1.Namespace, error)

func (*FakeNamespaceClient) Update

func (c *FakeNamespaceClient) Update(namespace *v1.Namespace) (*v1.Namespace, error)

func (*FakeNamespaceClient) UpdateStatus

func (c *FakeNamespaceClient) UpdateStatus(namespace *v1.Namespace) (*v1.Namespace, error)

func (*FakeNamespaceClient) Watch

type FakeServerResourcesInterface

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

func NewFakeServerResourcesInterface

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

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 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 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