Documentation ¶
Overview ¶
Package fakes contains configurable test fakes for an RE service.
Index ¶
- func BuildDir(path string, s *Server, execRoot string) (root *repb.Directory, childDir []*repb.Directory, err error)
- type ActionCache
- func (c *ActionCache) Clear()
- func (c *ActionCache) Get(d digest.Digest) *repb.ActionResult
- func (c *ActionCache) GetActionResult(ctx context.Context, req *repb.GetActionResultRequest) (res *repb.ActionResult, err error)
- func (c *ActionCache) Put(d digest.Digest, res *repb.ActionResult)
- func (c *ActionCache) PutAction(ac *repb.Action, res *repb.ActionResult) digest.Digest
- func (c *ActionCache) Reads(d digest.Digest) int
- func (c *ActionCache) UpdateActionResult(ctx context.Context, req *repb.UpdateActionResultRequest) (res *repb.ActionResult, err error)
- func (c *ActionCache) Writes(d digest.Digest) int
- type CAS
- func (f *CAS) BatchReadBlobs(ctx context.Context, req *repb.BatchReadBlobsRequest) (*repb.BatchReadBlobsResponse, error)
- func (f *CAS) BatchReqs() int
- func (f *CAS) BatchUpdateBlobs(ctx context.Context, req *repb.BatchUpdateBlobsRequest) (*repb.BatchUpdateBlobsResponse, error)
- func (f *CAS) BlobMissingReqs(d digest.Digest) int
- func (f *CAS) BlobReads(d digest.Digest) int
- func (f *CAS) BlobWrites(d digest.Digest) int
- func (f *CAS) Clear()
- func (f *CAS) FindMissingBlobs(ctx context.Context, req *repb.FindMissingBlobsRequest) (*repb.FindMissingBlobsResponse, error)
- func (f *CAS) Get(d digest.Digest) ([]byte, bool)
- func (f *CAS) GetTree(req *repb.GetTreeRequest, ...) error
- func (f *CAS) MaxConcurrency() int
- func (f *CAS) Put(blob []byte) digest.Digest
- func (f *CAS) QueryWriteStatus(context.Context, *bspb.QueryWriteStatusRequest) (*bspb.QueryWriteStatusResponse, error)
- func (f *CAS) Read(req *bspb.ReadRequest, stream bsgrpc.ByteStream_ReadServer) error
- func (f *CAS) Write(stream bsgrpc.ByteStream_WriteServer) (err error)
- func (f *CAS) WriteReqs() int
- type Exec
- func (s *Exec) Clear()
- func (s *Exec) Execute(req *repb.ExecuteRequest, stream regrpc.Execution_ExecuteServer) (err error)
- func (s *Exec) ExecuteCalls() int
- func (s *Exec) GetCapabilities(ctx context.Context, req *repb.GetCapabilitiesRequest) (res *repb.ServerCapabilities, err error)
- func (s *Exec) WaitExecution(req *repb.WaitExecutionRequest, stream regrpc.Execution_WaitExecutionServer) (err error)
- type ExecutionCacheHit
- type InputFile
- type LogStream
- type LogStreams
- type Option
- type OutputDir
- type OutputFile
- type OutputSymlink
- type Reader
- func (f *Reader) QueryWriteStatus(context.Context, *bspb.QueryWriteStatusRequest) (*bspb.QueryWriteStatusResponse, error)
- func (f *Reader) Read(req *bspb.ReadRequest, stream bsgrpc.ByteStream_ReadServer) error
- func (f *Reader) Validate(t *testing.T)
- func (f *Reader) Write(bsgrpc.ByteStream_WriteServer) error
- type Server
- func (s *Server) Clear()
- func (s *Server) NewClientConn(ctx context.Context) (*grpc.ClientConn, error)
- func (s *Server) NewTestClient(ctx context.Context) (*rc.Client, error)
- func (*Server) QueryWriteStatus(context.Context, *bspb.QueryWriteStatusRequest) (*bspb.QueryWriteStatusResponse, error)
- func (s *Server) Read(req *bspb.ReadRequest, stream bsgrpc.ByteStream_ReadServer) error
- func (s *Server) Stop()
- func (s *Server) Write(stream bsgrpc.ByteStream_WriteServer) error
- type StdErr
- type StdErrRaw
- type StdErrStream
- type StdOut
- type StdOutRaw
- type StdOutStream
- type TestEnv
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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) Get ¶
func (c *ActionCache) Get(d digest.Digest) *repb.ActionResult
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.
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 (*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 ¶
BatchReqs returns the total number of BatchUpdateBlobs requests to this fake.
func (*CAS) BatchUpdateBlobs ¶
func (f *CAS) BatchUpdateBlobs(ctx context.Context, req *repb.BatchUpdateBlobsRequest) (*repb.BatchUpdateBlobsResponse, error)
BatchUpdateBlobs implements the corresponding RE API function.
func (*CAS) BlobMissingReqs ¶
BlobMissingReqs returns the total number of GetMissingBlobs requests for a particular digest.
func (*CAS) BlobReads ¶
BlobReads returns the total number of read requests for a particular digest.
func (*CAS) BlobWrites ¶
BlobWrites returns the total number of update requests for a particular digest.
func (*CAS) FindMissingBlobs ¶
func (f *CAS) FindMissingBlobs(ctx context.Context, req *repb.FindMissingBlobsRequest) (*repb.FindMissingBlobsResponse, error)
FindMissingBlobs implements the corresponding RE API function.
func (*CAS) Get ¶
Get returns the bytes corresponding to the given digest, and whether it was found.
func (*CAS) GetTree ¶
func (f *CAS) GetTree(req *repb.GetTreeRequest, stream regrpc.ContentAddressableStorage_GetTreeServer) error
GetTree implements the corresponding RE API function.
func (*CAS) MaxConcurrency ¶
MaxConcurrency returns the maximum number of concurrent Write/Batch requests to this fake.
func (*CAS) QueryWriteStatus ¶
func (f *CAS) QueryWriteStatus(context.Context, *bspb.QueryWriteStatusRequest) (*bspb.QueryWriteStatusResponse, error)
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.
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) 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 ¶
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 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) Put ¶
func (l *LogStreams) Put(name string, chunks ...string) error
Put stores a new logstream.
func (*LogStreams) Read ¶
func (l *LogStreams) Read(req *bspb.ReadRequest, stream bsgrpc.ByteStream_ReadServer) error
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 ¶
OutputFile is to be added as an output of the fake action.
type OutputSymlink ¶
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 ¶
func (f *Reader) QueryWriteStatus(context.Context, *bspb.QueryWriteStatusRequest) (*bspb.QueryWriteStatusResponse, error)
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.
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 (*Server) NewClientConn ¶
NewClientConn returns a gRPC client connction to the server.
func (*Server) NewTestClient ¶
NewTestClient returns a new in-process Client connected to this server.
func (*Server) QueryWriteStatus ¶
func (*Server) QueryWriteStatus(context.Context, *bspb.QueryWriteStatusRequest) (*bspb.QueryWriteStatusResponse, error)
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.
type StdErrStream ¶
type StdErrStream string
StdErrStream causes the fake action to indicate this as the name of the stderr logstream.
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 ¶
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 ¶
func (f *Writer) QueryWriteStatus(context.Context, *bspb.QueryWriteStatusRequest) (*bspb.QueryWriteStatusResponse, error)
QueryWriteStatus implements the corresponding RE API function.
func (*Writer) Read ¶
func (f *Writer) Read(*bspb.ReadRequest, bsgrpc.ByteStream_ReadServer) error
Read implements the corresponding RE API function.