Skip to content

Commit ee8da72

Browse files
committed
add contributing file and bootstrap
1 parent 82db3b8 commit ee8da72

File tree

4 files changed

+73
-17
lines changed

4 files changed

+73
-17
lines changed

β€ŽCONTRIBUTE.mdβ€Ž

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Contributing to Fluent PostgreSQL
2+
3+
πŸ‘‹ Welcome to the Vapor team! Join us on Slack ([http://vapor.team](http://vapor.team)) if you haven't already.
4+
5+
## Bootstrap
6+
7+
To prepare your computer for developing this package, you can run the bootstrap script.
8+
9+
```sh
10+
./contribute_boostrap.sh
11+
```
12+
13+
This script will start up a PostgreSQL docker container to test against. It will also generate and open Xcode for you.
14+
15+
Be careful to observe the script's output, it may have errors or ask you to do additional steps manually.
16+
17+
## Testing
18+
19+
Once in Xcode, select the `FluentPostgreSQL-Package` scheme and use `CMD+U` to run the tests.
20+
21+
When adding new tests (please do 😁), don't forget to add the method name to the `allTests` array.
22+
If you add a new `XCTestCase` subclass, make sure to add it to the `Tests/LinuxMain.swift` file.
23+
24+
If you are fixing a single GitHub issue in particular, you can add a test named `testGH<issue number>` to ensure
25+
that your fix is working. This will also help prevent regression.
26+
27+
28+
Thanks! πŸ™Œ

β€ŽTests/FluentPostgreSQLTests/FluentPostgreSQLTests.swiftβ€Ž

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,22 @@ import Async
22
import XCTest
33
import FluentBenchmark
44
import FluentPostgreSQL
5+
import Foundation
56

67
class FluentPostgreSQLTests: XCTestCase {
78
var benchmarker: Benchmarker<PostgreSQLDatabase>!
89
var database: PostgreSQLDatabase!
910

1011
override func setUp() {
1112
let eventLoop = MultiThreadedEventLoopGroup(numThreads: 1)
12-
database = PostgreSQLDatabase(config: .default())
13+
let config = PostgreSQLDatabaseConfig(
14+
hostname: ProcessInfo.processInfo.environment["PSQL_HOSTNAME"] ?? "localhost",
15+
port: 5432,
16+
username: "vapor_username",
17+
database: "vapor_database",
18+
password: "vapor_password"
19+
)
20+
database = PostgreSQLDatabase(config: config)
1321
benchmarker = Benchmarker(database, on: eventLoop, onFail: XCTFail)
1422
}
1523

@@ -101,7 +109,7 @@ class FluentPostgreSQLTests: XCTestCase {
101109

102110
func testDefaultValue() throws {
103111
let conn = try benchmarker.pool.requestConnection().wait()
104-
try? DefaultTest.revert(on: conn).wait()
112+
defer { try? DefaultTest.revert(on: conn).wait() }
105113
try DefaultTest.prepare(on: conn).wait()
106114
let test = DefaultTest()
107115
// _ = try test.save(on: conn).await(on: eventLoop)
@@ -114,28 +122,26 @@ class FluentPostgreSQLTests: XCTestCase {
114122
} else {
115123
XCTFail()
116124
}
117-
try DefaultTest.revert(on: conn).wait()
118125
benchmarker.pool.releaseConnection(conn)
119126
}
120127

121128

122129
func testUpdate() throws {
123130
benchmarker.database.enableLogging(using: .print)
124131
let conn = try benchmarker.pool.requestConnection().wait()
125-
try? User.revert(on: conn).wait()
132+
defer { try? User.revert(on: conn).wait() }
126133
try User.prepare(on: conn).wait()
127134
let user = User(id: nil, name: "Tanner", pet: Pet(name: "Zizek"))
128135
user.favoriteColors = ["pink", "blue"]
129136
_ = try user.save(on: conn).wait()
130137
try User.query(on: conn).update(["name": "Vapor"]).wait()
131-
try User.revert(on: conn).wait()
132138
benchmarker.pool.releaseConnection(conn)
133139
}
134140

135141
func testGH24() throws {
136142
benchmarker.database.enableLogging(using: .print)
137143
let conn = try benchmarker.pool.requestConnection().wait()
138-
try? Allergy.revert(on: conn).wait()
144+
defer { try? Allergy.revert(on: conn).wait() }
139145
try Allergy.prepare(on: conn).wait()
140146
struct Allergy: PostgreSQLModel, Migration {
141147
static let entity = "allergies"
@@ -165,7 +171,7 @@ class FluentPostgreSQLTests: XCTestCase {
165171
/// - prepare db
166172
benchmarker.database.enableLogging(using: .print)
167173
let conn = try benchmarker.pool.requestConnection().wait()
168-
try? Pet.revert(on: conn).wait()
174+
defer { try? Pet.revert(on: conn).wait() }
169175
try Pet.prepare(on: conn).wait()
170176

171177
/// - tests
@@ -181,16 +187,14 @@ class FluentPostgreSQLTests: XCTestCase {
181187

182188
func testPersistsDateMillisecondPart() throws {
183189
database.enableLogging(using: DatabaseLogger(handler: { print($0) }))
184-
let conn = try database.makeConnection(on: eventLoop).await(on: eventLoop)
185-
try? DefaultTest.revert(on: conn).await(on: eventLoop)
186-
try DefaultTest.prepare(on: conn).await(on: eventLoop)
190+
let conn = try benchmarker.pool.requestConnection().wait()
191+
defer { try? DefaultTest.revert(on: conn).wait() }
192+
try DefaultTest.prepare(on: conn).wait()
187193
var test = DefaultTest()
188194
test.date = PostgreSQLDate(Date(timeIntervalSinceReferenceDate: 123.456))
189-
_ = try test.save(on: conn).await(on: eventLoop)
190-
let fetched = try DefaultTest.query(on: conn).first().await(on: eventLoop)!
195+
_ = try test.save(on: conn).wait()
196+
let fetched = try DefaultTest.query(on: conn).first().wait()!
191197
XCTAssertEqual(123.456, fetched.date!.value!.timeIntervalSinceReferenceDate, accuracy: 1e-6)
192-
try DefaultTest.revert(on: conn).await(on: eventLoop)
193-
conn.close()
194198
}
195199

196200
static let allTests = [
@@ -209,6 +213,7 @@ class FluentPostgreSQLTests: XCTestCase {
209213
("testMinimumViableModelDeclaration", testMinimumViableModelDeclaration),
210214
("testGH24", testGH24),
211215
("testGH21", testGH21),
216+
("testPersistsDateMillisecondPart", testPersistsDateMillisecondPart),
212217
]
213218
}
214219

β€Žcircle.ymlβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ jobs:
1313
- image: norionomura/swift:swift-4.1-branch
1414
- image: circleci/postgres:latest
1515
environment:
16-
POSTGRES_USER: postgres
17-
POSTGRES_DB: postgres
18-
POSTGRES_PASSWORD: ""
16+
POSTGRES_USER: vapor_username
17+
POSTGRES_DB: vapor_database
18+
POSTGRES_PASSWORD: vapor_password
1919
steps:
2020
- run:
2121
name: Update APT

β€Žcontribute_boostrap.shβ€Ž

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
echo "πŸ’§ starting docker..."
2+
docker-machine start default
3+
4+
echo "πŸ’§ exporting docker machine environment..."
5+
eval $(docker-machine env default)
6+
7+
echo "πŸ’§ cleaning previous vapor-psql dev db..."
8+
docker stop vapor-psql
9+
docker rm vapor-psql
10+
11+
echo "πŸ’§ creating vapor-psql dev db..."
12+
docker run --name vapor-psql -e POSTGRES_USER=vapor_username -e POSTGRES_DB=vapor_database -e POSTGRES_PASSWORD=vapor_password -p 5432:5432 -d postgres:latest
13+
14+
echo "πŸ’§ generating xcode proj..."
15+
swift package generate-xcodeproj
16+
17+
echo "πŸ’§ add the following env variable to Xcode test scheme:"
18+
echo ""
19+
echo " PSQL_HOSTNAME: `docker-machine ip`"
20+
echo ""
21+
22+
echo "πŸ’§ opening xcode..."
23+
open *.xcodeproj

0 commit comments

Comments
Β (0)