testutil

package
v0.0.0-...-51f9457 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package testutil contains helpers used from CIPD backend unit tests.

Index

Constants

This section is empty.

Variables

View Source
var TestUser = identity.Identity("user:u@example.com")

Functions

func MakeZip

func MakeZip(files map[string]string) []byte

MakeZip produces a zip archive with given files.

Can be used to test reading of CIPD packages.

Types

type MetadataStore

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

MetadataStore implements metadata.Storage using memory, for tests.

Not terribly efficient, shouldn't be used with a large number of entries.

func (*MetadataStore) GetMetadata

func (s *MetadataStore) GetMetadata(c context.Context, prefix string) ([]*api.PrefixMetadata, error)

GetMetadata fetches metadata associated with the given prefix and all parent prefixes.

func (*MetadataStore) Populate

func (s *MetadataStore) Populate(prefix string, m *api.PrefixMetadata) *api.PrefixMetadata

Populate adds a metadata entry to the storage.

If populates Prefix and Fingerprint. Returns the added item. Panics if the prefix is bad or the given metadata is empty.

func (*MetadataStore) Purge

func (s *MetadataStore) Purge(prefix string)

Purge removes metadata entry for some prefix.

Panics if the prefix is bad. Purging missing metadata is noop.

func (*MetadataStore) UpdateMetadata

func (s *MetadataStore) UpdateMetadata(c context.Context, prefix string, cb func(c context.Context, m *api.PrefixMetadata) error) (*api.PrefixMetadata, error)

UpdateMetadata transactionally updates or creates metadata of some prefix.

func (*MetadataStore) VisitMetadata

func (s *MetadataStore) VisitMetadata(c context.Context, prefix string, cb metadata.Visitor) error

VisitMetadata performs depth-first enumeration of the metadata graph.

type MockCAS

type MockCAS struct {
	api.UnimplementedStorageServer

	Err error // an error to return or nil to pass through to the callback

	GetReaderImpl    func(context.Context, *api.ObjectRef) (gs.Reader, error)
	GetObjectURLImpl func(context.Context, *api.GetObjectURLRequest) (*api.ObjectURL, error)
	BeginUploadImpl  func(context.Context, *api.BeginUploadRequest) (*api.UploadOperation, error)
	FinishUploadImpl func(context.Context, *api.FinishUploadRequest) (*api.UploadOperation, error)
	CancelUploadImpl func(context.Context, *api.CancelUploadRequest) (*api.UploadOperation, error)
}

MockCAS implements cas.StorageServer interface.

func (*MockCAS) BeginUpload

BeginUpload implements the corresponding RPC method, see the proto doc.

func (*MockCAS) CancelUpload

CancelUpload implements the corresponding RPC method, see the proto doc.

func (*MockCAS) FinishUpload

FinishUpload implements the corresponding RPC method, see the proto doc.

func (*MockCAS) GetObjectURL

func (m *MockCAS) GetObjectURL(c context.Context, r *api.GetObjectURLRequest) (*api.ObjectURL, error)

GetObjectURL implements the corresponding RPC method, see the proto doc.

func (*MockCAS) GetReader

func (m *MockCAS) GetReader(c context.Context, ref *api.ObjectRef) (gs.Reader, error)

GetReader implements the corresponding method of cas.StorageServer interface.

type MockGSReader

type MockGSReader struct {
	io.ReaderAt

	Len int64
	Gen int64
}

MockGSReader implements gs.Reader on top of a regular io.ReaderAt.

func NewMockGSReader

func NewMockGSReader(data []byte) *MockGSReader

NewMockGSReader constructs MockGSReader from a byte slice.

func (*MockGSReader) Generation

func (m *MockGSReader) Generation() int64

Generation is part of gs.Reader interface.

func (*MockGSReader) Size

func (m *MockGSReader) Size() int64

Size is part of gs.Reader interface.

type NoopGoogleStorage

type NoopGoogleStorage struct {
	Err error // an error to return or nil to panic
}

NoopGoogleStorage implements gs.GoogleStorage interface by returning errors.

Can be embedded into mock implementations that override some subset of methods.

func (NoopGoogleStorage) CancelUpload

func (n NoopGoogleStorage) CancelUpload(c context.Context, uploadURL string) error

CancelUpload is part of gs.GoogleStorage interface.

func (NoopGoogleStorage) Copy

func (n NoopGoogleStorage) Copy(c context.Context, dst string, dstGen int64, src string, srcGen int64) error

Copy is part of gs.GoogleStorage interface.

func (NoopGoogleStorage) Delete

func (n NoopGoogleStorage) Delete(c context.Context, path string) error

Delete is part of gs.GoogleStorage interface.

func (NoopGoogleStorage) Exists

func (n NoopGoogleStorage) Exists(c context.Context, path string) (exists bool, err error)

Exists is part of gs.GoogleStorage interface.

func (NoopGoogleStorage) Publish

func (n NoopGoogleStorage) Publish(c context.Context, dst, src string, srcGen int64) error

Publish is part of gs.GoogleStorage interface.

func (NoopGoogleStorage) Reader

func (n NoopGoogleStorage) Reader(c context.Context, path string, gen int64) (gs.Reader, error)

Reader is part of gs.GoogleStorage interface.

func (NoopGoogleStorage) Size

func (n NoopGoogleStorage) Size(c context.Context, path string) (size uint64, exists bool, err error)

Size is part of gs.GoogleStorage interface.

func (NoopGoogleStorage) StartUpload

func (n NoopGoogleStorage) StartUpload(c context.Context, path string) (uploadURL string, err error)

StartUpload is part of gs.GoogleStorage interface.

Jump to

Keyboard shortcuts

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