From b1ed3e9cd4fd3dfddb6a71a221d8a3d7c4681472 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Wed, 26 Feb 2020 16:00:45 -0600 Subject: [PATCH 1/4] Update macOS version in Package.swift to match Vpaor's requirement. --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 1610c3de..05a70cde 100644 --- a/Package.swift +++ b/Package.swift @@ -4,7 +4,7 @@ import PackageDescription let package = Package( name: "fluent", platforms: [ - .macOS(.v10_14) + .macOS(.v10_15) ], products: [ .library(name: "Fluent", targets: ["Fluent"]), From 446dd7d1e5e0e6704bdaf03300174e535634a30a Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Wed, 26 Feb 2020 16:55:44 -0600 Subject: [PATCH 2/4] Update tests to match FluentKit beta 5 --- Tests/FluentTests/FluentOperatorTests.swift | 12 +++++- Tests/FluentTests/FluentPaginationTests.swift | 21 ++++------ Tests/FluentTests/FluentRepositoryTests.swift | 4 +- Tests/FluentTests/TestDatabase.swift | 42 ++++++++++++++----- 4 files changed, 53 insertions(+), 26 deletions(-) diff --git a/Tests/FluentTests/FluentOperatorTests.swift b/Tests/FluentTests/FluentOperatorTests.swift index 606babd3..068a71ee 100644 --- a/Tests/FluentTests/FluentOperatorTests.swift +++ b/Tests/FluentTests/FluentOperatorTests.swift @@ -32,7 +32,7 @@ final class FluentOperatorTests: XCTestCase { private final class Planet: Model { static let schema = "planets" - @ID(key: "id") + @ID(custom: .id) var id: Int? @Field(key: "name") @@ -44,7 +44,7 @@ private struct DummyDatabase: Database { fatalError() } - func execute(query: DatabaseQuery, onRow: @escaping (DatabaseRow) -> ()) -> EventLoopFuture { + func execute(query: DatabaseQuery, onOutput: @escaping (DatabaseOutput) -> ()) -> EventLoopFuture { fatalError() } @@ -52,7 +52,15 @@ private struct DummyDatabase: Database { fatalError() } + func execute(enum: DatabaseEnum) -> EventLoopFuture { + fatalError() + } + func withConnection(_ closure: @escaping (Database) -> EventLoopFuture) -> EventLoopFuture { fatalError() } + + func transaction(_ closure: @escaping (Database) -> EventLoopFuture) -> EventLoopFuture { + fatalError() + } } diff --git a/Tests/FluentTests/FluentPaginationTests.swift b/Tests/FluentTests/FluentPaginationTests.swift index c3d64581..63dbee37 100644 --- a/Tests/FluentTests/FluentPaginationTests.swift +++ b/Tests/FluentTests/FluentPaginationTests.swift @@ -11,8 +11,8 @@ final class FluentPaginationTests: XCTestCase { for i in 1...1_000 { rows.append(TestRow(data: ["id": i, "title": "Todo #\(i)"])) } - - app.databases.use(TestDatabaseDriver { query in + + app.databases.use(TestDatabaseConfiguration { query in XCTAssertEqual(query.schema, "todos") let result: [TestRow] if let limit = query.limits.first?.value, let offset = query.offsets.first?.value { @@ -20,16 +20,13 @@ final class FluentPaginationTests: XCTestCase { } else { result = rows } - - if query.fields.count == 1 { - // aggregate - return [ - TestRow(data: ["fluentAggregate": rows.count]) - ] - } else { - return result + + switch query.action { + case .aggregate(_): + return [TestRow(data: [.aggregate: rows.count])] + default: + return result } - }, as: .test) app.get("todos") { req -> EventLoopFuture> in @@ -90,7 +87,7 @@ private extension DatabaseQuery.Offset { private final class Todo: Model, Content { static let schema = "todos" - @ID(key: "id") + @ID(custom: .id) var id: Int? @Field(key: "title") diff --git a/Tests/FluentTests/FluentRepositoryTests.swift b/Tests/FluentTests/FluentRepositoryTests.swift index f5b6de50..42a3fb1a 100644 --- a/Tests/FluentTests/FluentRepositoryTests.swift +++ b/Tests/FluentTests/FluentRepositoryTests.swift @@ -37,7 +37,7 @@ final class FluentRepositoryTests: XCTestCase { let app = Application(.testing) defer { app.shutdown() } - app.databases.use(TestDatabaseDriver { query in + app.databases.use(TestDatabaseConfiguration { query in XCTAssertEqual(query.schema, "posts") return [ TestRow(data: ["id": 1, "content": "a"]), @@ -102,7 +102,7 @@ private final class Post: Model, Content, Equatable { static var schema: String { "posts" } - @ID(key: "id") + @ID(custom: .id) var id: Int? @Field(key: "content") diff --git a/Tests/FluentTests/TestDatabase.swift b/Tests/FluentTests/TestDatabase.swift index 2bf186a5..f369e0a1 100644 --- a/Tests/FluentTests/TestDatabase.swift +++ b/Tests/FluentTests/TestDatabase.swift @@ -8,40 +8,52 @@ struct TestDatabase: Database { let driver: TestDatabaseDriver let context: DatabaseContext - func execute(query: DatabaseQuery, onRow: @escaping (DatabaseRow) -> ()) -> EventLoopFuture { - self.driver.handler(query).forEach(onRow) + func execute(query: DatabaseQuery, onOutput: @escaping (DatabaseOutput) -> ()) -> EventLoopFuture { + self.driver.handler(query).forEach(onOutput) return self.eventLoop.makeSucceededFuture(()) } func execute(schema: DatabaseSchema) -> EventLoopFuture { fatalError() } - + + func execute(enum: DatabaseEnum) -> EventLoopFuture { + fatalError() + } + func withConnection(_ closure: @escaping (Database) -> EventLoopFuture) -> EventLoopFuture { closure(self) } + + func transaction(_ closure: @escaping (Database) -> EventLoopFuture) -> EventLoopFuture { + closure(self) + } } -struct TestRow: DatabaseRow { - var data: [String: Any] +struct TestRow: DatabaseOutput { + var data: [FieldKey: Any] var description: String { self.data.description } + + func schema(_ schema: String) -> DatabaseOutput { + self + } - func contains(field: String) -> Bool { + func contains(_ field: FieldKey) -> Bool { self.data.keys.contains(field) } - func decode(field: String, as type: T.Type, for database: Database) throws -> T where T : Decodable { - return self.data[field] as! T + func decode(_ field: FieldKey, as type: T.Type) throws -> T where T : Decodable { + self.data[field]! as! T } } final class TestDatabaseDriver: DatabaseDriver { - let handler: (DatabaseQuery) -> [DatabaseRow] + let handler: (DatabaseQuery) -> [DatabaseOutput] - init(_ handler: @escaping (DatabaseQuery) -> [DatabaseRow]) { + init(_ handler: @escaping (DatabaseQuery) -> [DatabaseOutput]) { self.handler = handler } @@ -53,3 +65,13 @@ final class TestDatabaseDriver: DatabaseDriver { // nothing } } + +struct TestDatabaseConfiguration: DatabaseConfiguration { + let handler: (DatabaseQuery) -> [DatabaseOutput] + + var middleware: [AnyModelMiddleware] = [] + + func makeDriver(for databases: Databases) -> DatabaseDriver { + TestDatabaseDriver(handler) + } +} From bd2d0b5378b45f329b90d4cf310cd078f3dc6638 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Wed, 26 Feb 2020 16:59:49 -0600 Subject: [PATCH 3/4] Require the beta versions we actually require of Vapor and FluentKit --- Package.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 05a70cde..3a24ce76 100644 --- a/Package.swift +++ b/Package.swift @@ -10,8 +10,8 @@ let package = Package( .library(name: "Fluent", targets: ["Fluent"]), ], dependencies: [ - .package(url: "https://github.com/vapor/fluent-kit.git", from: "1.0.0-beta.2"), - .package(url: "https://github.com/vapor/vapor.git", from: "4.0.0-beta.2"), + .package(url: "https://github.com/vapor/fluent-kit.git", from: "1.0.0-beta.5"), + .package(url: "https://github.com/vapor/vapor.git", from: "4.0.0-beta.4"), ], targets: [ .target(name: "Fluent", dependencies: ["FluentKit", "Vapor"]), From 670915604bf5183052df189645d69acaebef404b Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Wed, 26 Feb 2020 17:01:56 -0600 Subject: [PATCH 4/4] Update CI to Swift 5.2 requirement --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4207acc1..5d50456b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,14 +4,14 @@ on: jobs: xenial: container: - image: vapor/swift:5.1-xenial + image: vapor/swift:5.2-xenial runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - run: swift test --enable-test-discovery --sanitize=thread bionic: container: - image: vapor/swift:5.1-bionic + image: vapor/swift:5.2-bionic runs-on: ubuntu-latest steps: - uses: actions/checkout@v1