fakes

package
v0.0.0-...-ebb4f00 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package fakes contains configurable test fakes for an RE service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildDir

func BuildDir(path string, s *Server, execRoot string) (root *repb.Directory, childDir []*repb.Directory, err error)

BuildDir builds the directory tree by recursively iterating through the directory. This is similar to tree.go ComputeMerkleTree.

Types

type ActionCache

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

ActionCache implements the RE ActionCache interface, storing fixed results.

func NewActionCache

func NewActionCache() *ActionCache

NewActionCache returns a new empty ActionCache.

func (*ActionCache) Clear

func (c *ActionCache) Clear()

Clear removes all results from the cache.

func (*ActionCache) Get

Get returns a previously saved fake result for the given action digest.

func (*ActionCache) GetActionResult

func (c *ActionCache) GetActionResult(ctx context.Context, req *repb.GetActionResultRequest) (res *repb.ActionResult, err error)

GetActionResult returns a stored result, if it was found.

func (*ActionCache) Put

func (c *ActionCache) Put(d digest.Digest, res *repb.ActionResult)

Put sets a fake result for a given action digest.

func (*ActionCache) PutAction

func (c *ActionCache) PutAction(ac *repb.Action, res *repb.ActionResult) digest.Digest

PutAction sets a fake result for a given action, and returns the action digest.

func (*ActionCache) Reads

func (c *ActionCache) Reads(d digest.Digest) int

Reads returns the number of times GetActionResult was called for a given action digest. These include both successful and unsuccessful reads.

func (*ActionCache) UpdateActionResult

func (c *ActionCache) UpdateActionResult(ctx context.Context, req *repb.UpdateActionResultRequest) (res *repb.ActionResult, err error)

UpdateActionResult sets/updates a given result.

func (*ActionCache) Writes

func (c *ActionCache) Writes(d digest.Digest) int

Writes returns the number of times UpdateActionResult was called for a given action digest.

type CAS

type CAS struct {
	// Maximum batch byte size to verify requests against.
	BatchSize         int
	ReqSleepDuration  time.Duration
	ReqSleepRandomize bool
	PerDigestBlockFn  map[digest.Digest]func()
	// contains filtered or unexported fields
}

CAS is a fake CAS that implements FindMissingBlobs, Read and Write, storing stored blobs in a map. It also counts the number of requests to store received, for validating batching logic.

func NewCAS

func NewCAS() *CAS

NewCAS returns a new empty fake CAS.

func (*CAS) BatchReadBlobs

func (f *CAS) BatchReadBlobs(ctx context.Context, req *repb.BatchReadBlobsRequest) (*repb.BatchReadBlobsResponse, error)

BatchReadBlobs implements the corresponding RE API function.

func (*CAS) BatchReqs

func (f *CAS) BatchReqs() int

BatchReqs returns the total number of BatchUpdateBlobs requests to this fake.

func (*CAS) BatchUpdateBlobs

BatchUpdateBlobs implements the corresponding RE API function.

func (*CAS) BlobMissingReqs

func (f *CAS) BlobMissingReqs(d digest.Digest) int

BlobMissingReqs returns the total number of GetMissingBlobs requests for a particular digest.

func (*CAS) BlobReads

func (f *CAS) BlobReads(d digest.Digest) int

BlobReads returns the total number of read requests for a particular digest.

func (*CAS) BlobWrites

func (f *CAS) BlobWrites(d digest.Digest) int

BlobWrites returns the total number of update requests for a particular digest.

func (*CAS) Clear

func (f *CAS) Clear()

Clear removes all results from the cache.

func (*CAS) FindMissingBlobs

FindMissingBlobs implements the corresponding RE API function.

func (*CAS) Get

func (f *CAS) Get(d digest.Digest) ([]byte, bool)

Get returns the bytes corresponding to the given digest, and whether it was found.

func (*CAS) GetTree

GetTree implements the corresponding RE API function.

func (*CAS) MaxConcurrency

func (f *CAS) MaxConcurrency() int

MaxConcurrency returns the maximum number of concurrent Write/Batch requests to this fake.

func (*CAS) Put

func (f *CAS) Put(blob []byte) digest.Digest

