storage

package
v0.0.0-...-264fa3d Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package storage provides a mock rotate.StorageClient implementation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EnsureBucketExistsResponse

type EnsureBucketExistsResponse struct {
	Err error
}

EnsureBucketExistsResponse is the result of EnsureBucketExists for a given bucket.

type FakeObject

type FakeObject struct {
	Data []byte
}

FakeObject is a cell that can be used by readers and writers alike to manipulate an object's contents.

type Mock

type Mock struct {
	BucketObjects   map[string]map[string]*Responses
	EnsureResponses map[string]*EnsureBucketExistsResponse
	// contains filtered or unexported fields
}

Mock implements the rotate.StorageClient interface to mock object contents.

func WithError

func WithError(err error) *Mock

WithError returns an initial Mock implementation that always returns the given error.

func WithInitialContents

func WithInitialContents(initialContents map[string][]byte, bucket string) *Mock

WithInitialContents returns an initial Mock implementation with objects with the given contents all in the same bucket.

func (*Mock) Clone

func (s *Mock) Clone() *Mock

Clone returns a new Mock with all objects containing the same contents in new cells.

func (*Mock) EnsureBucketExists

func (s *Mock) EnsureBucketExists(_ context.Context, bucket string) error

EnsureBucketExists does nothing.

func (*Mock) Exists

func (s *Mock) Exists(ctx context.Context, bucket, object string) (bool, error)

Exists returns if the object exists in the given bucket.

func (*Mock) IsNotExists

func (s *Mock) IsNotExists(err error) bool

IsNotExists returns whether an error returned from Mock represents the NotExists error.

func (*Mock) Reader

func (s *Mock) Reader(_ context.Context, bucket, object string) (io.ReadCloser, error)

Reader returns a reader object for the given object path.

func (*Mock) Wipeout

func (s *Mock) Wipeout(_ context.Context, bucket string) error

Wipeout deletes all objects under the given bucket.

func (*Mock) Writer

func (s *Mock) Writer(_ context.Context, bucket, object string) (io.WriteCloser, error)

Writer returns a writer object for the given object.

type ObjectReader

type ObjectReader struct {
	ReadErr  error
	CloseErr error
}

ObjectReader is an io.Reader that reads a FakeObject or errors, and returns an error on Close().

func (*ObjectReader) Close

func (r *ObjectReader) Close() error

Close returns the canned CloseErr.

func (*ObjectReader) Read

func (r *ObjectReader) Read([]byte) (int, error)

type ObjectWriter

type ObjectWriter struct {
	M *Mock

	Bucket   string
	Object   string
	Content  []byte
	WriteErr error
	CloseErr error
}

ObjectWriter is an io.Writer that overwrites/creates a FakeObject with Content, or returns an error on Close().

func (*ObjectWriter) Close

func (w *ObjectWriter) Close() error

Close commits Writer changes back to the Storage representation, or returns a canned error.

func (*ObjectWriter) Write

func (w *ObjectWriter) Write(b []byte) (int, error)

Write updates the Writer with b as additional content to be appended, or returns a canned error.

type ReaderResponse

type ReaderResponse struct {
	ReaderMaker func() io.ReadCloser
	Err         error
}

ReaderResponse is the reader or error that Reader returns for a specific object.

type Responses

type Responses struct {
	// If there is content, then it's stored here in Cell.
	Cell      *FakeObject
	ReadResp  *ReaderResponse
	WriteResp *WriterResponse
}

Responses is a representation of the Reader and Writer responses at an object granularity.

type WriterResponse

type WriterResponse struct {
	Writer io.WriteCloser
	Err    error
}

WriterResponse is the writer or error that Writer returns for a specific object.

Jump to

Keyboard shortcuts

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