devserver

package
v0.0.0-...-d046166 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2020 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Overview

Package devserver provides a client for devservers. For more information about devservers, see go/devserver-doc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseGSURL

func ParseGSURL(gsURL string) (bucket, path string, err error)

ParseGSURL parses a Google Cloud Storage URL. It is parsed as:

gs://<bucket>/<path>

Note that path is not prefixed with a slash, which is suitable for use with GCS APIs.

Types

type Client

type Client interface {
	// Open opens a file on Google Cloud Storage at gsURL. gsURL must have a "gs://" scheme.
	// Callers are responsible to close the/ returned io.ReadCloser after use.
	// If the file does not exist, os.ErrNotExist is returned.
	Open(ctx context.Context, gsURL string) (io.ReadCloser, error)

	// TearDown should be called once when the Client is destructed,
	// regardless of whether Open was called or not.
	TearDown() error
}

Client is a client interface to communicate with devservers.

func NewClient

func NewClient(ctx context.Context, devservers []string, tlwServer, dutName string) (Client, error)

NewClient creates a Client from a list of devservers or a TLW server. If tlwServer is non-empty, TLWClient is returned. If devserver contains 1 or more element, RealClient is returned. If the oth are empty, PseudoClient is returned.

type FakeClient

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

FakeClient is a fake implementation of devserver.Client suitable for unit tests.

func NewFakeClient

func NewFakeClient(files map[string][]byte) *FakeClient

NewFakeClient constructs a FakeClient. files is a map from GS URL to content.

func (*FakeClient) Open

func (c *FakeClient) Open(ctx context.Context, gsURL string) (io.ReadCloser, error)

Open simulates a download from Google Cloud Storage.

func (*FakeClient) TearDown

func (c *FakeClient) TearDown() error

TearDown does nothing.

type PseudoClient

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

PseudoClient is an implementation of Client to simulate devservers without credentials.

func NewPseudoClient

func NewPseudoClient(opts ...PseudoClientOption) *PseudoClient

NewPseudoClient creates a PseudoClient.

func (*PseudoClient) Open

func (c *PseudoClient) Open(ctx context.Context, gsURL string) (io.ReadCloser, error)

Open downloads a file on GCS directly from storage.googleapis.com.

func (*PseudoClient) TearDown

func (c *PseudoClient) TearDown() error

TearDown does nothing.

type PseudoClientOption

type PseudoClientOption func(o *pseudoClientOptions)

PseudoClientOption is an option accepted by NewPseudoClient to configure PseudoClient initialization.

func WithBaseURL

func WithBaseURL(baseURL string) PseudoClientOption

WithBaseURL returns an option that specifies the base URL of Google Cloud Storage HTTP API.

func WithHTTPClient

func WithHTTPClient(cl *http.Client) PseudoClientOption

WithHTTPClient returns an option that specifies http.Client used by PseudoClient.

type RealClient

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

RealClient is an implementation of Client to communicate with real devservers.

func NewRealClient

func NewRealClient(ctx context.Context, dsURLs []string, o *RealClientOptions) *RealClient

NewRealClient creates a RealClient. This function checks if devservers at dsURLs are up, and selects a subset of devservers to use. A devserver URL is usually in the form of "http://<hostname>:<port>", without trailing slashes. If we can not verify a devserver is up within ctx's timeout, it is considered down. Be sure to set ctx's timeout carefully since this function can block until it expires if any devserver is down. If o is nil, default options are used. If o is partially nil, defaults are used for them.

func (*RealClient) Open

func (c *RealClient) Open(ctx context.Context, gsURL string) (io.ReadCloser, error)

Open downloads a file on GCS via devservers. It returns an error if no devserver is up.

func (*RealClient) Status

func (c *RealClient) Status() string

Status returns a message describing the status of devservers.

func (*RealClient) TearDown

func (c *RealClient) TearDown() error

TearDown does nothing.

func (*RealClient) UpServerURLs

func (c *RealClient) UpServerURLs() []string

UpServerURLs returns URLs of operational devservers.

type RealClientOptions

type RealClientOptions struct {
	// HTTPClient is HTTP client to use. If nil, defaultHTTPClient is used.
	HTTPClient *http.Client

	// StageRetryWaits instructs retry strategy for stage.
	// Its length is the number of retries and the i-th value is the interval before i-th retry.
	// If nil, default strategy is used. If zero-length slice, no retry is attempted.
	StageRetryWaits []time.Duration
}

RealClientOptions contains options used when connecting to devserver.

type TLWClient

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

TLWClient is an implementation of Client to communicate with Test Lab Services wiring API.

func NewTLWClient

func NewTLWClient(ctx context.Context, tlwserver, dutName string) (*TLWClient, error)

NewTLWClient creates a TLWClient.

func (*TLWClient) Open

func (c *TLWClient) Open(ctx context.Context, gsURL string) (io.ReadCloser, error)

Open downloads a file on GCS from storage.googleapis.com using the TLW API.

func (*TLWClient) TearDown

func (c *TLWClient) TearDown() error

TearDown closes the gRPC connection to the TLW service.

Directories

Path Synopsis
Package devservertest provides a fake implementation of devservers.
Package devservertest provides a fake implementation of devservers.

Jump to

Keyboard shortcuts

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