Put adds a given blob to the cache and returns its digest.

func (*CAS) QueryWriteStatus

QueryWriteStatus implements the corresponding RE API function.

func (*CAS) Read

func (f *CAS) Read(req *bspb.ReadRequest, stream bsgrpc.ByteStream_ReadServer) error

Read implements the corresponding RE API function.

func (*CAS) Write

func (f *CAS) Write(stream bsgrpc.ByteStream_WriteServer) (err error)

Write implements the corresponding RE API function.

func (*CAS) WriteReqs

func (f *CAS) WriteReqs() int

WriteReqs returns the total number of Write requests to this fake.

type Exec

type Exec struct {

	// Fake result of an execution.
	// The returned completed result, if any.
	ActionResult *repb.ActionResult
	// Returned completed execution status, if not Ok.
	Status *status.Status
	// Whether action was fake-fetched from the action cache upon execution (simulates a race between
	// two executions).
	Cached bool
	// Any blobs that will be put in the CAS after the fake execution completes.
	OutputBlobs [][]byte
	// Name of the logstream to write stdout to.
	StdOutStreamName string
	// Name of the logstream to write stderr to.
	StdErrStreamName string
	// contains filtered or unexported fields
}

Exec implements the complete RE execution interface for a single execution, returning a fixed result or an error.

func NewExec

func NewExec(t testing.TB, ac *ActionCache, cas *CAS) *Exec

NewExec returns a new empty Exec.

func (*Exec) Clear

func (s *Exec) Clear()

Clear removes all preset results from the fake.

func (*Exec) Execute

func (s *Exec) Execute(req *repb.ExecuteRequest, stream regrpc.Execution_ExecuteServer) (err error)

Execute returns the saved result ActionResult, or a Status. It also puts it in the action cache unless the execute request specified

func (*Exec) ExecuteCalls

func (s *Exec) ExecuteCalls() int

ExecuteCalls returns the total number of Execute calls.

func (*Exec) GetCapabilities

func (s *Exec) GetCapabilities(ctx context.Context, req *repb.GetCapabilitiesRequest) (res *repb.ServerCapabilities, err error)

GetCapabilities returns the fake capabilities.

func (*Exec) WaitExecution

func (s *Exec) WaitExecution(req *repb.WaitExecutionRequest, stream regrpc.Execution_WaitExecutionServer) (err error)

type ExecutionCacheHit

type ExecutionCacheHit bool

ExecutionCacheHit of true will cause the ActionResult to be returned as a cache hit during fake execution.

type InputFile

type InputFile struct {
	Path     string
	Contents string
}

InputFile to be made available to the fake action.

type LogStream

type LogStream struct {
	// Name is the name of the stream. The stream may be downloaded by fetching the resource named
	// instance/logstreams/<name> from bytestream.
	Name string
	// Chunks is a list of the chunks that will be sent by bytestream.
	Chunks []string
}

LogStream adds a new logstream that may be served from the bytestream API.

type LogStreams

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

LogStreams is a fake logstream implementation that implements the bytestream Read command.

func NewLogStreams

func NewLogStreams() *LogStreams

NewLogStreams returns a new empty fake logstream implementation.

func (*LogStreams) Clear

func (l *LogStreams) Clear()

Clear removes all logstreams.

func (*LogStreams) Put

func (l *LogStreams) Put(name string, chunks ...string) error

Put stores a new logstream.

func (*LogStreams) Read

Read implements the Bytestream Read command. The chunks of the requested logstream are sent one at a time.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option provides extra configuration for the test environment.

type OutputDir

type OutputDir struct {
	Path string
}

OutputDir is to be added as an output of the fake action.

type OutputFile

type OutputFile struct {
	Path     string
	Contents string
}

OutputFile is to be added as an output of the fake action.

type OutputSymlink struct {
	Path   string
	Target string
}

OutputSymlink is to be added as an output of the fake action.

type Reader

type Reader struct {
	// Blob is the blob being read.
	Blob []byte
	// Chunks is a list of chunk sizes, in the order they are produced. The sum must be equal to the
	// length of blob.
	Chunks []int
	// ExpectCompressed signals whether this writer should error on non-compressed blob calls.
	ExpectCompressed bool
}

