Skip to content

Commit 4ad7cf6

Browse files
committed
Drop database id, base docker name on port
1 parent cf001fe commit 4ad7cf6

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

Tests/AppTests/Helpers/DatabasePool.swift

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import Foundation
16-
1715
import App
1816
import PostgresNIO
1917
import ShellOut
@@ -22,10 +20,7 @@ import Vapor
2220

2321

2422
actor DatabasePool {
25-
typealias DatabaseID = UUID
26-
2723
struct Database: Hashable {
28-
var id: DatabaseID
2924
var port: Int
3025

3126
var connectionDetails: ConnectionDetails {
@@ -98,20 +93,19 @@ actor DatabasePool {
9893
}
9994

10095
private func launchDB(maxAttempts: Int = 3) async throws -> Database {
101-
let id = UUID()
10296
let port = Int.random(in: 10_000...65_000)
103-
_ = try? await ShellOut.shellOut(to: .removeDB(id: id))
97+
_ = try? await ShellOut.shellOut(to: .removeDB(port: port))
10498
try await run(maxAttempts: 3) { attempt in
105-
print("⚠️ Launching DB \(id) on port \(port) (attempt: \(attempt))")
106-
try await ShellOut.shellOut(to: .launchDB(id: id, port: port))
99+
print("⚠️ Launching DB on port \(port) (attempt: \(attempt))")
100+
try await ShellOut.shellOut(to: .launchDB(port: port))
107101
}
108-
return .init(id: id, port: port)
102+
return .init(port: port)
109103
}
110104

111105
private func removeDB(database: Database, maxAttempts: Int = 3) async throws {
112106
try await run(maxAttempts: 3) { attempt in
113-
// print("⚠️ Removing DB \(database.id) on port \(database.port) (attempt: \(attempt))")
114-
try await ShellOut.shellOut(to: .removeDB(id: database.id))
107+
// print("⚠️ Removing DB on port \(database.port) (attempt: \(attempt))")
108+
try await ShellOut.shellOut(to: .removeDB(port: database.port))
115109
}
116110
}
117111
}

Tests/AppTests/Helpers/ShellOutCommand+ext.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import Foundation
16-
1715
import ShellOut
1816

1917

2018
extension ShellOutCommand {
21-
static func launchDB(id: UUID, port: Int) -> ShellOutCommand {
19+
static func launchDB(port: Int) -> ShellOutCommand {
2220
.init(command: "docker", arguments: [
23-
"run", "--name", "spi_test_\(id)",
21+
"run", "--name", "spi_test_\(port)",
2422
"-e", "POSTGRES_DB=spi_test",
2523
"-e", "POSTGRES_USER=spi_test",
2624
"-e", "POSTGRES_PASSWORD=xxx",
@@ -32,9 +30,9 @@ extension ShellOutCommand {
3230
])
3331
}
3432

35-
static func removeDB(id: UUID) -> ShellOutCommand {
33+
static func removeDB(port: Int) -> ShellOutCommand {
3634
.init(command: "docker", arguments: [
37-
"rm", "-f", "spi_test_\(id)"
35+
"rm", "-f", "spi_test_\(port)"
3836
])
3937
}
4038
}

0 commit comments

Comments
 (0)