juju: github.com/juju/juju/state/backups/testing Index | Files

package testing

import "github.com/juju/juju/state/backups/testing"

Index

Package Files

fakes.go file.go metadata.go suite.go testing.go

func FinishMetadata Uses

func FinishMetadata(meta *backups.Metadata)

FinishMetadata finishes a metadata with test values.

func NewArchive Uses

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

NewArchive returns a new archive file containing the files.

func NewArchiveBasic Uses

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

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

func NewMetadata Uses

func NewMetadata() *backups.Metadata

NewMetadata returns a Metadata to use for testing.

func NewMetadataStarted Uses

func NewMetadataStarted() *backups.Metadata

NewMetadataStarted returns a Metadata to use for testing.

func SHA1SumFile Uses

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

SHA1SumFile returns the RFC 3230 SHA hash of the file.

func SetOrigin Uses

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

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

func UpdateNotes Uses

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

UpdateNotes derives a new Metadata with new notes.

type BaseSuite Uses

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 Uses

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

type FakeBackups Uses

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
    // Filename holds the name of the file to return.
    Filename string

    // 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
    // KeepCopy holds the keepCopy bool that was passed in.
    KeepCopy bool
    // NoDownload holds the noDownload bool that was passed in.
    NoDownload bool
}

FakeBackups is an implementation of Backups to use for testing. TODO: (hml) 2018-04-25 Let's change FakeBackups to using gomock or base.APICaller. Checking calls made and arguments is a pain.

func (*FakeBackups) Add Uses

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

Add stores the backup and returns its new ID.

func (*FakeBackups) Create Uses

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

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

func (*FakeBackups) Get Uses

func (b *FakeBackups) Get(id string) (*backups.Metadata, io.ReadCloser, error)

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

func (*FakeBackups) List Uses

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

List returns the metadata for all stored backups.

func (*FakeBackups) Remove Uses

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

Remove deletes the backup from storage.

func (*FakeBackups) Restore Uses

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

Restore restores a machine to a backed up status.

type FakeStorage Uses

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 Uses

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

func (*FakeStorage) CheckCalled Uses

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 Uses

func (s *FakeStorage) Close() error

func (*FakeStorage) Get Uses

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

func (*FakeStorage) List Uses

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

func (*FakeStorage) Metadata Uses

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

func (*FakeStorage) Remove Uses

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

func (*FakeStorage) SetFile Uses

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

type File Uses

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 Uses

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

AddToArchive adds the file to the tar archive.

Package testing imports 19 packages (graph). Updated 2019-08-26. Refresh now. Tools for package owners.