@@ -8,17 +8,20 @@ import (
8
8
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
9
9
10
10
"github.com/seal-io/terraform-provider-byteset/utils/strx"
11
+ "github.com/seal-io/terraform-provider-byteset/utils/testx"
11
12
)
12
13
13
- func TestAccResourcePipeline_sqlite (t * testing.T ) {
14
+ func TestAccResourcePipeline_file_to_sqlite (t * testing.T ) {
14
15
// Test pipeline.
15
16
var (
17
+ testdataPath = testx .AbsolutePath ("testdata" )
18
+
16
19
resourceName = "byteset_pipeline.test"
17
20
18
- basicSrc = fmt .Sprintf ("file://%s/sqlite.sql" , testdataPath () )
21
+ basicSrc = fmt .Sprintf ("file://%s/sqlite.sql" , testdataPath )
19
22
basicDst = "sqlite:///tmp/sqlite.db"
20
23
21
- fkSrc = fmt .Sprintf ("file://%s/sqlite-fk.sql" , testdataPath () )
24
+ fkSrc = fmt .Sprintf ("file://%s/sqlite-fk.sql" , testdataPath )
22
25
fkDst = "sqlite:///tmp/sqlite.db?_pragma=foreign_keys(1)"
23
26
)
24
27
@@ -28,28 +31,29 @@ func TestAccResourcePipeline_sqlite(t *testing.T) {
28
31
Steps : []resource.TestStep {
29
32
// Basic.
30
33
{
31
- Config : testConfig (basicSrc , basicDst ),
34
+ Config : testConfigOfSourceFile (basicSrc , basicDst , 1 , 1 ),
32
35
Check : resource .ComposeAggregateTestCheckFunc (
33
36
resource .TestCheckResourceAttr (resourceName , "source.address" , basicSrc ),
34
37
resource .TestCheckResourceAttr (resourceName , "destination.address" , basicDst ),
35
- resource .TestCheckResourceAttr (resourceName , "destination.conn_max_open" , "15" ),
36
- resource .TestCheckResourceAttr (resourceName , "destination.conn_max_idle" , "5" ),
37
- resource .TestCheckResourceAttr (resourceName , "destination.conn_max_life" , "300" ),
38
+ resource .TestCheckResourceAttr (resourceName , "destination.conn_max_open" , "1" ),
39
+ resource .TestCheckResourceAttr (resourceName , "destination.conn_max_idle" , "1" ),
38
40
),
39
41
},
40
42
// Foreign Key.
41
43
{
42
- Config : testConfig (fkSrc , fkDst ),
44
+ Config : testConfigOfSourceFile (fkSrc , fkDst , 1 , 1 ),
43
45
Check : resource .ComposeAggregateTestCheckFunc (
44
46
resource .TestCheckResourceAttr (resourceName , "source.address" , fkSrc ),
45
47
resource .TestCheckResourceAttr (resourceName , "destination.address" , fkDst ),
48
+ resource .TestCheckResourceAttr (resourceName , "destination.conn_max_open" , "1" ),
49
+ resource .TestCheckResourceAttr (resourceName , "destination.conn_max_idle" , "1" ),
46
50
),
47
51
},
48
52
},
49
53
})
50
54
}
51
55
52
- func TestAccResourcePipeline_mysql (t * testing.T ) {
56
+ func TestAccResourcePipeline_file_to_mysql (t * testing.T ) {
53
57
// Start Database.
54
58
var (
55
59
database = "byteset"
@@ -78,12 +82,13 @@ func TestAccResourcePipeline_mysql(t *testing.T) {
78
82
79
83
// Test pipeline.
80
84
var (
85
+ testdataPath = testx .AbsolutePath ("testdata" )
81
86
resourceName = "byteset_pipeline.test"
82
87
83
- basicSrc = fmt .Sprintf ("file://%s/mysql.sql" , testdataPath () )
88
+ basicSrc = fmt .Sprintf ("file://%s/mysql.sql" , testdataPath )
84
89
basicDst = fmt .Sprintf ("mysql://root:%s@tcp(127.0.0.1:3306)/%s" , password , database )
85
90
86
- fkSrc = fmt .Sprintf ("file://%s/mysql-fk.sql" , testdataPath () )
91
+ fkSrc = fmt .Sprintf ("file://%s/mysql-fk.sql" , testdataPath )
87
92
fkDst = fmt .Sprintf ("mysql://root:%s@tcp(127.0.0.1)/%s" , password , database )
88
93
89
94
largeSrc = "https://raw.githubusercontent.com/seal-io/terraform-provider-byteset/main/byteset/testdata/mysql-lg.sql"
@@ -95,31 +100,37 @@ func TestAccResourcePipeline_mysql(t *testing.T) {
95
100
ProtoV6ProviderFactories : testAccProviderFactories ,
96
101
Steps : []resource.TestStep {
97
102
{
98
- Config : testConfig (basicSrc , basicDst ),
103
+ Config : testConfigOfSourceFile (basicSrc , basicDst , 5 , 5 ),
99
104
Check : resource .ComposeAggregateTestCheckFunc (
100
105
resource .TestCheckResourceAttr (resourceName , "source.address" , basicSrc ),
101
106
resource .TestCheckResourceAttr (resourceName , "destination.address" , basicDst ),
107
+ resource .TestCheckResourceAttr (resourceName , "destination.conn_max_open" , "5" ),
108
+ resource .TestCheckResourceAttr (resourceName , "destination.conn_max_idle" , "5" ),
102
109
),
103
110
},
104
111
{
105
- Config : testConfig (fkSrc , fkDst ),
112
+ Config : testConfigOfSourceFile (fkSrc , fkDst , 5 , 5 ),
106
113
Check : resource .ComposeAggregateTestCheckFunc (
107
114
resource .TestCheckResourceAttr (resourceName , "source.address" , fkSrc ),
108
115
resource .TestCheckResourceAttr (resourceName , "destination.address" , fkDst ),
116
+ resource .TestCheckResourceAttr (resourceName , "destination.conn_max_open" , "5" ),
117
+ resource .TestCheckResourceAttr (resourceName , "destination.conn_max_idle" , "5" ),
109
118
),
110
119
},
111
120
{
112
- Config : testConfig (largeSrc , largeDst ),
121
+ Config : testConfigOfSourceFile (largeSrc , largeDst , 5 , 5 ),
113
122
Check : resource .ComposeAggregateTestCheckFunc (
114
123
resource .TestCheckResourceAttr (resourceName , "source.address" , largeSrc ),
115
124
resource .TestCheckResourceAttr (resourceName , "destination.address" , largeDst ),
125
+ resource .TestCheckResourceAttr (resourceName , "destination.conn_max_open" , "5" ),
126
+ resource .TestCheckResourceAttr (resourceName , "destination.conn_max_idle" , "5" ),
116
127
),
117
128
},
118
129
},
119
130
})
120
131
}
121
132
122
- func TestAccResourcePipeline_postgres (t * testing.T ) {
133
+ func TestAccResourcePipeline_file_to_postgres (t * testing.T ) {
123
134
// Start Database.
124
135
var (
125
136
database = "byteset"
@@ -149,12 +160,13 @@ func TestAccResourcePipeline_postgres(t *testing.T) {
149
160
150
161
// Test pipeline.
151
162
var (
163
+ testdataPath = testx .AbsolutePath ("testdata" )
152
164
resourceName = "byteset_pipeline.test"
153
165
154
- basicSrc = fmt .Sprintf ("file://%s/postgres.sql" , testdataPath () )
166
+ basicSrc = fmt .Sprintf ("file://%s/postgres.sql" , testdataPath )
155
167
basicDst = fmt .
Sprintf (
"postgres://root:%[email protected] :5432/%s?sslmode=disable" ,
password ,
database )
156
168
157
- fkSrc = fmt .Sprintf ("file://%s/postgres-fk.sql" , testdataPath () )
169
+ fkSrc = fmt .Sprintf ("file://%s/postgres-fk.sql" , testdataPath )
158
170
fkDst = fmt .
Sprintf (
"postgres://root:%[email protected] /%s?sslmode=disable" ,
password ,
database )
159
171
160
172
largeSrc = "https://raw.githubusercontent.com/seal-io/terraform-provider-byteset/main/byteset/testdata/postgres-lg.sql"
@@ -166,40 +178,52 @@ func TestAccResourcePipeline_postgres(t *testing.T) {
166
178
ProtoV6ProviderFactories : testAccProviderFactories ,
167
179
Steps : []resource.TestStep {
168
180
{
169
- Config : testConfig (basicSrc , basicDst ),
181
+ Config : testConfigOfSourceFile (basicSrc , basicDst , 5 , 5 ),
170
182
Check : resource .ComposeAggregateTestCheckFunc (
171
183
resource .TestCheckResourceAttr (resourceName , "source.address" , basicSrc ),
172
184
resource .TestCheckResourceAttr (resourceName , "destination.address" , basicDst ),
185
+ resource .TestCheckResourceAttr (resourceName , "destination.conn_max_open" , "5" ),
186
+ resource .TestCheckResourceAttr (resourceName , "destination.conn_max_idle" , "5" ),
173
187
),
174
188
},
175
189
{
176
- Config : testConfig (fkSrc , fkDst ),
190
+ Config : testConfigOfSourceFile (fkSrc , fkDst , 5 , 5 ),
177
191
Check : resource .ComposeAggregateTestCheckFunc (
178
192
resource .TestCheckResourceAttr (resourceName , "source.address" , fkSrc ),
179
193
resource .TestCheckResourceAttr (resourceName , "destination.address" , fkDst ),
194
+ resource .TestCheckResourceAttr (resourceName , "destination.conn_max_open" , "5" ),
195
+ resource .TestCheckResourceAttr (resourceName , "destination.conn_max_idle" , "5" ),
180
196
),
181
197
},
182
198
{
183
- Config : testConfig (largeSrc , largeDst ),
199
+ Config : testConfigOfSourceFile (largeSrc , largeDst , 5 , 5 ),
184
200
Check : resource .ComposeAggregateTestCheckFunc (
185
201
resource .TestCheckResourceAttr (resourceName , "source.address" , largeSrc ),
186
202
resource .TestCheckResourceAttr (resourceName , "destination.address" , largeDst ),
203
+ resource .TestCheckResourceAttr (resourceName , "destination.conn_max_open" , "5" ),
204
+ resource .TestCheckResourceAttr (resourceName , "destination.conn_max_idle" , "5" ),
187
205
),
188
206
},
189
207
},
190
208
})
191
209
}
192
210
193
- func testConfig (src , dst string ) string {
211
+ func testConfigOfSourceFile (src , dst string , dstMaxOpen , dstMaxIdle int ) string {
194
212
const tmpl = `
195
213
resource "byteset_pipeline" "test" {
196
214
source = {
197
215
address = "{{ .Src }}"
198
216
}
199
217
destination = {
200
218
address = "{{ .Dst }}"
219
+ conn_max_open = {{ .DstMaxOpen }}
220
+ conn_max_idle = {{ .DstMaxIdle }}
201
221
}
202
222
}`
203
223
204
- return renderConfigTemplate (tmpl , "Src" , src , "Dst" , dst )
224
+ return renderConfigTemplate (tmpl ,
225
+ "Src" , src ,
226
+ "Dst" , dst ,
227
+ "DstMaxOpen" , dstMaxOpen ,
228
+ "DstMaxIdle" , dstMaxIdle )
205
229
}
0 commit comments