Skip to content

Commit

Permalink
Updates default DB config for tests to use test_ prefix (#67)
Browse files Browse the repository at this point in the history
* Defaults the DB schema name, username, and password used for tests to be prefixed with `test_` rather than `vapor_`. Updates README, CI and docker-compose.yml. Removes a few Vapor-specific references in the tests. Also some CI improvements.
  • Loading branch information
gwynne authored Nov 13, 2021
1 parent eab410d commit 03cc5d4
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 198 deletions.
225 changes: 88 additions & 137 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,178 +5,129 @@ defaults:
run:
shell: bash
jobs:
dependents:
linux-all:
strategy:
fail-fast: false
matrix:
dbimage:
- mysql:5.7
- mysql:8.0
- mariadb:10.2
- mariadb:10.7
- percona:5.7
- percona:8.0
swiftver:
- swift:5.2
- swift:5.5
- swiftlang/swift:nightly-main
swiftos:
- focal
container: ${{ format('{0}-{1}', matrix.swiftver, matrix.swiftos) }}
runs-on: ubuntu-latest
env:
LOG_LEVEL: debug
# Unfortunately, fluent-mysql-driver details leak through here
MYSQL_DATABASE: 'test_database'
MYSQL_DATABASE_A: 'test_database'
MYSQL_DATABASE_B: 'test_database'
MYSQL_USER: 'test_username'
MYSQL_USERNAME: 'test_username'
MYSQL_USERNAME_A: 'test_username'
MYSQL_USERNAME_B: 'test_username'
MYSQL_PASSWORD: 'test_password'
MYSQL_PASSWORD_A: 'test_password'
MYSQL_PASSWORD_B: 'test_password'
MYSQL_HOSTNAME: 'mysql-a'
MYSQL_HOSTNAME_A: 'mysql-a'
MYSQL_HOSTNAME_B: 'mysql-b'
services:
mysql-a:
image: ${{ matrix.dbimage }}
env:
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_USER: vapor_username
MYSQL_PASSWORD: vapor_password
MYSQL_DATABASE: vapor_database
MYSQL_USER: test_username
MYSQL_PASSWORD: test_password
MYSQL_DATABASE: test_database
mysql-b:
image: ${{ matrix.dbimage }}
env:
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_USER: vapor_username
MYSQL_PASSWORD: vapor_password
MYSQL_DATABASE: vapor_database
container: swift:5.4-focal
strategy:
fail-fast: false
matrix:
dbimage:
- mysql:5.7
- mysql:8.0
- mariadb:latest
dependent:
- mysql-kit
- fluent-mysql-driver
MYSQL_USER: test_username
MYSQL_PASSWORD: test_password
MYSQL_DATABASE: test_database
steps:
- name: Check out package
uses: actions/checkout@v2
with:
path: package
- name: Check out dependent
with: { path: 'mysql-nio' }
- name: Run tests
run: swift test --package-path mysql-nio --enable-test-discovery
- name: Check out mysql-kit dependent
uses: actions/checkout@v2
with:
repository: vapor/${{ matrix.dependent }}
path: dependent
- name: Use local package
run: swift package edit mysql-nio --path ../package
working-directory: dependent
- name: Run tests with Thread Sanitizer
run: swift test --enable-test-discovery --sanitize=thread
working-directory: dependent
env:
MYSQL_HOSTNAME: mysql-a
MYSQL_HOSTNAME_A: mysql-a
MYSQL_HOSTNAME_B: mysql-b
LOG_LEVEL: trace
linux:
strategy:
fail-fast: false
matrix:
dbimage:
- mysql:5.7
- mysql:8.0
- mariadb:latest
runner:
- swift:5.2-xenial
- swift:5.2-bionic
- swift:5.2-focal
- swift:5.2-centos7
- swift:5.2-centos8
- swift:5.2-amazonlinux2
- swift:5.3-xenial
- swift:5.3-bionic
- swift:5.3-focal
- swift:5.3-centos7
- swift:5.3-centos8
- swift:5.3-amazonlinux2
- swift:5.4-bionic
- swift:5.4-focal
- swift:5.4-centos7
- swift:5.4-centos8
- swift:5.4-amazonlinux2
- swiftlang/swift:nightly-5.5-focal
- swiftlang/swift:nightly-5.5-centos8
- swiftlang/swift:nightly-5.5-amazonlinux2
- swiftlang/swift:nightly-main-focal
- swiftlang/swift:nightly-main-centos8
- swiftlang/swift:nightly-main-amazonlinux2
exclude:
- runner: swift:5.2-amazonlinux2
dbimage: mysql:8.0
- runner: swift:5.3-amazonlinux2
dbimage: mysql:8.0
- runner: swift:5.4-amazonlinux2
dbimage: mysql:8.0
- runner: swiftlang/swift:nightly-5.5-amazonlinux2
dbimage: mysql:8.0
- runner: swiftlang/swift:nightly-main-amazonlinux2
dbimage: mysql:8.0
container: ${{ matrix.runner }}
runs-on: ubuntu-latest
services:
mysql:
image: ${{ matrix.dbimage }}
env:
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_USER: vapor_username
MYSQL_PASSWORD: vapor_password
MYSQL_DATABASE: vapor_database
steps:
- name: Workaround SPM incompatibility with old Git on CentOS 7
if: ${{ contains(matrix.runner, 'centos7') }}
run: |
yum install -y make libcurl-devel
git clone https://github.com/git/git -bv2.28.0 --depth 1 && cd git
make prefix=/usr -j all install NO_OPENSSL=1 NO_EXPAT=1 NO_TCLTK=1 NO_GETTEXT=1 NO_PERL=1
- name: Check out code
with: { repository: 'vapor/mysql-kit', path: 'mysql-kit' }
- name: Check out fluent-mysql-driver dependent
uses: actions/checkout@v2
- name: Run tests with Thread Sanitizer
run: swift test --enable-test-discovery --sanitize=thread
env:
MYSQL_HOSTNAME: mysql
LOG_LEVEL: trace
macOS:
with: { repository: 'vapor/fluent-mysql-driver', path: 'fluent-mysql-driver' }
- name: Use local package in dependents
run: |
swift package --package-path mysql-kit edit mysql-nio --path mysql-nio
swift package --package-path fluent-mysql-driver edit mysql-nio --path mysql-nio
- name: Run mysql-kit tests
run: swift test --package-path mysql-kit --enable-test-discovery
- name: Run fluent-mysql-driver tests
run: swift test --package-path fluent-mysql-driver --enable-test-discovery

macos-all:
strategy:
fail-fast: false
matrix:
formula:
- [email protected]
- [email protected]
dbimage:
- mysql
- mariadb
- percona-server
xcode:
- latest
- latest-stable
- latest
include:
- username: root
- formula: mariadb
- dbimage: mariadb
username: runner
runs-on: macos-latest
runs-on: macos-11
env:
LOG_LEVEL: debug
MYSQL_DATABASE: 'test_database'
MYSQL_USERNAME: 'test_username'
MYSQL_PASSWORD: 'test_password'
MYSQL_HOSTNAME: '127.0.0.1'
steps:
- name: Select latest available Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: ${{ matrix.xcode }}
- name: Install MySQL server from Homebrew
run: brew install ${{ matrix.formula }} && brew link --force ${{ matrix.formula }}
- name: Start MySQL server
run: brew services start ${{ matrix.formula }}
- name: Wait for MySQL server to be ready
run: until echo | mysql -u${{ matrix.username }}; do sleep 1; done
timeout-minutes: 5
- name: Set up MySQL databases and privileges
- name: Install MySQL, setup DB and auth, and wait for server start
run: |
mysql -u${{ matrix.username }} --batch <<-'SQL'
CREATE USER vapor_username@localhost IDENTIFIED BY 'vapor_password';
CREATE DATABASE vapor_database;
GRANT ALL PRIVILEGES ON vapor_database.* TO vapor_username@localhost;
brew install ${{ matrix.dbimage }} && brew link --force ${{ matrix.dbimage }}
brew services start ${{ matrix.dbimage }}
until echo | mysql -u${{ matrix.username }}; do sleep 1; done
mysql -u${{ matrix.username }} --batch <<-SQL
CREATE USER $MYSQL_USERNAME@localhost IDENTIFIED BY '$MYSQL_PASSWORD';
CREATE DATABASE $MYSQL_DATABASE;
GRANT ALL PRIVILEGES ON $MYSQL_DATABASE.* TO $MYSQL_USERNAME@localhost;
SQL
timeout-minutes: 5
- name: Check out code
uses: actions/checkout@v2
- name: Run tests with Thread Sanitizer
run: swift test --enable-test-discovery --sanitize=thread
env:
MYSQL_HOSTNAME: '127.0.0.1'
MYSQL_DATABASE: vapor_database
LOG_LEVEL: trace
# windows:
# strategy:
# fail-fast: false
# matrix:
# swiftver:
# - '5.4.2'
- name: Run all tests
run: swift test

# Leave Windows disabled until NIO works there.
# windows-all:
# runs-on: windows-latest
# continue-on-error: true
# steps:
# - uses: compnerd/gha-setup-swift@main
# with:
# branch: swift-5.5-release
# tag: 5.5-RELEASE
# - name: Check out code
# uses: actions/checkout@v2
# - name: Run tests
# uses: MaxDesiatov/swift-windows-action@v1
# with:
# shell-action: swift test
# swift-version: ${{ matrix.swiftver }}
# run: swift test
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<a href="https://swift.org">
<img src="http://img.shields.io/badge/swift-5.2-brightgreen.svg" alt="Swift 5.2">
</a>
<a href="https://swift.org">
<img src="http://img.shields.io/badge/swift-5.5-brightgreen.svg" alt="Swift 5.5">
</a>
<br>
<br>

Expand Down Expand Up @@ -96,9 +99,9 @@ import MySQLNIO
let eventLoop: EventLoop = ...
let conn = try MySQLConnection(
to: .makeAddressResolvingHost("my.mysql.server", port: 5432),
username: "vapor_username",
database: "vapor_database",
password: "vapor_password",
username: "test_username",
database: "test_database",
password: "test_password",
on: eventLoop
).wait()
```
Expand Down
20 changes: 10 additions & 10 deletions Tests/MySQLNIOTests/MySQLNIOTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,18 @@ final class MySQLNIOTests: XCTestCase {
XCTAssertEqual(dropResults.count, 0)
let createResults = try conn.simpleQuery("CREATE TABLE foos (id BIGINT SIGNED, name VARCHAR(64))").wait()
XCTAssertEqual(createResults.count, 0)
let insertResults = try conn.query("INSERT INTO foos VALUES (?, ?)", [-1, "vapor"]).wait()
let insertResults = try conn.query("INSERT INTO foos VALUES (?, ?)", [-1, "test"]).wait()
XCTAssertEqual(insertResults.count, 0)
let selectResults = try conn.query("SELECT * FROM foos WHERE name = ?", ["vapor"]).wait()
let selectResults = try conn.query("SELECT * FROM foos WHERE name = ?", ["test"]).wait()
guard selectResults.count == 1 else {
XCTFail("invalid row count")
return
}
XCTAssertEqual(selectResults[0].column("id")?.int, -1)
XCTAssertEqual(selectResults[0].column("name")?.string, "vapor")
XCTAssertEqual(selectResults[0].column("name")?.string, "test")

// test double parameterized query
let selectResults2 = try conn.query("SELECT * FROM foos WHERE name = ?", ["vapor"]).wait()
let selectResults2 = try conn.query("SELECT * FROM foos WHERE name = ?", ["test"]).wait()
XCTAssertEqual(selectResults2.count, 1)
}

Expand All @@ -224,7 +224,7 @@ final class MySQLNIOTests: XCTestCase {
XCTAssertEqual(dropResults.count, 0)
let createResults = try conn.simpleQuery("CREATE TABLE foos (id BIGINT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(64))").wait()
XCTAssertEqual(createResults.count, 0)
let insertResults = try conn.query("INSERT INTO foos (name) VALUES (?)", ["vapor"]) { metadata in
let insertResults = try conn.query("INSERT INTO foos (name) VALUES (?)", ["test"]) { metadata in
XCTAssertEqual(metadata.affectedRows, 1)
XCTAssertEqual(metadata.lastInsertID, 1)
}.wait()
Expand Down Expand Up @@ -335,7 +335,7 @@ final class MySQLNIOTests: XCTestCase {
.init("xinteger", "INTEGER(1)", 2147483647),
.init("xbigint", "BIGINT(1)", MySQLData(int: .max)),
.init("xdecimal", "DECIMAL(12,5)", MySQLData(decimal: Decimal(string:"-12.34567")!)),
.init("xname", "VARCHAR(10) NOT NULL", "vapor"),
.init("xname", "VARCHAR(10) NOT NULL", "test"),
]

let conn = try MySQLConnection.test(on: self.eventLoop).wait()
Expand All @@ -355,7 +355,7 @@ final class MySQLNIOTests: XCTestCase {
XCTAssertEqual(insertResults.count, 0)

// select data
let selectResults = try conn.query("SELECT * FROM kitchen_sink WHERE xname = ?;", ["vapor"]).wait()
let selectResults = try conn.query("SELECT * FROM kitchen_sink WHERE xname = ?;", ["test"]).wait()
XCTAssertEqual(selectResults.count, 1)

for test in tests {
Expand Down Expand Up @@ -387,11 +387,11 @@ final class MySQLNIOTests: XCTestCase {

func testSHA2() throws {
var message = ByteBufferAllocator().buffer(capacity: 0)
message.writeString("vapor")
message.writeString("test")
var digest = sha256(message)
XCTAssertEqual(digest.readBytes(length: 32), [
0xFB, 0x7A, 0xE6, 0x94, 0xBA, 0x3F, 0xD9, 0x0A, 0xE3, 0x90, 0x9C, 0xCC, 0xCD, 0x0B, 0xE0, 0xDA,
0xE9, 0x88, 0xE7, 0x02, 0x96, 0xD7, 0x09, 0x9B, 0xC5, 0x70, 0x8A, 0x87, 0x2F, 0x4C, 0xC1, 0x72
0x9f, 0x86, 0xd0, 0x81, 0x88, 0x4c, 0x7d, 0x65, 0x9a, 0x2f, 0xea, 0xa0, 0xc5, 0x5a, 0xd0, 0x15,
0xa3, 0xbf, 0x4f, 0x1b, 0x2b, 0x0b, 0x82, 0x2c, 0xd1, 0x5d, 0x6c, 0x15, 0xb0, 0xf0, 0x0a, 0x08,
])
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/MySQLNIOTests/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ extension MySQLConnection {
tls.certificateVerification = .none
return self.connect(
to: addr,
username: env("MYSQL_USERNAME") ?? "vapor_username",
database: env("MYSQL_DATABASE") ?? "vapor_database",
password: env("MYSQL_PASSWORD") ?? "vapor_password",
username: env("MYSQL_USERNAME") ?? "test_username",
database: env("MYSQL_DATABASE") ?? "test_database",
password: env("MYSQL_PASSWORD") ?? "test_password",
tlsConfiguration: tls,
on: eventLoop
)
Expand Down
Loading

0 comments on commit 03cc5d4

Please sign in to comment.