Documentation ¶
Overview ¶
Package testutil contains helpers used from CIPD backend unit tests.
Index ¶
- Variables
- func MakeZip(files map[string]string) []byte
- func TestingContext() (context.Context, testclock.TestClock, func(string) context.Context)
- type MetadataStore
- func (s *MetadataStore) GetMetadata(c context.Context, prefix string) ([]*api.PrefixMetadata, error)
- func (s *MetadataStore) Populate(prefix string, m *api.PrefixMetadata) *api.PrefixMetadata
- func (s *MetadataStore) Purge(prefix string)
- func (s *MetadataStore) UpdateMetadata(c context.Context, prefix string, cb func(m *api.PrefixMetadata) error) (*api.PrefixMetadata, error)
- func (s *MetadataStore) VisitMetadata(c context.Context, prefix string, cb metadata.Visitor) error
- type MockCAS
- func (m *MockCAS) BeginUpload(c context.Context, r *api.BeginUploadRequest) (*api.UploadOperation, error)
- func (m *MockCAS) CancelUpload(c context.Context, r *api.CancelUploadRequest) (*api.UploadOperation, error)
- func (m *MockCAS) FinishUpload(c context.Context, r *api.FinishUploadRequest) (*api.UploadOperation, error)
- func (m *MockCAS) GetObjectURL(c context.Context, r *api.GetObjectURLRequest) (*api.ObjectURL, error)
- func (m *MockCAS) GetReader(c context.Context, ref *api.ObjectRef) (gs.Reader, error)
- type MockGSReader
- type NoopGoogleStorage
- func (n NoopGoogleStorage) CancelUpload(c context.Context, uploadURL string) error
- func (n NoopGoogleStorage) Copy(c context.Context, dst string, dstGen int64, src string, srcGen int64) error
- func (n NoopGoogleStorage) Delete(c context.Context, path string) error
- func (n NoopGoogleStorage) Exists(c context.Context, path string) (exists bool, err error)
- func (n NoopGoogleStorage) Publish(c context.Context, dst, src string, srcGen int64) error
- func (n NoopGoogleStorage) Reader(c context.Context, path string, gen int64) (gs.Reader, error)
- func (n NoopGoogleStorage) Size(c context.Context, path string) (size uint64, exists bool, err error)
- func (n NoopGoogleStorage) StartUpload(c context.Context, path string) (uploadURL string, err error)
Constants ¶
This section is empty.
Variables ¶
var TestTime = testclock.TestRecentTimeUTC.Round(time.Millisecond)
var TestUser = identity.Identity("user:u@example.com")
Functions ¶
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(m *api.PrefixMetadata) error) (*api.PrefixMetadata, error)
UpdateMetadata transactionally updates or creates metadata of some prefix.
func (*MetadataStore) VisitMetadata ¶
VisitMetadata performs depth-first enumeration of the metadata graph.
type MockCAS ¶
type MockCAS struct { 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(c 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(c 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(c 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(c context.Context, r *api.GetObjectURLRequest) (*api.ObjectURL, error)
GetObjectURL implements the corresponding RPC method, see the proto doc.
type MockGSReader ¶
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) 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.