From 5a8c88956ea11eaf3e8aa8cffadfca06bf58c51d Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Thu, 2 May 2024 09:57:13 +0300 Subject: [PATCH] chore(spanner): remove the need for github.com/stretchr/testify (#9760) * chore(spanner): remove the need for github.com/stretchr/testify Updates https://github.com/googleapis/google-cloud-go/issues/9378 * go mod tidy an additional file * add missing empty line --- spanner/go.mod | 7 +- spanner/go.sum | 7 -- spanner/integration_test.go | 5 +- spanner/mocks_test.go | 84 ++++++-------- spanner/row_test.go | 152 +++++++++++-------------- spanner/test/opentelemetry/test/go.sum | 2 - 6 files changed, 110 insertions(+), 147 deletions(-) diff --git a/spanner/go.mod b/spanner/go.mod index 547d1c6016c7..051f935252ff 100644 --- a/spanner/go.mod +++ b/spanner/go.mod @@ -10,7 +10,6 @@ require ( github.com/google/go-cmp v0.6.0 github.com/googleapis/gax-go/v2 v2.12.3 github.com/json-iterator/go v1.1.12 - github.com/stretchr/testify v1.9.0 go.opencensus.io v0.24.0 go.opentelemetry.io/otel v1.24.0 go.opentelemetry.io/otel/metric v1.24.0 @@ -31,7 +30,6 @@ require ( github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa // indirect - github.com/davecgh/go-spew v1.1.1 // indirect github.com/envoyproxy/go-control-plane v0.12.0 // indirect github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect @@ -43,9 +41,7 @@ require ( github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/rogpeppe/go-internal v1.12.0 // indirect - github.com/stretchr/objx v0.5.2 // indirect + github.com/stretchr/testify v1.9.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect go.opentelemetry.io/otel/sdk v1.24.0 // indirect @@ -56,5 +52,4 @@ require ( golang.org/x/sys v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.5.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/spanner/go.sum b/spanner/go.sum index 242053eda276..04be0903f3f0 100644 --- a/spanner/go.sum +++ b/spanner/go.sum @@ -832,10 +832,8 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lyft/protoc-gen-star v0.6.0/go.mod h1:TGAoBVkt8w7MPG72TrKIu85MIdXwDuzJYeZuUPFPNwA= github.com/lyft/protoc-gen-star v0.6.1/go.mod h1:TGAoBVkt8w7MPG72TrKIu85MIdXwDuzJYeZuUPFPNwA= @@ -869,8 +867,6 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= -github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w= github.com/ruudk/golang-pdf417 v0.0.0-20201230142125-a7e3863a1245/go.mod h1:pQAZKsJ8yyVxGRWYNEm9oFB8ieLgKFnamEyDmSA0BRk= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -880,8 +876,6 @@ github.com/spf13/afero v1.9.2/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcD github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -1564,7 +1558,6 @@ google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/spanner/integration_test.go b/spanner/integration_test.go index 62bc18cefd0b..9063dfbf8f53 100644 --- a/spanner/integration_test.go +++ b/spanner/integration_test.go @@ -45,7 +45,6 @@ import ( v1 "cloud.google.com/go/spanner/apiv1" sppb "cloud.google.com/go/spanner/apiv1/spannerpb" "cloud.google.com/go/spanner/internal" - "github.com/stretchr/testify/require" "go.opencensus.io/stats/view" "go.opencensus.io/tag" "google.golang.org/api/iterator" @@ -2251,7 +2250,9 @@ func TestIntegration_BasicTypes(t *testing.T) { } // cleanup _, err = client.Apply(ctx, []*Mutation{Delete("Types", AllKeys())}) - require.NoError(t, err) + if err != nil { + t.Fatal(err) + } } } diff --git a/spanner/mocks_test.go b/spanner/mocks_test.go index f7553f217e8c..4e5920292ec5 100644 --- a/spanner/mocks_test.go +++ b/spanner/mocks_test.go @@ -14,54 +14,56 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by mockery v2.40.1. DO NOT EDIT. - package spanner import ( - mock "github.com/stretchr/testify/mock" + "fmt" + "google.golang.org/api/iterator" ) -// mockRowIterator is an autogenerated mock type for the mockRowIterator type +// mockRowIterator is a mock for the rowIterator type. type mockRowIterator struct { - mock.Mock -} + pending []mockRow -// Next provides a mock function with given fields: -func (_m *mockRowIterator) Next() (*Row, error) { - ret := _m.Called() + stopCalled bool +} - if len(ret) == 0 { - panic("no return value specified for Next") - } +type mockRow struct { + Row *Row + Error error +} - var r0 *Row - var r1 error - if rf, ok := ret.Get(0).(func() (*Row, error)); ok { - return rf() - } - if rf, ok := ret.Get(0).(func() *Row); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*Row) +func newMockIterator(values ...any) *mockRowIterator { + it := &mockRowIterator{} + for _, row := range values { + switch row := row.(type) { + case *Row: + it.pending = append(it.pending, mockRow{Row: row}) + case error: + it.pending = append(it.pending, mockRow{Error: row}) + default: + panic(fmt.Sprintf("unsupported type %T", row)) } } + return it +} - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) +func (it *mockRowIterator) Next() (*Row, error) { + if len(it.pending) == 0 { + panic("no more rows to return") } - return r0, r1 + v := it.pending[0] + it.pending = it.pending[1:] + + return v.Row, v.Error } -func (_m *mockRowIterator) Do(f func(r *Row) error) error { - defer _m.Stop() +func (it *mockRowIterator) Do(f func(r *Row) error) error { + defer it.Stop() for { - row, err := _m.Next() + row, err := it.Next() switch err { case iterator.Done: return nil @@ -75,21 +77,9 @@ func (_m *mockRowIterator) Do(f func(r *Row) error) error { } } -// Stop provides a mock function with given fields: -func (_m *mockRowIterator) Stop() { - _m.Called() -} - -// newRowIterator creates a new instance of mockRowIterator. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func newRowIterator(t interface { - mock.TestingT - Cleanup(func()) -}) *mockRowIterator { - mock := &mockRowIterator{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock +func (it *mockRowIterator) Stop() { + if it.stopCalled { + panic("Stop has already been called") + } + it.stopCalled = true } diff --git a/spanner/row_test.go b/spanner/row_test.go index 83c2dd662f12..463fec1d35f7 100644 --- a/spanner/row_test.go +++ b/spanner/row_test.go @@ -2104,7 +2104,7 @@ func TestSelectAll(t *testing.T) { type args struct { destination interface{} options []DecodeOptions - mock func(mockIterator *mockRowIterator) + mock *mockRowIterator } type testStruct struct { Col1 int64 @@ -2129,22 +2129,21 @@ func TestSelectAll(t *testing.T) { name: "success: using slice of primitives", args: args{ destination: &[]string{}, - mock: func(mockIterator *mockRowIterator) { - mockIterator.On("Next").Once().Return(&Row{ + mock: newMockIterator( + &Row{ []*sppb.StructType_Field{ {Name: "Col0", Type: stringType()}, }, []*proto3.Value{stringProto("value")}, - }, nil) - mockIterator.On("Next").Once().Return(&Row{ + }, + &Row{ []*sppb.StructType_Field{ {Name: "Col0", Type: stringType()}, }, []*proto3.Value{stringProto("value2")}, - }, nil) - mockIterator.On("Next").Once().Return(nil, iterator.Done) - mockIterator.On("Stop").Once().Return(nil) - }, + }, + iterator.Done, + ), }, want: &[]string{"value", "value2"}, }, @@ -2152,22 +2151,21 @@ func TestSelectAll(t *testing.T) { name: "success: using slice of pointer to primitives", args: args{ destination: &[]*string{}, - mock: func(mockIterator *mockRowIterator) { - mockIterator.On("Next").Once().Return(&Row{ + mock: newMockIterator( + &Row{ []*sppb.StructType_Field{ {Name: "Col0", Type: stringType()}, }, []*proto3.Value{stringProto("value")}, - }, nil) - mockIterator.On("Next").Once().Return(&Row{ + }, + &Row{ []*sppb.StructType_Field{ {Name: "Col0", Type: stringType()}, }, []*proto3.Value{stringProto("value2")}, - }, nil) - mockIterator.On("Next").Once().Return(nil, iterator.Done) - mockIterator.On("Stop").Once().Return(nil) - }, + }, + iterator.Done, + ), }, want: &[]*string{stringPointer("value"), stringPointer("value2")}, }, @@ -2175,8 +2173,8 @@ func TestSelectAll(t *testing.T) { name: "success: using slice of structs", args: args{ destination: &[]testStruct{}, - mock: func(mockIterator *mockRowIterator) { - mockIterator.On("Next").Once().Return(&Row{ + mock: newMockIterator( + &Row{ []*sppb.StructType_Field{ {Name: "Col1", Type: intType()}, {Name: "Col2", Type: floatType()}, @@ -2184,8 +2182,8 @@ func TestSelectAll(t *testing.T) { {Name: "Col4", Type: timeType()}, }, []*proto3.Value{intProto(1), floatProto(1.1), stringProto("value"), timeProto(tm)}, - }, nil) - mockIterator.On("Next").Once().Return(&Row{ + }, + &Row{ []*sppb.StructType_Field{ {Name: "Col1", Type: intType()}, {Name: "Col2", Type: floatType()}, @@ -2193,10 +2191,9 @@ func TestSelectAll(t *testing.T) { {Name: "Col4", Type: timeType()}, }, []*proto3.Value{intProto(2), floatProto(2.2), stringProto("value2"), timeProto(tm.Add(24 * time.Hour))}, - }, nil) - mockIterator.On("Next").Once().Return(nil, iterator.Done) - mockIterator.On("Stop").Once().Return(nil) - }, + }, + iterator.Done, + ), }, want: &[]testStruct{ {Col1: 1, COL2: 1.1, Col3: "value", Col4: tm}, @@ -2207,26 +2204,25 @@ func TestSelectAll(t *testing.T) { name: "success: using slice of pointer to structs", args: args{ destination: &[]*testStruct{}, - mock: func(mockIterator *mockRowIterator) { - mockIterator.On("Next").Once().Return(&Row{ + mock: newMockIterator( + &Row{ []*sppb.StructType_Field{ {Name: "Col1", Type: intType()}, {Name: "Col2", Type: floatType()}, {Name: "Col3", Type: stringType()}, }, []*proto3.Value{intProto(1), floatProto(1.1), stringProto("value")}, - }, nil) - mockIterator.On("Next").Once().Return(&Row{ + }, + &Row{ []*sppb.StructType_Field{ {Name: "Col1", Type: intType()}, {Name: "Col2", Type: floatType()}, {Name: "Col3", Type: stringType()}, }, []*proto3.Value{intProto(2), floatProto(2.2), stringProto("value2")}, - }, nil) - mockIterator.On("Next").Once().Return(nil, iterator.Done) - mockIterator.On("Stop").Once().Return(nil) - }, + }, + iterator.Done, + ), }, want: &[]*testStruct{ {Col1: 1, COL2: 1.1, Col3: "value"}, @@ -2236,8 +2232,8 @@ func TestSelectAll(t *testing.T) { name: "success: when spanner row contains more columns than declared in Go struct but called WithLenient", args: args{ destination: &[]*testStruct{}, - mock: func(mockIterator *mockRowIterator) { - mockIterator.On("Next").Once().Return(&Row{ + mock: newMockIterator( + &Row{ []*sppb.StructType_Field{ {Name: "Col1", Type: intType()}, {Name: "Col2", Type: floatType()}, @@ -2246,11 +2242,10 @@ func TestSelectAll(t *testing.T) { {Name: "Col5", Type: stringType()}, }, []*proto3.Value{intProto(1), floatProto(1.1), stringProto("value"), timeProto(tm), stringProto("value2")}, - }, nil) + }, // failure case - mockIterator.On("Next").Once().Return(nil, iterator.Done) - mockIterator.On("Stop").Once().Return(nil) - }, + iterator.Done, + ), options: []DecodeOptions{WithLenient()}, }, want: &[]*testStruct{ @@ -2261,26 +2256,25 @@ func TestSelectAll(t *testing.T) { name: "success: using prefilled destination should append to the destination", args: args{ destination: &[]*testStruct{{Col1: 3, COL2: 3.3, Col3: "value3"}}, - mock: func(mockIterator *mockRowIterator) { - mockIterator.On("Next").Once().Return(&Row{ + mock: newMockIterator( + &Row{ []*sppb.StructType_Field{ {Name: "Col1", Type: intType()}, {Name: "Col2", Type: floatType()}, {Name: "Col3", Type: stringType()}, }, []*proto3.Value{intProto(1), floatProto(1.1), stringProto("value")}, - }, nil) - mockIterator.On("Next").Once().Return(&Row{ + }, + &Row{ []*sppb.StructType_Field{ {Name: "Col1", Type: intType()}, {Name: "Col2", Type: floatType()}, {Name: "Col3", Type: stringType()}, }, []*proto3.Value{intProto(2), floatProto(2.2), stringProto("value2")}, - }, nil) - mockIterator.On("Next").Once().Return(nil, iterator.Done) - mockIterator.On("Stop").Once().Return(nil) - }, + }, + iterator.Done, + ), }, want: &[]*testStruct{ {Col1: 3, COL2: 3.3, Col3: "value3"}, @@ -2292,8 +2286,8 @@ func TestSelectAll(t *testing.T) { name: "success: using slice of structs with spanner tag annotations", args: args{ destination: &[]testStructWithTag{}, - mock: func(mockIterator *mockRowIterator) { - mockIterator.On("Next").Once().Return(&Row{ + mock: newMockIterator( + &Row{ []*sppb.StructType_Field{ {Name: "Tag1", Type: intType()}, {Name: "Tag2", Type: floatType()}, @@ -2301,8 +2295,8 @@ func TestSelectAll(t *testing.T) { {Name: "Tag4", Type: timeType()}, }, []*proto3.Value{intProto(1), floatProto(1.1), stringProto("value"), timeProto(tm)}, - }, nil) - mockIterator.On("Next").Once().Return(&Row{ + }, + &Row{ []*sppb.StructType_Field{ {Name: "Tag1", Type: intType()}, {Name: "Tag2", Type: floatType()}, @@ -2310,10 +2304,9 @@ func TestSelectAll(t *testing.T) { {Name: "Tag4", Type: timeType()}, }, []*proto3.Value{intProto(2), floatProto(2.2), stringProto("value2"), timeProto(tm.Add(24 * time.Hour))}, - }, nil) - mockIterator.On("Next").Once().Return(nil, iterator.Done) - mockIterator.On("Stop").Once().Return(nil) - }, + }, + iterator.Done, + ), }, want: &[]testStructWithTag{ {Col1: 1, Col2: 1.1, Col3: "value", Col4: tm}, @@ -2324,19 +2317,18 @@ func TestSelectAll(t *testing.T) { name: "failure: in case of error destination will have the partial result", args: args{ destination: &[]*testStruct{{Col1: 3, COL2: 3.3, Col3: "value3"}}, - mock: func(mockIterator *mockRowIterator) { - mockIterator.On("Next").Once().Return(&Row{ + mock: newMockIterator( + &Row{ []*sppb.StructType_Field{ {Name: "Col1", Type: intType()}, {Name: "Col2", Type: floatType()}, {Name: "Col3", Type: stringType()}, }, []*proto3.Value{intProto(1), floatProto(1.1), stringProto("value")}, - }, nil) + }, // failure case - mockIterator.On("Next").Once().Return(nil, errors.New("some error")) - mockIterator.On("Stop").Once().Return(nil) - }, + errors.New("some error"), + ), }, want: &[]*testStruct{ {Col1: 3, COL2: 3.3, Col3: "value3"}, @@ -2348,8 +2340,8 @@ func TestSelectAll(t *testing.T) { name: "failure: when spanner row contains more columns than declared in Go struct", args: args{ destination: &[]*testStruct{{Col1: 3, COL2: 3.3, Col3: "value3"}}, - mock: func(mockIterator *mockRowIterator) { - mockIterator.On("Next").Once().Return(&Row{ + mock: newMockIterator( + &Row{ []*sppb.StructType_Field{ {Name: "Col1", Type: intType()}, {Name: "Col2", Type: floatType()}, @@ -2357,11 +2349,10 @@ func TestSelectAll(t *testing.T) { {Name: "Col4", Type: stringType()}, }, []*proto3.Value{intProto(1), floatProto(1.1), stringProto("value")}, - }, nil) + }, // failure case - mockIterator.On("Next").Once().Return(nil, iterator.Done) - mockIterator.On("Stop").Once().Return(nil) - }, + iterator.Done, + ), }, want: &[]*testStruct{ {Col1: 3, COL2: 3.3, Col3: "value3"}, @@ -2372,8 +2363,8 @@ func TestSelectAll(t *testing.T) { name: "failure: when spanner row contains more columns and destination is primitive slice", args: args{ destination: &[]int64{}, - mock: func(mockIterator *mockRowIterator) { - mockIterator.On("Next").Once().Return(&Row{ + mock: newMockIterator( + &Row{ []*sppb.StructType_Field{ {Name: "Col1", Type: intType()}, {Name: "Col2", Type: floatType()}, @@ -2381,11 +2372,10 @@ func TestSelectAll(t *testing.T) { {Name: "Col4", Type: stringType()}, }, []*proto3.Value{intProto(1), floatProto(1.1), stringProto("value")}, - }, nil) + }, // failure case - mockIterator.On("Next").Once().Return(nil, iterator.Done) - mockIterator.On("Stop").Once().Return(nil) - }, + iterator.Done, + ), }, want: &[]int64{}, wantErr: true, @@ -2394,8 +2384,8 @@ func TestSelectAll(t *testing.T) { name: "failure: when spanner row contains more columns and destination is primitive slice using WithLenient", args: args{ destination: &[]int64{}, - mock: func(mockIterator *mockRowIterator) { - mockIterator.On("Next").Once().Return(&Row{ + mock: newMockIterator( + &Row{ []*sppb.StructType_Field{ {Name: "Col1", Type: intType()}, {Name: "Col2", Type: floatType()}, @@ -2403,11 +2393,10 @@ func TestSelectAll(t *testing.T) { {Name: "Col4", Type: stringType()}, }, []*proto3.Value{intProto(1), floatProto(1.1), stringProto("value")}, - }, nil) + }, // failure case - mockIterator.On("Next").Once().Return(nil, iterator.Done) - mockIterator.On("Stop").Once().Return(nil) - }, + iterator.Done, + ), options: []DecodeOptions{WithLenient()}, }, want: &[]int64{}, @@ -2416,10 +2405,7 @@ func TestSelectAll(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - mockIterator := &mockRowIterator{} - if tt.args.mock != nil { - tt.args.mock(mockIterator) - } + mockIterator := tt.args.mock if err := SelectAll(mockIterator, tt.args.destination, tt.args.options...); (err != nil) != tt.wantErr { t.Errorf("SelectAll() error = %v, wantErr %v", err, tt.wantErr) } diff --git a/spanner/test/opentelemetry/test/go.sum b/spanner/test/opentelemetry/test/go.sum index 5ec0a67facd0..a01335c58370 100644 --- a/spanner/test/opentelemetry/test/go.sum +++ b/spanner/test/opentelemetry/test/go.sum @@ -1652,7 +1652,6 @@ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qq github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w= github.com/ruudk/golang-pdf417 v0.0.0-20201230142125-a7e3863a1245/go.mod h1:pQAZKsJ8yyVxGRWYNEm9oFB8ieLgKFnamEyDmSA0BRk= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -1664,7 +1663,6 @@ github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8w github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=