coordinatorTest

package
v0.0.0-...-ff9afc2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 43 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestSecret

func TestSecret() types.PrefixSecret

TestSecret returns a testing types.StreamPrefix.

func WithProjectNamespace

func WithProjectNamespace(c context.Context, project string, f func(context.Context))

WithProjectNamespace runs f in project's namespace.

Types

type ArchivalStorage

type ArchivalStorage struct {
	// Storage is the base (archive) Storage instance.
	storage.Storage

	// Opts is the set of archival options that the Storage was instantiated with.
	Opts archive.Options
	// contains filtered or unexported fields
}

ArchivalStorage is a bound GSClient-backed Storage instance.

func (*ArchivalStorage) Close

func (st *ArchivalStorage) Close()

Close implements storage.Storage.

func (*ArchivalStorage) GetSignedURLs

GetSignedURLs implements coordinator.SigningStorage.

type BigTableStorage

type BigTableStorage struct {
	// Testing is the base in-memory BigTable instance that is backing this
	// Storage.
	bigtable.Testing
	// contains filtered or unexported fields
}

BigTableStorage is a bound BigTable-backed Storage instance.

func (*BigTableStorage) Close

func (st *BigTableStorage) Close()

Close implements storage.Storage.

func (*BigTableStorage) GetSignedURLs

GetSignedURLs implements coordinator.Storage.

type Environment

type Environment struct {
	// ServiceID is LogDog's service ID for tests.
	ServiceID string

	// Clock is the installed test clock instance.
	Clock testclock.TestClock

	// AuthState is the fake authentication state.
	AuthState authtest.FakeState

	// Services is the set of installed Coordinator services.
	Services Services

	// BigTable in-memory testing instance.
	BigTable bigtable.Testing
	// GSClient is the test GSClient instance installed (by default) into
	// Services.
	GSClient GSClient

	// StorageCache is the default storage cache instance.
	StorageCache StorageCache
	// contains filtered or unexported fields
}

Environment contains all of the testing facilities that are installed into the Context.

func Install

func Install() (context.Context, *Environment)

Install creates a testing Context and installs common test facilities into it, returning the Environment to which they're bound.

func (*Environment) ActAsAnon

func (e *Environment) ActAsAnon()

ActAsAnon mocks the auth state to indicate an anonymous caller.

It has no access to any project.

func (*Environment) ActAsNobody

func (e *Environment) ActAsNobody()

ActAsNobody mocks the auth state to indicate it's some unknown user calling.

It has no access to any project.

func (*Environment) ActAsReader

func (e *Environment) ActAsReader(project, realm string)

ActAsReader mocks the auth state to indicate it's a prefix reader calling.

func (*Environment) ActAsService

func (e *Environment) ActAsService()

ActAsService mocks the auth state to indicate it's a service calling.

func (*Environment) ActAsWriter

func (e *Environment) ActAsWriter(project, realm string)

ActAsWriter mocks the auth state to indicate it's a prefix writer calling.

func (*Environment) AddProject

func (e *Environment) AddProject(c context.Context, project string)

AddProject ensures there's a config for the given project.

func (*Environment) JoinAdmins

func (e *Environment) JoinAdmins()

JoinAdmins adds the current caller to the administrators group.

func (*Environment) JoinServices

func (e *Environment) JoinServices()

JoinServices adds the current caller to the services group.

func (*Environment) ModProjectConfig

func (e *Environment) ModProjectConfig(c context.Context, project string, fn func(*svcconfig.ProjectConfig))

ModProjectConfig loads the current configuration for the named project, invokes the callback with its contents, and writes the result back to config.

func (*Environment) ModServiceConfig

func (e *Environment) ModServiceConfig(c context.Context, fn func(*svcconfig.Config))

ModServiceConfig loads the current service configuration, invokes the callback with its contents, and writes the result back to config.

type GSClient

type GSClient map[gs.Path][]byte

GSClient is a testing Google Storage client implementation.

func (GSClient) Attrs

func (c GSClient) Attrs(path gs.Path) (*storage.ObjectAttrs, error)

Attrs implements gs.Client.

func (GSClient) Close

func (c GSClient) Close() error

Close implements gs.Client.

func (GSClient) Delete

func (c GSClient) Delete(gs.Path) error

Delete implements gs.Client.

func (GSClient) Get

func (c GSClient) Get(path gs.Path) []byte

