Skip to content

Commit 021297f

Browse files
datastore-postgres testFixtures
1 parent 2509237 commit 021297f

File tree

5 files changed

+38
-31
lines changed

5 files changed

+38
-31
lines changed

airbyte-cdk/java/airbyte-cdk/core/src/test/kotlin/io/airbyte/cdk/db/jdbc/TestDefaultJdbcDatabase.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,19 @@ internal class TestDefaultJdbcDatabase {
132132
Jsons.jsonNode(ImmutableMap.of("id", 3, "name", "vash"))
133133
)
134134

135-
private var PSQL_DB: PostgreSQLContainer<*>? = null
135+
private lateinit var PSQL_DB: PostgreSQLContainer<Nothing>
136136

137137
@JvmStatic
138138
@BeforeAll
139139
fun init(): Unit {
140140
PSQL_DB = PostgreSQLContainer<Nothing>("postgres:13-alpine")
141-
PSQL_DB!!.start()
141+
PSQL_DB.start()
142142
}
143143

144144
@JvmStatic
145145
@AfterAll
146146
fun cleanUp(): Unit {
147-
PSQL_DB!!.close()
147+
PSQL_DB.close()
148148
}
149149
}
150150
}

airbyte-cdk/java/airbyte-cdk/core/src/test/kotlin/io/airbyte/cdk/db/jdbc/TestJdbcUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ internal class TestJdbcUtils {
334334
Jsons.jsonNode(ImmutableMap.of("id", 3, "name", "vash"))
335335
)
336336

337-
private var PSQL_DB: PostgreSQLContainer<*>? = null
337+
private lateinit var PSQL_DB: PostgreSQLContainer<Nothing>
338338

339339
private val sourceOperations: JdbcSourceOperations = JdbcUtils.defaultSourceOperations
340340

airbyte-cdk/java/airbyte-cdk/core/src/test/kotlin/io/airbyte/cdk/db/jdbc/TestStreamingJdbcDatabase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ internal class TestStreamingJdbcDatabase {
162162
}
163163

164164
companion object {
165-
private var PSQL_DB: PostgreSQLContainer<*>? = null
165+
private lateinit var PSQL_DB: PostgreSQLContainer<Nothing>
166166

167167
@JvmStatic
168168
@BeforeAll

airbyte-cdk/java/airbyte-cdk/datastore-postgres/src/testFixtures/java/io/airbyte/cdk/testutils/PostgreSQLContainerHelper.java

Lines changed: 0 additions & 26 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2023 Airbyte, Inc., all rights reserved.
3+
*/
4+
package io.airbyte.cdk.testutils
5+
6+
import java.io.IOException
7+
import java.util.*
8+
import org.testcontainers.containers.PostgreSQLContainer
9+
import org.testcontainers.utility.MountableFile
10+
11+
object PostgreSQLContainerHelper {
12+
@JvmStatic
13+
fun runSqlScript(file: MountableFile?, db: PostgreSQLContainer<Nothing>) {
14+
try {
15+
val scriptPath = "/etc/" + UUID.randomUUID() + ".sql"
16+
db.copyFileToContainer(file, scriptPath)
17+
db.execInContainer(
18+
"psql",
19+
"-d",
20+
db.databaseName,
21+
"-U",
22+
db.username,
23+
"-a",
24+
"-f",
25+
scriptPath
26+
)
27+
} catch (e: InterruptedException) {
28+
throw RuntimeException(e)
29+
} catch (e: IOException) {
30+
throw RuntimeException(e)
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)