mirror of
https://github.com/restic/restic.git
synced 2025-10-27 14:18:40 +00:00
Update dependencies
Among others, this updates minio-go, so that the new "eu-west-3" zone for AWS is supported.
This commit is contained in:
160
vendor/cloud.google.com/go/spanner/internal/testutil/mockclient.go
generated
vendored
160
vendor/cloud.google.com/go/spanner/internal/testutil/mockclient.go
generated
vendored
@@ -19,13 +19,13 @@ package testutil
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
proto3 "github.com/golang/protobuf/ptypes/struct"
|
||||
pbt "github.com/golang/protobuf/ptypes/timestamp"
|
||||
@@ -37,17 +37,14 @@ import (
|
||||
|
||||
// Action is a mocked RPC activity that MockCloudSpannerClient will take.
|
||||
type Action struct {
|
||||
method string
|
||||
err error
|
||||
}
|
||||
|
||||
// NewAction creates Action objects.
|
||||
func NewAction(m string, e error) Action {
|
||||
return Action{m, e}
|
||||
Method string
|
||||
Err error
|
||||
}
|
||||
|
||||
// MockCloudSpannerClient is a mock implementation of sppb.SpannerClient.
|
||||
type MockCloudSpannerClient struct {
|
||||
sppb.SpannerClient
|
||||
|
||||
mu sync.Mutex
|
||||
t *testing.T
|
||||
// Live sessions on the client.
|
||||
@@ -62,9 +59,6 @@ type MockCloudSpannerClient struct {
|
||||
nice bool
|
||||
// Client will stall on any requests.
|
||||
freezed chan struct{}
|
||||
|
||||
// embed nil interface so updating proto with new methods don't fail the build
|
||||
sppb.SpannerClient
|
||||
}
|
||||
|
||||
// NewMockCloudSpannerClient creates new MockCloudSpannerClient instance.
|
||||
@@ -91,8 +85,8 @@ func (m *MockCloudSpannerClient) MakeStrict() {
|
||||
m.nice = false
|
||||
}
|
||||
|
||||
// InjectError injects a global error that will be returned by all APIs regardless of
|
||||
// the actions array.
|
||||
// InjectError injects a global error that will be returned by all calls to method
|
||||
// regardless of the actions array.
|
||||
func (m *MockCloudSpannerClient) InjectError(method string, err error) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
@@ -103,7 +97,7 @@ func (m *MockCloudSpannerClient) InjectError(method string, err error) {
|
||||
func (m *MockCloudSpannerClient) SetActions(acts ...Action) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.actions = []Action{}
|
||||
m.actions = nil
|
||||
for _, act := range acts {
|
||||
m.actions = append(m.actions, act)
|
||||
}
|
||||
@@ -178,28 +172,15 @@ func (m *MockCloudSpannerClient) DeleteSession(c context.Context, r *sppb.Delete
|
||||
return &empty.Empty{}, nil
|
||||
}
|
||||
|
||||
// ExecuteSql is a placeholder for SpannerClient.ExecuteSql.
|
||||
func (m *MockCloudSpannerClient) ExecuteSql(c context.Context, r *sppb.ExecuteSqlRequest, opts ...grpc.CallOption) (*sppb.ResultSet, error) {
|
||||
m.ready()
|
||||
return nil, errors.New("Unimplemented")
|
||||
}
|
||||
|
||||
// ExecuteStreamingSql is a mock implementation of SpannerClient.ExecuteStreamingSql.
|
||||
func (m *MockCloudSpannerClient) ExecuteStreamingSql(c context.Context, r *sppb.ExecuteSqlRequest, opts ...grpc.CallOption) (sppb.Spanner_ExecuteStreamingSqlClient, error) {
|
||||
m.ready()
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if err := m.injErr["ExecuteStreamingSql"]; err != nil {
|
||||
act, err := m.expectAction("ExecuteStreamingSql")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(m.actions) == 0 {
|
||||
m.t.Fatalf("unexpected ExecuteStreamingSql executed")
|
||||
}
|
||||
act := m.actions[0]
|
||||
m.actions = m.actions[1:]
|
||||
if act.method != "ExecuteStreamingSql" {
|
||||
m.t.Fatalf("unexpected ExecuteStreamingSql call, want action: %v", act)
|
||||
}
|
||||
wantReq := &sppb.ExecuteSqlRequest{
|
||||
Session: "mocksession",
|
||||
Transaction: &sppb.TransactionSelector{
|
||||
@@ -222,38 +203,24 @@ func (m *MockCloudSpannerClient) ExecuteStreamingSql(c context.Context, r *sppb.
|
||||
},
|
||||
ParamTypes: map[string]*sppb.Type{"var1": &sppb.Type{Code: sppb.TypeCode_STRING}},
|
||||
}
|
||||
if !reflect.DeepEqual(r, wantReq) {
|
||||
if !proto.Equal(r, wantReq) {
|
||||
return nil, fmt.Errorf("got query request: %v, want: %v", r, wantReq)
|
||||
}
|
||||
if act.err != nil {
|
||||
return nil, act.err
|
||||
if act.Err != nil {
|
||||
return nil, act.Err
|
||||
}
|
||||
return nil, errors.New("query never succeeds on mock client")
|
||||
}
|
||||
|
||||
// Read is a placeholder for SpannerClient.Read.
|
||||
func (m *MockCloudSpannerClient) Read(c context.Context, r *sppb.ReadRequest, opts ...grpc.CallOption) (*sppb.ResultSet, error) {
|
||||
m.ready()
|
||||
m.t.Fatalf("Read is unimplemented")
|
||||
return nil, errors.New("Unimplemented")
|
||||
}
|
||||
|
||||
// StreamingRead is a placeholder for SpannerClient.StreamingRead.
|
||||
func (m *MockCloudSpannerClient) StreamingRead(c context.Context, r *sppb.ReadRequest, opts ...grpc.CallOption) (sppb.Spanner_StreamingReadClient, error) {
|
||||
m.ready()
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if err := m.injErr["StreamingRead"]; err != nil {
|
||||
act, err := m.expectAction("StreamingRead", "StreamingReadIndex")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(m.actions) == 0 {
|
||||
m.t.Fatalf("unexpected StreamingRead executed")
|
||||
}
|
||||
act := m.actions[0]
|
||||
m.actions = m.actions[1:]
|
||||
if act.method != "StreamingRead" && act.method != "StreamingIndexRead" {
|
||||
m.t.Fatalf("unexpected read call, want action: %v", act)
|
||||
}
|
||||
wantReq := &sppb.ReadRequest{
|
||||
Session: "mocksession",
|
||||
Transaction: &sppb.TransactionSelector{
|
||||
@@ -284,14 +251,14 @@ func (m *MockCloudSpannerClient) StreamingRead(c context.Context, r *sppb.ReadRe
|
||||
All: false,
|
||||
},
|
||||
}
|
||||
if act.method == "StreamingIndexRead" {
|
||||
if act.Method == "StreamingIndexRead" {
|
||||
wantReq.Index = "idx1"
|
||||
}
|
||||
if !reflect.DeepEqual(r, wantReq) {
|
||||
if !proto.Equal(r, wantReq) {
|
||||
return nil, fmt.Errorf("got query request: %v, want: %v", r, wantReq)
|
||||
}
|
||||
if act.err != nil {
|
||||
return nil, act.err
|
||||
if act.Err != nil {
|
||||
return nil, act.Err
|
||||
}
|
||||
return nil, errors.New("read never succeeds on mock client")
|
||||
}
|
||||
@@ -302,19 +269,12 @@ func (m *MockCloudSpannerClient) BeginTransaction(c context.Context, r *sppb.Beg
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if !m.nice {
|
||||
if err := m.injErr["BeginTransaction"]; err != nil {
|
||||
act, err := m.expectAction("BeginTransaction")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(m.actions) == 0 {
|
||||
m.t.Fatalf("unexpected Begin executed")
|
||||
}
|
||||
act := m.actions[0]
|
||||
m.actions = m.actions[1:]
|
||||
if act.method != "Begin" {
|
||||
m.t.Fatalf("unexpected Begin call, want action: %v", act)
|
||||
}
|
||||
if act.err != nil {
|
||||
return nil, act.err
|
||||
if act.Err != nil {
|
||||
return nil, act.Err
|
||||
}
|
||||
}
|
||||
resp := &sppb.Transaction{Id: []byte("transaction-1")}
|
||||
@@ -330,19 +290,12 @@ func (m *MockCloudSpannerClient) Commit(c context.Context, r *sppb.CommitRequest
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if !m.nice {
|
||||
if err := m.injErr["Commit"]; err != nil {
|
||||
act, err := m.expectAction("Commit")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(m.actions) == 0 {
|
||||
m.t.Fatalf("unexpected Commit executed")
|
||||
}
|
||||
act := m.actions[0]
|
||||
m.actions = m.actions[1:]
|
||||
if act.method != "Commit" {
|
||||
m.t.Fatalf("unexpected Commit call, want action: %v", act)
|
||||
}
|
||||
if act.err != nil {
|
||||
return nil, act.err
|
||||
if act.Err != nil {
|
||||
return nil, act.Err
|
||||
}
|
||||
}
|
||||
return &sppb.CommitResponse{CommitTimestamp: &pbt.Timestamp{Seconds: 1, Nanos: 2}}, nil
|
||||
@@ -354,37 +307,64 @@ func (m *MockCloudSpannerClient) Rollback(c context.Context, r *sppb.RollbackReq
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if !m.nice {
|
||||
if err := m.injErr["Rollback"]; err != nil {
|
||||
act, err := m.expectAction("Rollback")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(m.actions) == 0 {
|
||||
m.t.Fatalf("unexpected Rollback executed")
|
||||
}
|
||||
act := m.actions[0]
|
||||
m.actions = m.actions[1:]
|
||||
if act.method != "Rollback" {
|
||||
m.t.Fatalf("unexpected Rollback call, want action: %v", act)
|
||||
}
|
||||
if act.err != nil {
|
||||
return nil, act.err
|
||||
if act.Err != nil {
|
||||
return nil, act.Err
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *MockCloudSpannerClient) expectAction(methods ...string) (Action, error) {
|
||||
for _, me := range methods {
|
||||
if err := m.injErr[me]; err != nil {
|
||||
return Action{}, err
|
||||
}
|
||||
}
|
||||
if len(m.actions) == 0 {
|
||||
m.t.Fatalf("unexpected %v executed", methods)
|
||||
}
|
||||
act := m.actions[0]
|
||||
m.actions = m.actions[1:]
|
||||
for _, me := range methods {
|
||||
if me == act.Method {
|
||||
return act, nil
|
||||
}
|
||||
}
|
||||
m.t.Fatalf("unexpected call of one of %v, want method %s", methods, act.Method)
|
||||
return Action{}, nil
|
||||
}
|
||||
|
||||
// Freeze stalls all requests.
|
||||
func (m *MockCloudSpannerClient) Freeze() {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.freezed = make(chan struct{})
|
||||
}
|
||||
|
||||
// Unfreeze restores processing requests.
|
||||
func (m *MockCloudSpannerClient) Unfreeze() {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
close(m.freezed)
|
||||
}
|
||||
|
||||
// ready checks conditions before executing requests
|
||||
// TODO: also check injected errors, actions
|
||||
func (m *MockCloudSpannerClient) ready() {
|
||||
// check if client should be freezed
|
||||
<-m.freezed
|
||||
// CheckActionsConsumed checks that all actions have been consumed.
|
||||
func (m *MockCloudSpannerClient) CheckActionsConsumed() {
|
||||
if len(m.actions) != 0 {
|
||||
m.t.Fatalf("unconsumed mock client actions: %v", m.actions)
|
||||
}
|
||||
}
|
||||
|
||||
// ready checks conditions before executing requests
|
||||
// TODO: add checks for injected errors, actions
|
||||
func (m *MockCloudSpannerClient) ready() {
|
||||
m.mu.Lock()
|
||||
freezed := m.freezed
|
||||
m.mu.Unlock()
|
||||
// check if client should be freezed
|
||||
<-freezed
|
||||
}
|
||||
|
||||
5
vendor/cloud.google.com/go/spanner/internal/testutil/mockserver.go
generated
vendored
5
vendor/cloud.google.com/go/spanner/internal/testutil/mockserver.go
generated
vendored
@@ -67,15 +67,14 @@ type MockCtlMsg struct {
|
||||
// MockCloudSpanner is a mock implementation of SpannerServer interface.
|
||||
// TODO: make MockCloudSpanner a full-fleged Cloud Spanner implementation.
|
||||
type MockCloudSpanner struct {
|
||||
sppb.SpannerServer
|
||||
|
||||
s *grpc.Server
|
||||
t *testing.T
|
||||
addr string
|
||||
msgs chan MockCtlMsg
|
||||
readTs time.Time
|
||||
next int
|
||||
|
||||
// embed nil interface so updating proto with new methods don't fail the build
|
||||
sppb.SpannerServer
|
||||
}
|
||||
|
||||
// Addr returns the listening address of mock server.
|
||||
|
||||
Reference in New Issue
Block a user