@@ -60,39 +60,45 @@ func testS3Storage(ctx context.Context, t *testing.T, clickhouseContainer testco
60
60
minioPort , err := minioContainer .MappedPort (ctx , "9000" )
61
61
require .NoError (t , err , "Failed to get Minio port" )
62
62
63
+ runMainTestScenario (ctx , t , clickhouseContainer , []string {
64
+ "--storage-type" , "s3" ,
65
+ "--storage-config" , fmt .Sprintf ("bucket=testbucket,region=us-east-1,endpoint=http://%s:%s" , minioHost , minioPort .Port ()),
66
+ })
67
+ }
68
+
69
+ func runMainTestScenario (ctx context.Context , t * testing.T , clickhouseContainer testcontainers.Container , storageArgs []string ) {
63
70
// Create test tables and insert data
64
71
require .NoError (t , createTestTables (ctx , t , clickhouseContainer ))
65
72
66
- // Test with database filter
67
- err = runClickHouseDump (ctx , t , clickhouseContainer ,
68
- "dump" ,
69
- "--storage-type" , "s3" ,
70
- "--storage-config" , fmt .Sprintf ("bucket=testbucket,region=us-east-1,endpoint=http://%s:%s" , minioHost , minioPort .Port ()),
71
- "--databases" , "test_db1" ,
72
- "--compress-format" , "gzip" ,
73
- "--compress-level" , "6" ,
73
+ // Test 1: Default dump (should get all tables except system)
74
+ err := runClickHouseDump (ctx , t , clickhouseContainer ,
75
+ append ([]string {
76
+ "dump" ,
77
+ "--compress-format" , "gzip" ,
78
+ "--compress-level" , "6" ,
79
+ }, storageArgs ... )... ,
74
80
)
75
81
require .NoError (t , err , "Failed to dump data" )
76
-
82
+
77
83
// Clear tables
78
84
require .NoError (t , clearTestTables (ctx , t , clickhouseContainer ))
79
85
80
86
// Restore with same filters
81
87
err = runClickHouseDump (ctx , t , clickhouseContainer ,
82
- "restore" ,
83
- "--storage-type" , "s3" ,
84
- "--storage-config" , fmt .Sprintf ("bucket=testbucket,region=us-east-1,endpoint=http://%s:%s" , minioHost , minioPort .Port ()),
85
- "--databases" , "test_db1" ,
88
+ append ([]string {
89
+ "restore" ,
90
+ }, storageArgs ... )... ,
86
91
)
87
92
require .NoError (t , err , "Failed to restore data" )
88
93
89
- // Verify only test_db1 tables were restored
94
+ // Verify only non-system tables were restored
90
95
require .NoError (t , verifyTestData (ctx , t , clickhouseContainer , "test_db1.users" , "1\t Alice\n 2\t Bob\n " ))
91
96
require .NoError (t , verifyTestData (ctx , t , clickhouseContainer , "test_db1.logs" , "1\t log entry 1\n 2\t log entry 2\n " ))
97
+ require .NoError (t , verifyTestData (ctx , t , clickhouseContainer , "test_db2.products" , "1\t Product A\n 2\t Product B\n " ))
92
98
93
- // Verify test_db2 tables were NOT restored
94
- _ , err = executeQueryWithResult (ctx , t , clickhouseContainer , "SELECT * FROM test_db2.products " )
95
- require .Error (t , err , "test_db2.products should not exist after filtered restore" )
99
+ // Verify system tables were NOT restored
100
+ _ , err = executeQueryWithResult (ctx , t , clickhouseContainer , "SELECT * FROM system.metrics " )
101
+ require .Error (t , err , "system.metrics should not exist after restore" )
96
102
}
97
103
98
104
func testGCSStorage (ctx context.Context , t * testing.T , clickhouseContainer testcontainers.Container ) {
@@ -102,7 +108,16 @@ func testGCSStorage(ctx context.Context, t *testing.T, clickhouseContainer testc
102
108
require .NoError (t , gcsContainer .Terminate (ctx ))
103
109
}()
104
110
105
- // TODO: Implement GCS storage test
111
+ gcsHost , err := gcsContainer .Host (ctx )
112
+ require .NoError (t , err , "Failed to get GCS host" )
113
+
114
+ gcsPort , err := gcsContainer .MappedPort (ctx , "4443" )
115
+ require .NoError (t , err , "Failed to get GCS port" )
116
+
117
+ runMainTestScenario (ctx , t , clickhouseContainer , []string {
118
+ "--storage-type" , "gcs" ,
119
+ "--storage-config" , fmt .Sprintf ("bucket=testbucket,endpoint=http://%s:%s" , gcsHost , gcsPort .Port ()),
120
+ })
106
121
}
107
122
108
123
func testAzureBlobStorage (ctx context.Context , t * testing.T , clickhouseContainer testcontainers.Container ) {
@@ -112,7 +127,16 @@ func testAzureBlobStorage(ctx context.Context, t *testing.T, clickhouseContainer
112
127
require .NoError (t , azuriteContainer .Terminate (ctx ))
113
128
}()
114
129
115
- // TODO: Implement Azure Blob storage test
130
+ azuriteHost , err := azuriteContainer .Host (ctx )
131
+ require .NoError (t , err , "Failed to get Azurite host" )
132
+
133
+ azuritePort , err := azuriteContainer .MappedPort (ctx , "10000" )
134
+ require .NoError (t , err , "Failed to get Azurite port" )
135
+
136
+ runMainTestScenario (ctx , t , clickhouseContainer , []string {
137
+ "--storage-type" , "azblob" ,
138
+ "--storage-config" , fmt .Sprintf ("account=devstoreaccount1,key=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==,container=testcontainer,endpoint=http://%s:%s/devstoreaccount1" , azuriteHost , azuritePort .Port ()),
139
+ })
116
140
}
117
141
118
142
func testFTPStorage (ctx context.Context , t * testing.T , clickhouseContainer testcontainers.Container ) {
@@ -122,7 +146,16 @@ func testFTPStorage(ctx context.Context, t *testing.T, clickhouseContainer testc
122
146
require .NoError (t , ftpContainer .Terminate (ctx ))
123
147
}()
124
148
125
- // TODO: Implement FTP storage test
149
+ ftpHost , err := ftpContainer .Host (ctx )
150
+ require .NoError (t , err , "Failed to get FTP host" )
151
+
152
+ ftpPort , err := ftpContainer .MappedPort (ctx , "21" )
153
+ require .NoError (t , err , "Failed to get FTP port" )
154
+
155
+ runMainTestScenario (ctx , t , clickhouseContainer , []string {
156
+ "--storage-type" , "ftp" ,
157
+ "--storage-config" , fmt .Sprintf ("host=%s:%s,user=testuser,password=testpass" , ftpHost , ftpPort .Port ()),
158
+ })
126
159
}
127
160
128
161
func testSFTPStorage (ctx context.Context , t * testing.T , clickhouseContainer testcontainers.Container ) {
@@ -132,95 +165,26 @@ func testSFTPStorage(ctx context.Context, t *testing.T, clickhouseContainer test
132
165
require .NoError (t , sftpContainer .Terminate (ctx ))
133
166
}()
134
167
135
- // TODO: Implement SFTP storage test
168
+ sftpHost , err := sftpContainer .Host (ctx )
169
+ require .NoError (t , err , "Failed to get SFTP host" )
170
+
171
+ sftpPort , err := sftpContainer .MappedPort (ctx , "22" )
172
+ require .NoError (t , err , "Failed to get SFTP port" )
173
+
174
+ runMainTestScenario (ctx , t , clickhouseContainer , []string {
175
+ "--storage-type" , "sftp" ,
176
+ "--storage-config" , fmt .Sprintf ("host=%s:%s,user=testuser,password=testpass" , sftpHost , sftpPort .Port ()),
177
+ })
136
178
}
137
179
138
180
func testFileStorage (ctx context.Context , t * testing.T , clickhouseContainer testcontainers.Container ) {
139
181
// Create temp directory for test
140
182
tempDir := t .TempDir ()
141
183
142
- // Create test tables and insert data
143
- require .NoError (t , createTestTables (ctx , t , clickhouseContainer ))
144
-
145
- // Test 1: Default dump (should get all tables except system)
146
- err := runClickHouseDump (ctx , t , clickhouseContainer ,
147
- "dump" ,
148
- "--storage-type" , "file" ,
149
- "--storage-path" , tempDir ,
150
- )
151
- require .NoError (t , err , "Failed to dump data" )
152
- require .NoError (t , verifyDumpResults (ctx , t , clickhouseContainer , tempDir , []string {
153
- "test_db1.users.schema.sql" ,
154
- "test_db1.users.data.sql" ,
155
- "test_db1.logs.schema.sql" ,
156
- "test_db1.logs.data.sql" ,
157
- "test_db2.products.schema.sql" ,
158
- "test_db2.products.data.sql" ,
159
- }))
160
-
161
- // Test 2: Filter by database
162
- tempDir = t .TempDir ()
163
- err = runClickHouseDump (ctx , t , clickhouseContainer ,
164
- "dump" ,
165
- "--storage-type" , "file" ,
166
- "--storage-path" , tempDir ,
167
- "--databases" , "test_db1" ,
168
- )
169
- require .NoError (t , err , "Failed to dump data" )
170
- require .NoError (t , verifyDumpResults (ctx , t , clickhouseContainer , tempDir , []string {
171
- "test_db1.users.schema.sql" ,
172
- "test_db1.users.data.sql" ,
173
- "test_db1.logs.schema.sql" ,
174
- "test_db1.logs.data.sql" ,
175
- }))
176
-
177
- // Test 3: Filter by table pattern
178
- tempDir = t .TempDir ()
179
- err = runClickHouseDump (ctx , t , clickhouseContainer ,
180
- "dump" ,
184
+ runMainTestScenario (ctx , t , clickhouseContainer , []string {
181
185
"--storage-type" , "file" ,
182
186
"--storage-path" , tempDir ,
183
- "--tables" , "user.*|prod.*" ,
184
- )
185
- require .NoError (t , err , "Failed to dump data" )
186
- require .NoError (t , verifyDumpResults (ctx , t , clickhouseContainer , tempDir , []string {
187
- "test_db1.users.schema.sql" ,
188
- "test_db1.users.data.sql" ,
189
- "test_db2.products.schema.sql" ,
190
- "test_db2.products.data.sql" ,
191
- }))
192
-
193
- // Test 4: Exclude tables
194
- tempDir = t .TempDir ()
195
- err = runClickHouseDump (ctx , t , clickhouseContainer ,
196
- "dump" ,
197
- "--storage-type" , "file" ,
198
- "--storage-path" , tempDir ,
199
- "--exclude-tables" , "logs" ,
200
- )
201
- require .NoError (t , err , "Failed to dump data" )
202
- require .NoError (t , verifyDumpResults (ctx , t , clickhouseContainer , tempDir , []string {
203
- "test_db1.users.schema.sql" ,
204
- "test_db1.users.data.sql" ,
205
- "test_db2.products.schema.sql" ,
206
- "test_db2.products.data.sql" ,
207
- }))
208
-
209
- // Test 5: Custom exclude databases
210
- tempDir = t .TempDir ()
211
- err = runClickHouseDump (ctx , t , clickhouseContainer ,
212
- "dump" ,
213
- "--storage-type" , "file" ,
214
- "--storage-path" , tempDir ,
215
- "--exclude-databases" , "test_db2" ,
216
- )
217
- require .NoError (t , err , "Failed to dump data" )
218
- require .NoError (t , verifyDumpResults (ctx , t , clickhouseContainer , tempDir , []string {
219
- "test_db1.users.schema.sql" ,
220
- "test_db1.users.data.sql" ,
221
- "test_db1.logs.schema.sql" ,
222
- "test_db1.logs.data.sql" ,
223
- }))
187
+ })
224
188
}
225
189
226
190
func startMinioContainer (ctx context.Context ) (testcontainers.Container , error ) {
0 commit comments