testutil

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// KvMeta is the Metadata for mocked KV table.
	KvMeta = sppb.ResultSetMetadata{
		RowType: &sppb.StructType{
			Fields: []*sppb.StructType_Field{
				{
					Name: "Key",
					Type: &sppb.Type{Code: sppb.TypeCode_STRING},
				},
				{
					Name: "Value",
					Type: &sppb.Type{Code: sppb.TypeCode_STRING},
				},
			},
		},
	}
)

Functions

func DecodeResumeToken

func DecodeResumeToken(t []byte) (uint64, error)

DecodeResumeToken decodes a mock resume token into an uint64 integer.

func EncodeResumeToken

func EncodeResumeToken(t uint64) []byte

EncodeResumeToken return mock resume token encoding for an uint64 integer.

Types

type Action

type Action struct {
	Method string
	Err    error
}

Action is a mocked RPC activity that MockCloudSpannerClient will take.

type MockCloudSpanner

type MockCloudSpanner struct {
	sppb.SpannerServer
	// contains filtered or unexported fields
}

MockCloudSpanner is a mock implementation of SpannerServer interface. TODO: make MockCloudSpanner a full-fleged Cloud Spanner implementation.

func NewMockCloudSpanner

func NewMockCloudSpanner(t *testing.T, ts time.Time) *MockCloudSpanner

NewMockCloudSpanner creates a new MockCloudSpanner instance.

func (*MockCloudSpanner) AddMsg

func (m *MockCloudSpanner) AddMsg(err error, resumeToken bool)

AddMsg generates a new mocked row which can be received by client.

func (*MockCloudSpanner) Addr

func (m *MockCloudSpanner) Addr() string

Addr returns the listening address of mock server.

func (*MockCloudSpanner) CreateSession

CreateSession is a placeholder for SpannerServer.CreateSession.

func (*MockCloudSpanner) DeleteSession

DeleteSession is a placeholder for SpannerServer.DeleteSession.

func (*MockCloudSpanner) Done

func (m *MockCloudSpanner) Done()

Done signals an end to a mocked stream.

func (*MockCloudSpanner) ExecuteStreamingSql

ExecuteStreamingSql is a mock implementation of SpannerServer.ExecuteStreamingSql.

func (*MockCloudSpanner) GetSession

GetSession is a placeholder for SpannerServer.GetSession.

func (*MockCloudSpanner) Serve

func (m *MockCloudSpanner) Serve()

Serve runs a MockCloudSpanner listening on a random localhost address.

func (*MockCloudSpanner) Stop

func (m *MockCloudSpanner) Stop()

Stop terminates MockCloudSpanner and closes the serving port.

func (*MockCloudSpanner) StreamingRead

StreamingRead is a placeholder for SpannerServer.StreamingRead.

type MockCloudSpannerClient

type MockCloudSpannerClient struct {
	sppb.SpannerClient
	// contains filtered or unexported fields
}

MockCloudSpannerClient is a mock implementation of sppb.SpannerClient.

func NewMockCloudSpannerClient

func NewMockCloudSpannerClient(t *testing.T, acts ...Action) *MockCloudSpannerClient

NewMockCloudSpannerClient creates new MockCloudSpannerClient instance.

func (*MockCloudSpannerClient) BeginTransaction

BeginTransaction is a placeholder for SpannerClient.BeginTransaction.

func (*MockCloudSpannerClient) CheckActionsConsumed added in v0.17.0

func (m *MockCloudSpannerClient) CheckActionsConsumed()

CheckActionsConsumed checks that all actions have been consumed.

func (*MockCloudSpannerClient) Commit

Commit is a placeholder for SpannerClient.Commit.

func (*MockCloudSpannerClient) CreateSession

CreateSession is a placeholder for SpannerClient.CreateSession.

func (*MockCloudSpannerClient) DeleteSession

DeleteSession is a placeholder for SpannerClient.DeleteSession.

func (*MockCloudSpannerClient) DumpPings

func (m *MockCloudSpannerClient) DumpPings() []string

DumpPings dumps the ping history.

func (*MockCloudSpannerClient) DumpSessions

func (m *MockCloudSpannerClient) DumpSessions() map[string]bool

DumpSessions dumps the internal session table.

func (*MockCloudSpannerClient) ExecuteStreamingSql

ExecuteStreamingSql is a mock implementation of SpannerClient.ExecuteStreamingSql.

func (*MockCloudSpannerClient) Freeze added in v0.11.0

func (m *MockCloudSpannerClient) Freeze()

Freeze stalls all requests.

func (*MockCloudSpannerClient) GetSession

GetSession is a placeholder for SpannerClient.GetSession.

func (*MockCloudSpannerClient) InjectError

func (m *MockCloudSpannerClient) InjectError(method string, err error)

InjectError injects a global error that will be returned by all calls to method regardless of the actions array.

func (*MockCloudSpannerClient) MakeNice

func (m *MockCloudSpannerClient) MakeNice()

MakeNice makes this a nice mock which will not fail on any request.

func (*MockCloudSpannerClient) MakeStrict

func (m *MockCloudSpannerClient) MakeStrict()

MakeStrict makes this a strict mock which will fail on any unexpected request.

func (*MockCloudSpannerClient) PartitionQuery added in v0.20.0

PartitionQuery is a placeholder for SpannerServer.PartitionQuery.

func (*MockCloudSpannerClient) PartitionRead added in v0.20.0

PartitionRead is a placeholder for SpannerServer.PartitionRead.

func (*MockCloudSpannerClient) Rollback

Rollback is a placeholder for SpannerClient.Rollback.

func (*MockCloudSpannerClient) SetActions

func (m *MockCloudSpannerClient) SetActions(acts ...Action)

SetActions sets the new set of expected actions to MockCloudSpannerClient.

func (*MockCloudSpannerClient) StreamingRead

StreamingRead is a placeholder for SpannerClient.StreamingRead.

func (*MockCloudSpannerClient) Unfreeze added in v0.11.0

func (m *MockCloudSpannerClient) Unfreeze()

Unfreeze restores processing requests.

type MockCtlMsg

type MockCtlMsg struct {
	// If ResumeToken == true, mock server will generate a row with
	// resume token.
	ResumeToken bool
	// If Err != nil, mock server will return error in RPC response.
	Err error
}

MockCtlMsg encapsulates PartialResultSet/error that might be sent to client

Jump to

Keyboard shortcuts

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