You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

62 lines
1.8 KiB

  1. // Copyright 2018 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package spanner
  15. import (
  16. "context"
  17. "io"
  18. "testing"
  19. "cloud.google.com/go/spanner/internal/testutil"
  20. sppb "google.golang.org/genproto/googleapis/spanner/v1"
  21. "google.golang.org/grpc/codes"
  22. )
  23. func TestMockPartitionedUpdate(t *testing.T) {
  24. t.Parallel()
  25. ctx := context.Background()
  26. ms := testutil.NewMockCloudSpanner(t, trxTs)
  27. ms.Serve()
  28. mc := sppb.NewSpannerClient(dialMock(t, ms))
  29. client := &Client{database: "mockdb"}
  30. client.clients = append(client.clients, mc)
  31. stmt := NewStatement("UPDATE t SET x = 2 WHERE x = 1")
  32. rowCount, err := client.PartitionedUpdate(ctx, stmt)
  33. if err != nil {
  34. t.Fatal(err)
  35. }
  36. want := int64(3)
  37. if rowCount != want {
  38. t.Errorf("got %d, want %d", rowCount, want)
  39. }
  40. }
  41. func TestMockPartitionedUpdateWithQuery(t *testing.T) {
  42. t.Parallel()
  43. ctx := context.Background()
  44. ms := testutil.NewMockCloudSpanner(t, trxTs)
  45. ms.AddMsg(io.EOF, true)
  46. ms.Serve()
  47. mc := sppb.NewSpannerClient(dialMock(t, ms))
  48. client := &Client{database: "mockdb"}
  49. client.clients = append(client.clients, mc)
  50. stmt := NewStatement("SELECT t.key key, t.value value FROM t_mock t")
  51. _, err := client.PartitionedUpdate(ctx, stmt)
  52. wantCode := codes.InvalidArgument
  53. if serr, ok := err.(*Error); !ok || serr.Code != wantCode {
  54. t.Errorf("got error %v, want code %s", err, wantCode)
  55. }
  56. }