testutil

package
v0.0.0-...-d3da680 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: Apache-2.0 Imports: 22 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 TestRequestID = trace.TraceID{1, 2, 3, 4, 5}
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(ctx 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(ctx context.Context, prefix string, cb func(ctx 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(ctx 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

func (m *MockCAS) BeginUpload(ctx context.Context, r *api.BeginUploadRequest) (*api.UploadOperation, error)

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

func (*MockCAS) CancelUpload

func (m *MockCAS) CancelUpload(ctx context.Context, r *api.CancelUploadRequest) (*api.UploadOperation, error)

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

func (*MockCAS) FinishUpload

func (m *MockCAS) FinishUpload(ctx context.Context, r *api.FinishUploadRequest) (*api.UploadOperation, error)

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

func (*MockCAS) GetObjectURL

func (m *MockCAS) GetObjectURL(ctx 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(ctx 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(ctx context.Context, uploadURL string) error

CancelUpload is part of gs.GoogleStorage interface.

func (NoopGoogleStorage) Copy

func (n NoopGoogleStorage) Copy(ctx 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(ctx context.Context, path string) error

Delete is part of gs.GoogleStorage interface.

func (NoopGoogleStorage) Exists

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

Exists is part of gs.GoogleStorage interface.

func (NoopGoogleStorage) Publish

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

Publish is part of gs.GoogleStorage interface.

func (NoopGoogleStorage) Reader

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

Reader is part of gs.GoogleStorage interface.

func (NoopGoogleStorage) Size

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

Size is part of gs.GoogleStorage interface.

func (NoopGoogleStorage) StartUpload

func (n NoopGoogleStorage) StartUpload(ctx 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