Skip to content

Commit 323ee58

Browse files
authored
Merge pull request #235 from schveiguy/splittests
Split testing into its own project
2 parents 3dc9742 + ef97eb1 commit 323ee58

File tree

27 files changed

+1613
-1834
lines changed

27 files changed

+1613
-1834
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ trim_trailing_whitespace=true
77
insert_final_newline=true
88
end_of_line=lf
99
charset=utf-8
10+
11+
[*.yml]
12+
indent_style=space
13+
indent_size=2

.github/workflows/dub.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ on:
99
schedule:
1010
- cron: '30 7 1 * *'
1111
push:
12+
branches:
13+
- master
1214
pull_request:
15+
workflow_dispatch:
1316

1417
jobs:
1518
build:

.github/workflows/integration-testing.yml

Lines changed: 65 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ on:
99
schedule:
1010
- cron: '30 7 1 * *'
1111
push:
12+
branches:
13+
- master
1214
pull_request:
15+
workflow_dispatch:
1316

1417
jobs:
1518
# mysql8-tests:
@@ -41,37 +44,37 @@ jobs:
4144
# --health-retries 4
4245

4346
# steps:
44-
# - uses: actions/checkout@v2
45-
46-
# - name: Install ${{ matrix.compiler }}
47-
# uses: dlang-community/setup-dlang@v1
48-
# with:
49-
# compiler: ${{ matrix.compiler }}
50-
51-
# - name: Install dependencies on Ubuntu
52-
# if: startsWith(matrix.os, 'ubuntu')
53-
# run: sudo apt-get update && sudo apt-get install libevent-dev -y
54-
55-
# ## Turns out the unittest-vibe-ut tried to connect to an actualy MySQL on 172.18.0.1 so it's not
56-
# ## actually a unit test at all. It's an integration test and should be pulled out from the main
57-
# ## codebase into a separate sub module
58-
# - name: Run unittest-vibe-ut
59-
# env:
60-
# MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
61-
# run: |
62-
# echo "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb" > testConnectionStr.txt
63-
# dub run -c unittest-vibe-ut -- -t
64-
65-
# - name: Build The Example Project
66-
# working-directory: ./examples/homePage
67-
# run: dub build
68-
69-
# - name: Run Example (MySQL 8)
70-
# working-directory: ./examples/homePage
71-
# env:
72-
# MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
73-
# run: |
74-
# ./example "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb"
47+
# - uses: actions/checkout@v2
48+
49+
# - name: Install ${{ matrix.compiler }}
50+
# uses: dlang-community/setup-dlang@v1
51+
# with:
52+
# compiler: ${{ matrix.compiler }}
53+
54+
# - name: Set up test connection string
55+
# env:
56+
# MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
57+
# run: |
58+
# echo "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb" > testConnectionStr.txt
59+
60+
# - name: Run unittests with Vibe.d
61+
# run: |
62+
# dub run ":integration-tests-vibe"
63+
64+
# - name: Run unittests with Phobos
65+
# run: |
66+
# dub run ":integration-tests-phobos"
67+
68+
# - name: Build The Example Project
69+
# working-directory: ./examples/homePage
70+
# run: dub build
71+
72+
# - name: Run Example (MySQL 8)
73+
# working-directory: ./examples/homePage
74+
# env:
75+
# MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
76+
# run: |
77+
# ./example "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb"
7578

7679
mysql57-tests:
7780
name: MySQL 5.7 Tests ${{ matrix.compiler }}
@@ -113,19 +116,25 @@ jobs:
113116
with:
114117
compiler: ${{ matrix.compiler }}
115118