Reader implements ByteStream's Read interface, returning one blob.

func (*Reader) QueryWriteStatus

QueryWriteStatus implements the corresponding RE API function.

func (*Reader) Read

func (f *Reader) Read(req *bspb.ReadRequest, stream bsgrpc.ByteStream_ReadServer) error

Read implements the corresponding RE API function.

func (*Reader) Validate

func (f *Reader) Validate(t *testing.T)

Validate ensures that a Reader has the chunk sizes set correctly.

func (*Reader) Write

Write implements the corresponding RE API function.

type Server

type Server struct {
	Exec        *Exec
	CAS         *CAS
	LogStreams  *LogStreams
	ActionCache *ActionCache
	// contains filtered or unexported fields
}

Server is a configurable fake in-process RBE server for use in integration tests.

func NewServer

func NewServer(t testing.TB) (s *Server, err error)

NewServer creates a server that is ready to accept requests.

func (*Server) Clear

func (s *Server) Clear()

Clear clears the fake results.

func (*Server) NewClientConn

func (s *Server) NewClientConn(ctx context.Context) (*grpc.ClientConn, error)

NewClientConn returns a gRPC client connction to the server.

func (*Server) NewTestClient

func (s *Server) NewTestClient(ctx context.Context) (*rc.Client, error)

NewTestClient returns a new in-process Client connected to this server.

func (*Server) QueryWriteStatus

QueryWriteStatus implements the corresponding RE API function.

func (*Server) Read

func (s *Server) Read(req *bspb.ReadRequest, stream bsgrpc.ByteStream_ReadServer) error

Read will serve both logstream and CAS resources, depending on the resource type indicated in the request.

func (*Server) Stop

func (s *Server) Stop()

Stop shuts down the in process server.

func (*Server) Write

func (s *Server) Write(stream bsgrpc.ByteStream_WriteServer) error

Write writes a blob to CAS.

type StdErr

type StdErr string

StdErr is to be added as an output of the fake action.

type StdErrRaw

type StdErrRaw string

StdErrRaw is to be added as a raw output of the fake action.

type StdErrStream

type StdErrStream string

StdErrStream causes the fake action to indicate this as the name of the stderr logstream.

type StdOut

type StdOut string

StdOut is to be added as an output of the fake action.

type StdOutRaw

type StdOutRaw string

StdOutRaw is to be added as a raw output of the fake action.

type StdOutStream

type StdOutStream string

StdOutStream causes the fake action to indicate this as the name of the stdout logstream.

type TestEnv

type TestEnv struct {
	Client   *rexec.Client
	Server   *Server
	ExecRoot string
	// contains filtered or unexported fields
}

TestEnv is a wrapper for convenient integration tests of remote execution.

func NewTestEnv

func NewTestEnv(t testing.TB) (*TestEnv, func())

NewTestEnv initializes a TestEnv containing a fake server, a client connected to it, and a temporary directory used as execution root for inputs and outputs. It returns the new env and a cleanup function that should be called in the end of the test.

func (*TestEnv) Set

func (e *TestEnv) Set(cmd *command.Command, opt *command.ExecutionOptions, res *command.Result, opts ...Option) (cmdDg, acDg, stderrDg, stdoutDg digest.Digest)

Set sets up the fake to return the given result on the given command execution. It is not possible to make the fake result in a LocalErrorResultStatus or an InterruptedResultStatus.

type Writer

type Writer struct {
	// Buf is a buffer that is set to the contents of a Write call after one is received.
	Buf []byte
	// Err is a copy of the error returned by Write.
	Err error
	// ExpectCompressed signals whether this writer should error on non-compressed blob calls.
	ExpectCompressed bool
}

Writer expects to receive Write calls and fills the buffer.

func (*Writer) QueryWriteStatus

QueryWriteStatus implements the corresponding RE API function.

func (*Writer) Read

Read implements the corresponding RE API function.

func (*Writer) Write

func (f *Writer) Write(stream bsgrpc.ByteStream_WriteServer) (err error)

Write implements the corresponding RE API function.

Jump to

Keyboard shortcuts

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