Documentation ¶
Overview ¶
Package testutil contains helpers used from CIPD backend unit tests.
Index ¶
- Variables
- func MakeZip(files map[string]string) []byte
- func TestingContext(mocks ...authtest.MockedDatum) (context.Context, testclock.TestClock, func(string) context.Context)
- type MetadataStore
- func (s *MetadataStore) GetMetadata(ctx 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(ctx context.Context, prefix string, ...) (*api.PrefixMetadata, error)
- func (s *MetadataStore) VisitMetadata(ctx context.Context, prefix string, cb metadata.Visitor) error
- type MockCAS
- func (m *MockCAS) BeginUpload(ctx context.Context, r *api.BeginUploadRequest) (*api.UploadOperation, error)
- func (m *MockCAS) CancelUpload(ctx context.Context, r *api.CancelUploadRequest) (*api.UploadOperation, error)
- func (m *MockCAS) FinishUpload(ctx context.Context, r *api.FinishUploadRequest) (*api.UploadOperation, error)
- func (m *MockCAS) GetObjectURL(ctx context.Context, r *api.GetObjectURLRequest) (*api.ObjectURL, error)
- func (m *MockCAS) GetReader(ctx context.Context, ref *api.ObjectRef) (gs.Reader, error)
- type MockGSReader
- type NoopGoogleStorage
- func (n NoopGoogleStorage) CancelUpload(ctx context.Context, uploadURL string) error
- func (n NoopGoogleStorage) Copy(ctx context.Context, dst string, dstGen int64, src string, srcGen int64) error
- func (n NoopGoogleStorage) Delete(ctx context.Context, path string) error
- func (n NoopGoogleStorage) Exists(ctx context.Context, path string) (exists bool, err error)
- func (n NoopGoogleStorage) Publish(ctx context.Context, dst, src string, srcGen int64) error
- func (n NoopGoogleStorage) Reader(ctx context.Context, path string, gen int64) (gs.Reader, error)
- func (n NoopGoogleStorage) Size(ctx context.Context, path string) (size uint64, exists bool, err error)
- func (n NoopGoogleStorage) StartUpload(ctx context.Context, path string) (uploadURL string, err error)
Constants ¶
This section is empty.
Variables ¶
var TestRequestID = trace.TraceID{1, 2, 3, 4, 5}
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(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.
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(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) 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.