fakes

package
v0.0.0-...-55c649e Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package fakes contains fake implementations to be used in unit tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GCE

type GCE struct {
	// Images represents the images present in the project.
	Images *compute.ImageList
	// Deprecated represents the set of deprecated images in the project.
	Deprecated map[string]*compute.DeprecationStatus
	// Operations is the sequence of operations that the fake GCE server should return.
	Operations []*compute.Operation
	// contains filtered or unexported fields
}

GCE is a fake GCE implementation. It is intended to be constructed with NewGCEServer.

The GCE struct represents the state of the fake GCE instance. Fields on this struct can be modified to influence the return values of GCE API calls.

GCE should not be considered concurrency-safe. Do not use this struct in a concurrent way.

func GCEForTest

func GCEForTest(t *testing.T, project string) (*GCE, *compute.Service)

GCEForTest encapsulates boilerplate needed for many test cases.

func NewGCEServer

func NewGCEServer(project string) *GCE

NewGCEServer constructs a fake GCE implementation for a given GCE project.

func (*GCE) Client

func (g *GCE) Client() (*compute.Service, error)

Client gets a GCE client to use for accessing the fake GCE server.

func (*GCE) Close

func (g *GCE) Close()

Close closes the fake GCE server.

type GCS

type GCS struct {
	// Objects represents the collection of objects that exist in the fake GCS server.
	// Keys are strings of the form "/<bucket>/<object path>". Values are data that belong
	// in each object.
	Objects map[string][]byte
	// Client is the client to use when accessing the fake GCS server.
	Client *storage.Client
	// Server is the fake GCS server. It uses state from this struct for serving requests.
	Server *httptest.Server
}

GCS contains data and functionality for a fake GCS server. It is intended to be constructed with NewGCSServer.

The GCS struct represents the state of the fake GCS instance. Fields on this struct can be modified to influence the return values of GCS API calls.

The fake GCS server implements a small part of the API discussed here: https://godoc.org/cloud.google.com/go/storage. Only the parts that we need for testing are implemented here. Documentation for the GCS JSON API is here: https://cloud.google.com/storage/docs/json_api/v1/

This struct should not be considered concurrency safe.

func GCSForTest

func GCSForTest(t *testing.T) *GCS

GCSForTest encapsulates boilerplate for getting a GCS object in tests.

func NewGCSServer

func NewGCSServer(ctx context.Context) (*GCS, error)

NewGCSServer constructs a fake GCS implementation.

func (*GCS) Close

func (g *GCS) Close() error

Close closes the fake GCS server and its client.

type Time

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

Time is a fake implementation of the time package.

func NewTime

func NewTime(t time.Time) *Time

NewTime gets a Time instance initialized with the given time.

func (*Time) Now

func (t *Time) Now() time.Time

Now gets the current time.

func (*Time) Sleep

func (t *Time) Sleep(s time.Duration)

Sleep increments the current time by the given duration.

Jump to

Keyboard shortcuts

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