mockservice

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hooks

type Hooks struct {
	BeforeGet    func(ctx context.Context, key string) error
	BeforePut    func(ctx context.Context, key string, data []byte, opts *objectstore.PutOptions) error
	BeforeDelete func(ctx context.Context, key string) error
	BeforeHead   func(ctx context.Context, key string) error
	BeforeList   func(ctx context.Context, prefix string) error
}

Hooks lets tests inject errors for specific operations. Each hook runs before the corresponding Service method touches state. If a hook returns a non-nil error, that error is returned verbatim and no state changes. Nil hook fields are skipped.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is an in-memory objectstore.Service implementation.

ETags are simulated with a monotonically-increasing counter per service instance: every successful Put yields a new ETag, so clients holding a stale ETag will fail IfMatch checks.

Hooks must be configured via SetHooks before any concurrent operations start; SetHooks does not synchronise with in-flight calls.

func New

func New() *Service

New returns an empty in-memory Service.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, key string) error

func (*Service) Get

func (s *Service) Get(ctx context.Context, key string) ([]byte, string, error)

func (*Service) Head

func (s *Service) Head(ctx context.Context, key string) (*objectstore.ObjectInfo, error)

func (*Service) List

func (s *Service) List(ctx context.Context, prefix string) ([]*objectstore.ObjectInfo, error)

func (*Service) Put

func (s *Service) Put(
	ctx context.Context,
	key string,
	data []byte,
	opts *objectstore.PutOptions,
) (string, error)

func (*Service) Reset

func (s *Service) Reset()

Reset clears all stored objects and resets the ETag counter. Hooks are kept.

func (*Service) SetHooks

func (s *Service) SetHooks(h Hooks)

SetHooks configures error-injection hooks. Call before concurrent operations.

Jump to

Keyboard shortcuts

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