Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

74 linhas
1.7 KiB

  1. /*
  2. Copyright 2018 Google LLC
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package spanner
  14. import (
  15. "testing"
  16. "time"
  17. sppb "google.golang.org/genproto/googleapis/spanner/v1"
  18. )
  19. func TestPartitionRoundTrip(t *testing.T) {
  20. t.Parallel()
  21. for i, want := range []Partition{
  22. {rreq: &sppb.ReadRequest{Table: "t"}},
  23. {qreq: &sppb.ExecuteSqlRequest{Sql: "sql"}},
  24. } {
  25. got := serdesPartition(t, i, &want)
  26. if !testEqual(got, want) {
  27. t.Errorf("got: %#v\nwant:%#v", got, want)
  28. }
  29. }
  30. }
  31. func TestBROTIDRoundTrip(t *testing.T) {
  32. t.Parallel()
  33. tm := time.Now()
  34. want := BatchReadOnlyTransactionID{
  35. tid: []byte("tid"),
  36. sid: "sid",
  37. rts: tm,
  38. }
  39. data, err := want.MarshalBinary()
  40. if err != nil {
  41. t.Fatal(err)
  42. }
  43. var got BatchReadOnlyTransactionID
  44. if err := got.UnmarshalBinary(data); err != nil {
  45. t.Fatal(err)
  46. }
  47. if !testEqual(got, want) {
  48. t.Errorf("got: %#v\nwant:%#v", got, want)
  49. }
  50. }
  51. // serdesPartition is a helper that serialize a Partition then deserialize it
  52. func serdesPartition(t *testing.T, i int, p1 *Partition) (p2 Partition) {
  53. var (
  54. data []byte
  55. err error
  56. )
  57. if data, err = p1.MarshalBinary(); err != nil {
  58. t.Fatalf("#%d: encoding failed %v", i, err)
  59. }
  60. if err = p2.UnmarshalBinary(data); err != nil {
  61. t.Fatalf("#%d: decoding failed %v", i, err)
  62. }
  63. return p2
  64. }