-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession_test.go
82 lines (78 loc) · 2.09 KB
/
session_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
_ "embed"
"testing"
sppb "cloud.google.com/go/spanner/apiv1/spannerpb"
"github.com/google/go-cmp/cmp"
"google.golang.org/protobuf/testing/protocmp"
)
func TestParseDirectedReadOption(t *testing.T) {
for _, tt := range []struct {
desc string
option string
want *sppb.DirectedReadOptions
}{
{
desc: "use directed read location option only",
option: "us-central1",
want: &sppb.DirectedReadOptions{
Replicas: &sppb.DirectedReadOptions_IncludeReplicas_{
IncludeReplicas: &sppb.DirectedReadOptions_IncludeReplicas{
ReplicaSelections: []*sppb.DirectedReadOptions_ReplicaSelection{
{
Location: "us-central1",
},
},
AutoFailoverDisabled: true,
},
},
},
},
{
desc: "use directed read location and type option (READ_ONLY)",
option: "us-central1:READ_ONLY",
want: &sppb.DirectedReadOptions{
Replicas: &sppb.DirectedReadOptions_IncludeReplicas_{
IncludeReplicas: &sppb.DirectedReadOptions_IncludeReplicas{
ReplicaSelections: []*sppb.DirectedReadOptions_ReplicaSelection{
{
Location: "us-central1",
Type: sppb.DirectedReadOptions_ReplicaSelection_READ_ONLY,
},
},
AutoFailoverDisabled: true,
},
},
},
},
{
desc: "use directed read location and type option (READ_WRITE)",
option: "us-central1:READ_WRITE",
want: &sppb.DirectedReadOptions{
Replicas: &sppb.DirectedReadOptions_IncludeReplicas_{
IncludeReplicas: &sppb.DirectedReadOptions_IncludeReplicas{
ReplicaSelections: []*sppb.DirectedReadOptions_ReplicaSelection{
{
Location: "us-central1",
Type: sppb.DirectedReadOptions_ReplicaSelection_READ_WRITE,
},
},
AutoFailoverDisabled: true,
},
},
},
},
{
desc: "use invalid type option",
option: "us-central1:READONLY",
want: nil,
},
} {
t.Run(tt.desc, func(t *testing.T) {
got, _ := parseDirectedReadOption(tt.option)
if !cmp.Equal(got, tt.want, protocmp.Transform()) {
t.Errorf("Got = %v, but want = %v", got, tt.want)
}
})
}
}