bucket

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2019 License: BSD-3-Clause Imports: 6 Imported by: 3

Documentation

Overview

Package bucket defines an interface for cloud storage buckets (AWS S3, Google Cloud Storage, etc.).

It also provides a mock implementation backed by local FSDB for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket interface {
	// Read downloads an entry from the bucket.
	//
	// It's the caller's responsibility to close the ReadCloser returned.
	Read(ctx context.Context, name string) (io.ReadCloser, error)

	// Write uploads an entry to the bucket.
	Write(ctx context.Context, name string, data io.Reader) error

	// Delete deletes an entry from the bucket.
	Delete(ctx context.Context, name string) error

	// IsNotExist checks whether an error returned by Read or Delete means the
	// entry does not exist on the bucket.
	IsNotExist(err error) bool
}

Bucket defines the interface for a remote storage bucket (e.g. s3 or gcs).

type Mock

type Mock struct {
	ReadDelay   MockOperationDelay
	WriteDelay  MockOperationDelay
	DeleteDelay MockOperationDelay
	// contains filtered or unexported fields
}

Mock is a mock implementation of Bucket, backed by local FSDB.

func MockBucket

func MockBucket(root string) *Mock

MockBucket creates a new mock Bucket using fsdb.

func (*Mock) Delete

func (m *Mock) Delete(ctx context.Context, name string) error

Delete deletes the file from fsdb.

func (*Mock) IsNotExist

func (m *Mock) IsNotExist(err error) bool

IsNotExist calls fsdb.IsNoSuchKeyError.

func (*Mock) Read

func (m *Mock) Read(ctx context.Context, name string) (io.ReadCloser, error)

Read reads the file from fsdb.

func (*Mock) Write

func (m *Mock) Write(ctx context.Context, name string, data io.Reader) error

Write writes the file to fsdb.

type MockOperationDelay

type MockOperationDelay struct {
	// Before is the delay between the function call and the actual operation.
	Before time.Duration

	// After is the delay between the actual operation completes and the function
	// returns.
	After time.Duration

	// Total is the minimal time the function call should take before returning.
	// Here are some examples assuming the operation itself takes 1ms and we have
	// a Total set to 50ms:
	// - If both Before and After are set to zero, the function call will take
	//   1ms to do the actual operation, then wait for ~49ms for the 50ms Total to
	//   pass, so it returns after approximately 50ms;
	// - If both Before and After are set to 30ms, the function call will first
	//   sleep 30ms, then take 1ms to do the actual operation, then sleep 30ms
	//   again. At this time the Total 50ms is already passed so the function
	//   returns at approximately 61ms.
	Total time.Duration
}

MockOperationDelay defines the delays of an operation (function call). It's useful to mimic network latency in local tests.

Jump to

Keyboard shortcuts

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