116-
- name: Install dependencies on Ubuntu
117-
if: startsWith(matrix.os, 'ubuntu')
118-
run: sudo apt-get update && sudo apt-get install libevent-dev -y
119-
120-
## Turns out the unittest-vibe-ut tried to connect to an actualy MySQL on 172.18.0.1 so it's not
121-
## actually a unit test at all. It's an integration test and should be pulled out from the main
122-
## codebase into a separate sub module
123-
- name: Run unittest-vibe-ut
119+
- name: Set up test connection string
124120
env:
125121
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
126122
run: |
127123
echo "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb" > testConnectionStr.txt
128-
dub run -c unittest-vibe-ut -- -t
124+
125+
- name: Run unittests with Vibe.d
126+
run: |
127+
dub run ":integration-tests-vibe"
128+
129+
- name: Run unittests with Phobos
130+
run: |
131+
dub run ":integration-tests-phobos"
132+
133+
- name: Run test connection utility
134+
env:
135+
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
136+
run: |
137+
dub run ":testconn" -- "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb"
129138
130139
- name: Build The Example Project
131140
working-directory: ./examples/homePage
@@ -178,19 +187,25 @@ jobs:
178187
with:
179188
compiler: ${{ matrix.compiler }}
180189

181-
- name: Install dependencies on Ubuntu
182-
if: startsWith(matrix.os, 'ubuntu')
183-
run: sudo apt-get update && sudo apt-get install libevent-dev -y
184-
185-
## Turns out the unittest-vibe-ut tried to connect to an actualy MySQL on 172.18.0.1 so it's not
186-
## actually a unit test at all. It's an integration test and should be pulled out from the main
187-
## codebase into a separate sub module
188-
- name: Run unittest-vibe-ut
190+
- name: Set up test connection string
189191
env:
190192
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
191193
run: |
192194
echo "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb" > testConnectionStr.txt
193-
dub run -c unittest-vibe-ut -- -t
195+
196+
- name: Run unittests with Vibe.d
197+
run: |
198+
dub run ":integration-tests-vibe"
199+
200+
- name: Run unittests with Phobos
201+
run: |
202+
dub run ":integration-tests-phobos"
203+
204+
- name: Run test connection utility
205+
env:
206+
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
207+
run: |
208+
dub run ":testconn" -- "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb"
194209
195210
- name: Build The Example Project
196211
working-directory: ./examples/homePage
@@ -201,4 +216,4 @@ jobs:
201216
env:
202217
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
203218
run: |
204-
./example "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb"
219+
./example "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb"

