testing

package
v0.0.0-...-a002913 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2015 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FinishMetadata

func FinishMetadata(meta *backups.Metadata)

FinishMetadata finishes a metadata with test values.

func NewArchive

func NewArchive(meta *backups.Metadata, files, dump []File) (*bytes.Buffer, error)

NewArchive returns a new archive file containing the files.

func NewArchiveBasic

func NewArchiveBasic(meta *backups.Metadata) (*bytes.Buffer, error)

NewArchiveBasic returns a new archive file with a few files provided.

func NewMetadata

func NewMetadata() *backups.Metadata

NewMetadata returns a Metadata to use for testing.

func NewMetadataStarted

func NewMetadataStarted() *backups.Metadata

NewMetadataStarted returns a Metadata to use for testing.

func SHA1SumFile

func SHA1SumFile(c *gc.C, file *os.File) string

SHA1SumFile returns the RFC 3230 SHA hash of the file.

func SetOrigin

func SetOrigin(meta *backups.Metadata, envUUID, machine, hostname string)

SetOrigin updates the metadata's origin with the privided information.

func UpdateNotes

func UpdateNotes(meta *backups.Metadata, notes string) *backups.Metadata

UpdateNotes derives a new Metadata with new notes.

Types

type BaseSuite

type BaseSuite struct {
	testing.IsolationSuite
	// Meta is a Metadata with standard test values.
	Meta *backups.Metadata
	// Storage is a FileStorage to use when testing backups.
	Storage *FakeStorage
}

The base suite for backups testing.

func (*BaseSuite) SetUpTest

func (s *BaseSuite) SetUpTest(c *gc.C)

type FakeBackups

type FakeBackups struct {
	// Calls contains the order in which methods were called.
	Calls []string

	// Meta holds the Metadata to return.
	Meta *backups.Metadata
	// MetaList holds the Metadata list to return.
	MetaList []*backups.Metadata
	// Archive holds the archive file to return.
	Archive io.ReadCloser
	// Error holds the error to return.
	Error error

	// IDArg holds the ID that was passed in.
	IDArg string
	// PathsArg holds the Paths that was passed in.
	PathsArg *backups.Paths
	// DBInfoArg holds the ConnInfo that was passed in.
	DBInfoArg *backups.DBInfo
	// MetaArg holds the backup metadata that was passed in.
	MetaArg *backups.Metadata
	// PrivateAddr Holds the address for the internal network of the machine.
	PrivateAddr string
	// InstanceId Is the id of the machine to be restored.
	InstanceId instance.Id
	// ArchiveArg holds the backup archive that was passed in.
	ArchiveArg io.Reader
}

FakeBackups is an implementation of Backups to use for testing.

func (*FakeBackups) Add

func (b *FakeBackups) Add(archive io.Reader, meta *backups.Metadata) (string, error)

Add stores the backup and returns its new ID.

func (*FakeBackups) Create

func (b *FakeBackups) Create(meta *backups.Metadata, paths *backups.Paths, dbInfo *backups.DBInfo) error

Create creates and stores a new juju backup archive and returns its associated metadata.

func (*FakeBackups) Get

Get returns the metadata and archive file associated with the ID.

func (*FakeBackups) List

func (b *FakeBackups) List() ([]*backups.Metadata, error)

List returns the metadata for all stored backups.

func (*FakeBackups) Remove

func (b *FakeBackups) Remove(id string) error

Remove deletes the backup from storage.

func (*FakeBackups) Restore

func (b *FakeBackups) Restore(bkpId string, args backups.RestoreArgs) error

Restore restores a machine to a backed up status.

type FakeStorage

type FakeStorage struct {
	// Calls contains the order in which methods were called.
	Calls []string

	// ID is the stored backup ID to return.
	ID string
	// Meta holds the Metadata to return.
	Meta filestorage.Metadata
	// MetaList holds the Metadata list to return.
	MetaList []filestorage.Metadata
	// File holds the stored file to return.
	File io.ReadCloser
	// Error holds the error to return.
	Error error

	// IDArg holds the ID that was passed in.
	IDArg string
	// MetaArg holds the Metadata that was passed in.
	MetaArg filestorage.Metadata
	// FileArg holds the file that was passed in.
	FileArg io.Reader
}

FakeStorage is a FileStorage implementation to use when testing backups.

func (*FakeStorage) Add

func (s *FakeStorage) Add(meta filestorage.Metadata, file io.Reader) (string, error)

func (*FakeStorage) CheckCalled

func (s *FakeStorage) CheckCalled(c *gc.C, id string, meta filestorage.Metadata, file io.Reader, calls ...string)

CheckCalled verifies that the fake was called as expected.

func (*FakeStorage) Close

func (s *FakeStorage) Close() error

func (*FakeStorage) Get

func (*FakeStorage) List

func (s *FakeStorage) List() ([]filestorage.Metadata, error)

func (*FakeStorage) Metadata

func (s *FakeStorage) Metadata(id string) (filestorage.Metadata, error)

func (*FakeStorage) Remove

func (s *FakeStorage) Remove(id string) error

func (*FakeStorage) SetFile

func (s *FakeStorage) SetFile(id string, file io.Reader) error

type File

type File struct {
	// Name is the path to which the file will be identified in the archive.
	Name string
	// Content is the data that will be written to the archive for the file.
	Content string
	// IsDir determines if the file is a regular file or a directory.
	IsDir bool
}

File represents a file during testing.

func (*File) AddToArchive

func (f *File) AddToArchive(archive *tar.Writer) error

AddToArchive adds the file to the tar archive.

Jump to

Keyboard shortcuts

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