From 03cc5d49379f26f9d6bd1703c99d46b7fcaacd2d Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Sat, 13 Nov 2021 09:57:55 -0600 Subject: [PATCH] Updates default DB config for tests to use test_ prefix (#67) * 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. --- .github/workflows/test.yml | 225 +++++++++--------------- README.md | 9 +- Tests/MySQLNIOTests/MySQLNIOTests.swift | 20 +-- Tests/MySQLNIOTests/Utilities.swift | 6 +- docker-compose.yml | 66 +++---- test.Dockerfile | 3 - 6 files changed, 131 insertions(+), 198 deletions(-) delete mode 100644 test.Dockerfile diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e1e5e37..c9e0930 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: - - mysql@8.0 - - mysql@5.7 + 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 diff --git a/README.md b/README.md index 83b67c0..4b478a7 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,9 @@ Swift 5.2 + + Swift 5.5 +

@@ -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() ``` diff --git a/Tests/MySQLNIOTests/MySQLNIOTests.swift b/Tests/MySQLNIOTests/MySQLNIOTests.swift index a50ac8d..bea091d 100644 --- a/Tests/MySQLNIOTests/MySQLNIOTests.swift +++ b/Tests/MySQLNIOTests/MySQLNIOTests.swift @@ -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) } @@ -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() @@ -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() @@ -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 { @@ -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, ]) } diff --git a/Tests/MySQLNIOTests/Utilities.swift b/Tests/MySQLNIOTests/Utilities.swift index ac27c95..47dbb4a 100644 --- a/Tests/MySQLNIOTests/Utilities.swift +++ b/Tests/MySQLNIOTests/Utilities.swift @@ -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 ) diff --git a/docker-compose.yml b/docker-compose.yml index 2f1c605..7570550 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,49 +1,31 @@ version: '3' +x-shared-config: &shared_config + platform: linux/amd64 + environment: + MYSQL_ALLOW_EMPTY_PASSWORD: "true" + MYSQL_DATABASE: test_database + MYSQL_USER: test_username + MYSQL_PASSWORD: test_password + ports: + - 3306:3306 + services: - mariadb: - image: mariadb - environment: - MYSQL_ALLOW_EMPTY_PASSWORD: "true" - MYSQL_DATABASE: vapor_database - MYSQL_USER: vapor_username - MYSQL_PASSWORD: vapor_password - ports: - - 3306:3306 - mysql: - image: mysql - environment: - MYSQL_ALLOW_EMPTY_PASSWORD: "true" - MYSQL_DATABASE: vapor_database - MYSQL_USER: vapor_username - MYSQL_PASSWORD: vapor_password - ports: - - 3306:3306 + percona-8_0: + image: percona:8.0 + <<: *shared_config + percona-5_7: + image: percona:5.7 + <<: *shared_config + mariadb-10_7: + image: mariadb:10.7 + <<: *shared_config + mariadb-10_2: + image: mariadb:10.2 + <<: *shared_config mysql-8_0: image: mysql:8.0 - environment: - MYSQL_ALLOW_EMPTY_PASSWORD: "true" - MYSQL_DATABASE: vapor_database - MYSQL_USER: vapor_username - MYSQL_PASSWORD: vapor_password - ports: - - 3306:3306 + <<: *shared_config mysql-5_7: image: mysql:5.7 - environment: - MYSQL_ALLOW_EMPTY_PASSWORD: "true" - MYSQL_DATABASE: vapor_database - MYSQL_USER: vapor_username - MYSQL_PASSWORD: vapor_password - ports: - - 3306:3306 - # unsupported: for testing errors - mysql-5_6: - image: mysql:5.6 - environment: - MYSQL_ALLOW_EMPTY_PASSWORD: "true" - MYSQL_DATABASE: vapor_database - MYSQL_USER: vapor_username - MYSQL_PASSWORD: vapor_password - ports: - - 3306:3306 + <<: *shared_config diff --git a/test.Dockerfile b/test.Dockerfile deleted file mode 100644 index 4dda9e9..0000000 --- a/test.Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM vapor/swift:5.0 -COPY . . -ENTRYPOINT swift test