README.md

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ MySQL native
55
[![GitHub - Builds](https://github.com/mysql-d/mysql-native/actions/workflows/dub.yml/badge.svg)](https://github.com/mysql-d/mysql-native/actions/workflows/dub.yml)
66
[![GitHub - Integration Tests](https://github.com/mysql-d/mysql-native/actions/workflows/integration-testing.yml/badge.svg)](https://github.com/mysql-d/mysql-native/actions/workflows/integration-testing.yml)
77

8+
*NOTE: we are in the process of migrating to github actions. Documentation will
9+
eventually be generated using github actions, and stored on github. This README
10+
is in flux at the moment, and may contain outdated information*
11+
812
A [Boost-licensed](http://www.boost.org/LICENSE_1_0.txt) native [D](http://dlang.org)
913
client driver for MySQL and MariaDB.
1014

@@ -89,7 +93,7 @@ void main(string[] args)
8993
"SELECT * FROM `tablename` WHERE `name`=? OR `name`=?",
9094
"Bob", "Bobby");
9195
bobs.close(); // Skip them
92-
96+
9397
Row[] rs = conn.query( // Same SQL as above, but only prepared once and is reused!
9498
"SELECT * FROM `tablename` WHERE `name`=? OR `name`=?",
9599
"Bob", "Ann").array; // Get ALL the rows at once
@@ -119,26 +123,41 @@ Additional notes
119123

120124
This requires MySQL server v4.1.1 or later, or a MariaDB server. Older
121125
versions of MySQL server are obsolete, use known-insecure authentication,
122-
and are not supported by this package.
126+
and are not supported by this package. Currently the github actions tests use
127+
MySQL 5.7 and MariaDB 10. MySQL 8 is supported with `mysql_native_password`
128+
authentication, but is not currently tested. Expect this to change in the future.
123129

124130
Normally, MySQL clients connect to a server on the same machine via a Unix
125131
socket on *nix systems, and through a named pipe on Windows. Neither of these
126132
conventions is currently supported. TCP is used for all connections.
127133

128-
For historical reference, see the [old homepage](http://britseyeview.com/software/mysqln/)
129-
for the original release of this project. Note, however, that version has
130-
become out-of-date.
134+
Unfortunately, the original home page of Steve Teale's mysqln is no longer
135+
available. You can see an archive on the [Internet Archive wayback
136+
machine](https://web.archive.org/web/20120323165808/http://britseyeview.com/software/mysqln)
131137

132138
Developers - How to run the test suite
133139
--------------------------------------
134140

135-
This package contains various unittests and integration tests. To run them,
136-
run `run-tests`.
141+
Unittests that do not require an actual server are located in the library
142+
codebase. You can run just these tests using `dub test`.
143+
144+
Unittests that require a working server are all located in the
145+
[integration-tests](integration-tests) subpackage. Due to a [dub
146+
issue](https://github.com/dlang/dub/issues/2136), the integration tests are run
147+
using the [integration-tests-phobos](integration-tests-phobos) and
148+
[integration-tests-vibe](integration-tests-vibe) subpackages. At some point, if this dub issue
149+
is fixed, they will simply become configurations in the main integration-tests
150+
repository. You can run these directly from the main repository folder by
151+
issuing the commands:
152+
153+
```sh
154+
dub run :integration-tests-phobos
155+
dub run :integration-tests-vibe
156+
```
157+
This will also run the library tests as well as the integration tests.
137158

138-
The first time you run `run-tests`, it will automatically create a
139-
file `testConnectionStr.txt` in project's base diretory and then exit.
140-
This file is deliberately not contained in the source repository
141-
because it's specific to your system.
159+
The first time you run an integration test, the file `testConnectionStr.txt`
160+
will be created in your current directory
142161

143162
Open the `testConnectionStr.txt` file and verify the connection settings
144163
inside, modifying them as needed, and if necessary, creating a test user and
@@ -148,6 +167,9 @@ The tests will completely clobber anything inside the db schema provided,
148167
but they will ONLY modify that one db schema. No other schema will be
149168
modified in any way.
150169

151-
After you've configured the connection string, run `run-tests` again
152-
and their tests will be compiled and run, first using Phobos sockets,
153-
then using Vibe sockets.
170+
After you've configured the connection string, run the integration tests again.
171+
172+
The integration tests use
173+
[unit-threaded](https://code.dlang.org/packages/unit-threaded) which allows for
174+
running individual named tests. Use this for running specific tests instead of
175+
the whole suite.

dub.sdl

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,22 @@
11
name "mysql-native"
22
description "A native MySQL driver implementation based on Steve Teale's original"
33
license "BSL-1.0"
4-
copyright "Copyright (c) 2011-2019 Steve Teale, James W. Oliphant, Simen Endsjø, Sönke Ludwig, Sergey Shamov, and Nick Sabalausky"
5-
authors "Steve Teale" "James W. Oliphant" "Simen Endsjø" "Sönke Ludwig" "Sergey Shamov" "Nick Sabalausky"
4+
copyright "Copyright (c) 2011-2021 Steve Teale, James W. Oliphant, Simen Endsjø, Sönke Ludwig, Sergey Shamov, Nick Sabalausky, and Steven Schveighoffer"
5+
authors "Steve Teale" "James W. Oliphant" "Simen Endsjø" "Sönke Ludwig" "Sergey Shamov" "Nick Sabalausky" "Steven Schveighoffer"
66

77
dependency "vibe-core" version="~>1.16.0" optional=true
88

99
toolchainRequirements frontend=">=2.068"
1010

11-
sourcePaths "source/"
12-
importPaths "source/"
13-
14-
configuration "application" {
15-
targetType "executable"
16-
versions "VibeCustomMain"
17-
}
11+
subPackage "./integration-tests"
12+
subPackage "./integration-tests-vibe"
13+
subPackage "./integration-tests-phobos"
14+
subPackage "./testconn"
1815

1916
configuration "library" {
20-
targetType "library"
21-
excludedSourceFiles "source/app.d"
2217
}
2318

24-
// Do not use this. Use "run_tests" insetad.
2519
configuration "unittest" {
26-
excludedSourceFiles "source/app.d"
27-
preBuildCommands \
28-
"echo \"ERROR: Don't use 'dub test' to test mysql-native. Use 'run_tests' instead.\"" \
29-
"echo Bailing..." \
30-
"mkdir" // Generate error to halt build
31-
}
32-
33-
// Run with: dub test -c unittest-vibe
34-
configuration "unittest-vibe" {
35-
targetType "executable"
36-
targetPath "bin/"
37-
targetName "mysqln-tests-vibe"
38-
excludedSourceFiles "source/app.d"
39-
40-
dependency "vibe-core" version="~>1.16.0" optional=false
41-
42-
// mainSourceFile "source/mysql/package.d"
4320
debugVersions "MYSQLN_TESTS"
44-
}
45-
46-
// Run with: dub run -c unittest-vibe-ut -- -t
47-
configuration "unittest-vibe-ut" {
48-
targetType "executable"
49-
targetPath "bin/"
50-
targetName "mysqln-tests-vibe"
51-
excludedSourceFiles "source/app.d"
52-
sourceFiles "bin/ut.d"
53-
importPaths "bin/"
54-
buildOptions "unittests"
55-
56-
dependency "vibe-core" version="~>1.16.0" optional=false
57-
58-
dependency "unit-threaded" version="~>1.0.15"
59-
60-
debugVersions "MYSQLN_TESTS"
61-
versions "MYSQLN_TESTS_NO_MAIN"
62-
versions "unitUnthreaded"
63-
64-
preBuildCommands "dub run unit-threaded -c gen_ut_main -- -f bin/ut.d"
21+
targetType "sourceLibrary"
6522
}

integration-tests-phobos/dub.sdl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name "integration-tests-phobos"
2+
description "Phobos tests for mysql-native"
3+
license "BSL-1.0"
4+
copyright "Copyright (c) 2011-2021 Steve Teale, James W. Oliphant, Simen Endsjø, Sönke Ludwig, Sergey Shamov, Nick Sabalausky, and Steven Schveighoffer"
5+
authors "Steve Teale" "James W. Oliphant" "Simen Endsjø" "Sönke Ludwig" "Sergey Shamov" "Nick Sabalausky" "Steven Schveighoffer"
6+
7+
dependency "mysql-native:integration-tests" path="../"
8+
targetType "executable"

integration-tests-phobos/source/dummy.d

Whitespace-only changes.

integration-tests-vibe/dub.sdl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name "integration-tests-vibe"
2+
description "Vibe tests for mysql-native"
3+
license "BSL-1.0"
4+
copyright "Copyright (c) 2011-2021 Steve Teale, James W. Oliphant, Simen Endsjø, Sönke Ludwig, Sergey Shamov, Nick Sabalausky, and Steven Schveighoffer"
5+
authors "Steve Teale" "James W. Oliphant" "Simen Endsjø" "Sönke Ludwig" "Sergey Shamov" "Nick Sabalausky" "Steven Schveighoffer"
6+
7+
dependency "mysql-native:integration-tests" path="../"
8+
dependency "vibe-core" version="~>1.16.0"
9+
targetType "executable"

integration-tests-vibe/source/dummy.d

Whitespace-only changes.

integration-tests/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Integration Tests for MySQL Native
2+
==================================
3+
4+
This sub-project is intended for proving the functionality of the project against a database instance.
5+
6+
See the instructions in the [main README](../README.md#developers---how-to-run-the-test-suite) on how to use this subpackage.
7+
8+
## Docker image
9+
10+
A docker-compose.yml is supplied for convenience when testing locally. It's preconfigured to use the same username/password that is used by default.
11+
12+
To run tests on your machine, presuming docker is installed, simply run:
13+
14+
```
15+
$ docker-compose up --detach
16+
```
17+
18+
Once you are finished, tear down the docker instance
19+
20+
```
21+
$ docker-compose down
22+
```

integration-tests/docker-compose.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: '3.7'
2+
services:
3+
mysql:
4+
# Don't use latest (MySQL Server 8.0) as we cannot currently support it
5+
image: mysql:5.7
6+
restart: always
7+
ports: ['3306:3306']
8+
environment:
9+
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
10+
- MYSQL_DATABASE=mysqln_testdb
11+
- MYSQL_USER=mysqln_test
12+
- MYSQL_PASSWORD=pass123

0 commit comments

Comments
 (0)