Get retrieves the data at the specific path.

func (GSClient) NewReader

func (c GSClient) NewReader(path gs.Path, offset int64, length int64) (io.ReadCloser, error)

NewReader implements gs.Client.

func (GSClient) NewWriter

func (c GSClient) NewWriter(gs.Path) (gs.Writer, error)

NewWriter implements gs.Client.

func (GSClient) Objects

func (c GSClient) Objects(path gs.Path) ([]*storage.ObjectAttrs, error)

Objects implements gs.Client.

func (GSClient) Put

func (c GSClient) Put(path gs.Path, d []byte)

Put sets the data at a given path.

func (GSClient) Rename

func (c GSClient) Rename(gs.Path, gs.Path) error

Rename implements gs.Client.

func (GSClient) SignedURL

func (c GSClient) SignedURL(p gs.Path, opts *storage.SignedURLOptions) (string, error)

SignedURL implements gs.Client.

type Services

type Services struct {
	// Storage returns an intermediate storage instance for use by this service.
	//
	// The caller must close the returned instance if successful.
	//
	// By default, this will return a *BigTableStorage instance bound to the
	// Environment's BigTable instance if the stream is not archived, and an
	// *ArchivalStorage instance bound to this Environment's GSClient instance
	// if the stream is archived.
	ST func(*coordinator.LogStreamState) (coordinator.SigningStorage, error)
}

Services is a testing stub for a coordinator.Services instance that allows the user to configure the various services that are returned.

func (*Services) StorageForStream

func (s *Services) StorageForStream(c context.Context, lst *coordinator.LogStreamState, project string) (coordinator.SigningStorage, error)

StorageForStream implements coordinator.Services.

type StorageCache

type StorageCache struct {
	Base storage.Cache
	// contains filtered or unexported fields
}

StorageCache wraps the default storage cache instance, adding tracking information that is useful for testing.

func (*StorageCache) Clear

func (sc *StorageCache) Clear()

Clear clears the stats for this cache instance.

func (*StorageCache) Get

func (sc *StorageCache) Get(c context.Context, key storage.CacheKey) ([]byte, bool)

Get implements storage.Cache.

func (*StorageCache) Put

func (sc *StorageCache) Put(c context.Context, key storage.CacheKey, v []byte, exp time.Duration)

Put implements storage.Cache.

func (*StorageCache) Stats

func (sc *StorageCache) Stats() StorageCacheStats

Stats returns the stats for this cache instance.

type StorageCacheStats

type StorageCacheStats struct {
	Puts   int
	Hits   int
	Misses int
}

StorageCacheStats expose stats for a StorageCache instance.

type TestStream

type TestStream struct {
	// Project is the project name for this stream.
	Project string
	// Realm is the realm name within the project for this stream.
	Realm string
	// Path is the path of this stream.
	Path types.StreamPath

	// Desc is the log stream descriptor.
	Desc *logpb.LogStreamDescriptor

	// Prefix is the Coordinator LogPrefix entity.
	Prefix *coordinator.LogPrefix
	// Prefix is the Coordinator LogStreamState entity.
	State *coordinator.LogStreamState
	// Prefix is the Coordinator LogStream entity.
	Stream *coordinator.LogStream
}

TestStream returns a testing stream.

func MakeStream

func MakeStream(c context.Context, project, realm string, path types.StreamPath) *TestStream

MakeStream builds a new TestStream with the supplied parameters.

func (*TestStream) DescBytes

func (ts *TestStream) DescBytes() []byte

DescBytes returns the marshalled descriptor bytes.

func (*TestStream) Get

func (ts *TestStream) Get(c context.Context) (err error)

Get reloads all of the entities for this TestStream.

func (*TestStream) LogEntry

func (ts *TestStream) LogEntry(c context.Context, i int) *logpb.LogEntry

LogEntry generates a generic testing log entry for this stream with the specific log stream index.

func (*TestStream) Put

func (ts *TestStream) Put(c context.Context) (err error)

Put adds all of the entities for this TestStream to the datastore.

func (*TestStream) Reload

func (ts *TestStream) Reload(c context.Context)

Reload loads derived fields from their base fields.

func (*TestStream) WithProjectNamespace

func (ts *TestStream) WithProjectNamespace(c context.Context, f func(context.Context))

WithProjectNamespace runs f in proj's namespace, bypassing authentication checks.

Jump to

Keyboard shortcuts

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