-
Notifications
You must be signed in to change notification settings - Fork 22
/
testing_write.go
153 lines (125 loc) · 3.75 KB
/
testing_write.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
package plugin
import (
"context"
"math/rand"
"testing"
"github.com/apache/arrow/go/v13/arrow"
"github.com/cloudquery/plugin-sdk/v4/schema"
)
type WriterTestSuite struct {
tests WriterTestSuiteTests
plugin *Plugin
// AllowNull is a custom func to determine whether a data type may be correctly represented as null.
// Destinations that have problems representing some data types should provide a custom implementation here.
// If this param is empty, the default is to allow all data types to be nullable.
// When the value returned by this func is `true` the comparison is made with the empty value instead of null.
allowNull AllowNullFunc
// IgnoreNullsInLists allows stripping null values from lists before comparison.
// Destination setups that don't support nulls in lists should set this to true.
ignoreNullsInLists bool
// genDataOptions define how to generate test data and which data types to skip
genDatOptions schema.TestSourceOptions
// random seed to use
randSeed int64
// rand.Rand
rand *rand.Rand
}
// SafeMigrations defines which migrations are supported by the plugin in safe migrate mode
type SafeMigrations struct {
AddColumn bool
AddColumnNotNull bool
RemoveColumn bool
RemoveColumnNotNull bool
ChangeColumn bool
}
type WriterTestSuiteTests struct {
// SkipUpsert skips testing with message.Insert and Upsert=true.
// Usually when a destination is not supporting primary keys
SkipUpsert bool
// SkipDeleteStale skips testing message.Delete events.
SkipDeleteStale bool
// SkipAppend skips testing message.Insert and Upsert=false.
SkipInsert bool
// SkipMigrate skips testing migration
SkipMigrate bool
// SafeMigrations defines which tests should work with force migration
// and which should pass with safe migration
SafeMigrations SafeMigrations
}
type NewPluginFunc func() *Plugin
func WithTestSourceAllowNull(allowNull func(arrow.DataType) bool) func(o *WriterTestSuite) {
return func(o *WriterTestSuite) {
o.allowNull = allowNull
}
}
func WithTestIgnoreNullsInLists() func(o *WriterTestSuite) {
return func(o *WriterTestSuite) {
o.ignoreNullsInLists = true
}
}
func WithTestDataOptions(opts schema.TestSourceOptions) func(o *WriterTestSuite) {
return func(o *WriterTestSuite) {
o.genDatOptions = opts
}
}
func WithRandomSeed(seed int64) func(o *WriterTestSuite) {
return func(o *WriterTestSuite) {
o.randSeed = seed
}
}
func TestWriterSuiteRunner(t *testing.T, p *Plugin, tests WriterTestSuiteTests, opts ...func(o *WriterTestSuite)) {
suite := &WriterTestSuite{
tests: tests,
plugin: p,
}
for _, opt := range opts {
opt(suite)
}
suite.rand = rand.New(rand.NewSource(suite.randSeed))
ctx := context.Background()
t.Run("TestUpsert", func(t *testing.T) {
if suite.tests.SkipUpsert {
t.Skip("skipping " + t.Name())
}
t.Run("Basic", func(t *testing.T) {
if err := suite.testUpsertBasic(ctx); err != nil {
t.Fatal(err)
}
})
t.Run("All", func(t *testing.T) {
if err := suite.testUpsertAll(ctx); err != nil {
t.Fatal(err)
}
})
})
t.Run("TestInsert", func(t *testing.T) {
if suite.tests.SkipInsert {
t.Skip("skipping " + t.Name())
}
t.Run("Basic", func(t *testing.T) {
if err := suite.testInsertBasic(ctx); err != nil {
t.Fatal(err)
}
})
t.Run("All", func(t *testing.T) {
if err := suite.testInsertAll(ctx); err != nil {
t.Fatal(err)
}
})
})
t.Run("TestDeleteStale", func(t *testing.T) {
if suite.tests.SkipDeleteStale {
t.Skip("skipping " + t.Name())
}
if err := suite.testDeleteStale(ctx); err != nil {
t.Fatal(err)
}
})
t.Run("TestMigrate", func(t *testing.T) {
if suite.tests.SkipMigrate {
t.Skip("skipping " + t.Name())
}
suite.testMigrate(ctx, t, false)
suite.testMigrate(ctx, t, true)
})
}