-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock_types.go
176 lines (145 loc) · 5.44 KB
/
mock_types.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package internal
import (
"context"
"database/sql"
"io"
psdbconnect "github.com/planetscale/airbyte-source/proto/psdbconnect/v1alpha1"
"google.golang.org/grpc"
)
func NewTestLogger() Logger {
return &testSingerLogger{}
}
type testSingerLogger struct {
logMessages []string
records map[string][]Record
state []State
streamSchemas map[string]StreamSchema
}
func (tal *testSingerLogger) Log(message string) {
if tal.logMessages == nil {
tal.logMessages = []string{}
}
tal.logMessages = append(tal.logMessages, message)
}
func (tal *testSingerLogger) Info(message string) {
tal.logMessages = append(tal.logMessages, message)
}
type testPlanetScaleEdgeDatabase struct {
CanConnectFn func(ctx context.Context, ps PlanetScaleSource) error
CanConnectFnInvoked bool
ReadFn func(ctx context.Context, ps PlanetScaleSource, s Stream, tc *psdbconnect.TableCursor) (*SerializedCursor, error)
ReadFnInvoked bool
}
func (tpe *testPlanetScaleEdgeDatabase) CanConnect(ctx context.Context, ps PlanetScaleSource) error {
tpe.CanConnectFnInvoked = true
return tpe.CanConnectFn(ctx, ps)
}
func (tpe *testPlanetScaleEdgeDatabase) Read(ctx context.Context, params ReadParams) (*SerializedCursor, error) {
tpe.ReadFnInvoked = true
return tpe.ReadFn(ctx, params.Source, params.Table, params.LastKnownPosition)
}
func (tpe *testPlanetScaleEdgeDatabase) Close() error {
// TODO implement me
panic("implement me")
}
func (tal *testSingerLogger) Error(message string) {
// TODO implement me
panic("implement me")
}
func (tal *testSingerLogger) State(state State) error {
tal.state = append(tal.state, state)
return nil
}
func (tal *testSingerLogger) Schema(catalog Catalog) error {
// TODO implement me
panic("implement me")
}
func (tal *testSingerLogger) StreamSchema(stream Stream) error {
if tal.streamSchemas == nil {
tal.streamSchemas = map[string]StreamSchema{}
}
tal.streamSchemas[stream.Name] = stream.Schema
return nil
}
func (tal *testSingerLogger) Record(record Record, stream Stream) error {
if tal.records == nil {
tal.records = make(map[string][]Record)
}
if tal.records[stream.Name] == nil {
tal.records[stream.Name] = []Record{}
}
tal.records[stream.Name] = append(tal.records[stream.Name], record)
return nil
}
func (tal *testSingerLogger) Flush(stream Stream) error {
return nil
}
type clientConnectionMock struct {
syncFn func(ctx context.Context, in *psdbconnect.SyncRequest, opts ...grpc.CallOption) (psdbconnect.Connect_SyncClient, error)
syncFnInvoked bool
syncFnInvokedCount int
}
type connectSyncClientMock struct {
lastResponseSent int
syncResponses []*psdbconnect.SyncResponse
syncError error
grpc.ClientStream
}
func (x *connectSyncClientMock) Recv() (*psdbconnect.SyncResponse, error) {
if x.syncError != nil {
return nil, x.syncError
}
if x.lastResponseSent >= len(x.syncResponses) {
return nil, io.EOF
}
x.lastResponseSent += 1
return x.syncResponses[x.lastResponseSent-1], nil
}
func (c *clientConnectionMock) Sync(ctx context.Context, in *psdbconnect.SyncRequest, opts ...grpc.CallOption) (psdbconnect.Connect_SyncClient, error) {
c.syncFnInvoked = true
c.syncFnInvokedCount += 1
return c.syncFn(ctx, in, opts...)
}
type mysqlAccessMock struct {
PingContextFn func(ctx context.Context, source PlanetScaleSource) error
PingContextFnInvoked bool
GetVitessTabletsFn func(ctx context.Context, psc PlanetScaleSource) ([]VitessTablet, error)
GetVitessTabletsFnInvoked bool
GetTableNamesFn func(ctx context.Context, source PlanetScaleSource) ([]string, error)
GetTableNamesFnInvoked bool
GetTableSchemaFn func(ctx context.Context, source PlanetScaleSource, s string) (map[string]StreamProperty, error)
GetTableSchemaFnInvoked bool
GetTablePrimaryKeysFn func(ctx context.Context, source PlanetScaleSource, s string) ([]string, error)
GetTablePrimaryKeysFnInvoked bool
GetVitessShardsFn func(ctx context.Context, psc PlanetScaleSource) ([]string, error)
GetVitessShardsFnInvoked bool
}
func (tma *mysqlAccessMock) PingContext(ctx context.Context, source PlanetScaleSource) error {
tma.PingContextFnInvoked = true
return tma.PingContextFn(ctx, source)
}
func (tma *mysqlAccessMock) GetTableNames(ctx context.Context, source PlanetScaleSource) ([]string, error) {
tma.GetTableNamesFnInvoked = true
return tma.GetTableNamesFn(ctx, source)
}
func (tma *mysqlAccessMock) GetTableSchema(ctx context.Context, source PlanetScaleSource, s string, b bool) (map[string]StreamProperty, error) {
tma.GetTableSchemaFnInvoked = true
return tma.GetTableSchemaFn(ctx, source, s)
}
func (tma *mysqlAccessMock) GetTablePrimaryKeys(ctx context.Context, source PlanetScaleSource, s string) ([]string, error) {
tma.GetTablePrimaryKeysFnInvoked = true
return tma.GetTablePrimaryKeysFn(ctx, source, s)
}
func (mysqlAccessMock) QueryContext(ctx context.Context, psc PlanetScaleSource, query string, args ...interface{}) (*sql.Rows, error) {
// TODO implement me
panic("implement me")
}
func (tma *mysqlAccessMock) GetVitessTablets(ctx context.Context, psc PlanetScaleSource) ([]VitessTablet, error) {
tma.GetVitessTabletsFnInvoked = true
return tma.GetVitessTabletsFn(ctx, psc)
}
func (tma *mysqlAccessMock) GetVitessShards(ctx context.Context, psc PlanetScaleSource) ([]string, error) {
tma.GetVitessShardsFnInvoked = true
return tma.GetVitessShardsFn(ctx, psc)
}
func (mysqlAccessMock) Close() error { return nil }