Skip to content

Commit 3206b2a

Browse files
authored
#109 better separation between unit tests and integration tests (#111)
* #109 stop running IT in unittest * #109 update ddbctest to test all supported databases against containers * install msodbcsql18 for integration tests * use env for db ports * add CONTRIBUTING.md file * remove Visual Studio project files and update gitignore
1 parent 97861c7 commit 3206b2a

21 files changed

+650
-2005
lines changed

.github/workflows/dub.yml

+25-16
Original file line numberDiff line numberDiff line change
@@ -57,38 +57,38 @@ jobs:
5757
run: dub build --config=full --arch=x86_64
5858

5959
# x86 (Windows Only)
60-
- name: dub test with SQLite config (x86)
60+
- name: dub test with full config (x86)
6161
if: ${{ startsWith(matrix.os, 'windows') }}
62-
run: dub test --config=SQLite --arch=x86
62+
run: dub test --config=full --arch=x86
6363

64-
- name: dub run with test config (x86)
65-
if: ${{ startsWith(matrix.os, 'windows') }}
66-
run: dub run --config=test --arch=x86
64+
#- name: dub run with test config (x86)
65+
# if: ${{ startsWith(matrix.os, 'windows') }}
66+
# run: dub run --config=test --arch=x86
6767

6868
- name: run the ddbctest project (x86)
6969
if: ${{ startsWith(matrix.os, 'windows') }}
7070
working-directory: example
7171
run: dub build --config=SQLite --arch=x86 && ./ddbctest --connection=sqlite:ddbc-test.sqlite
7272

7373
# x86_64 (all platforms)
74-
- name: dub test with SQLite config (x86_64)
75-
run: dub test --config=SQLite --arch=x86_64
74+
- name: dub test with full config (x86_64)
75+
run: dub test --config=full --arch=x86_64
7676

77-
- name: dub run with test config (x86_64)
78-
run: dub run --config=test --arch=x86_64
77+
#- name: dub run with test config (x86_64)
78+
# run: dub run --config=test --arch=x86_64
7979

8080
- name: run the ddbctest project (x86_64)
8181
working-directory: example
8282
run: dub build --config=SQLite --arch=x86_64 && ./ddbctest --connection=sqlite:ddbc-test.sqlite
8383

8484
# x86_mscoff (Windows with dmd Only)
85-
- name: dub test with SQLite config (x86_mscoff)
85+
- name: dub test with full config (x86_mscoff)
8686
if: ${{ startsWith(matrix.os, 'windows') && startsWith(matrix.compiler, 'dmd') }}
87-
run: dub test --config=SQLite --arch=x86_mscoff
87+
run: dub test --config=full --arch=x86_mscoff
8888

89-
- name: dub run with test config (x86_mscoff)
90-
if: ${{ startsWith(matrix.os, 'windows') && startsWith(matrix.compiler, 'dmd') }}
91-
run: dub run --config=test --arch=x86_mscoff
89+
#- name: dub run with test config (x86_mscoff)
90+
# if: ${{ startsWith(matrix.os, 'windows') && startsWith(matrix.compiler, 'dmd') }}
91+
# run: dub run --config=test --arch=x86_mscoff
9292

9393
- name: run the ddbctest project (x86_mscoff)
9494
if: ${{ startsWith(matrix.os, 'windows') && startsWith(matrix.compiler, 'dmd') }}
@@ -157,6 +157,16 @@ jobs:
157157
with:
158158
compiler: dmd-latest
159159

160+
- name: Install Microsoft ODBC
161+
run: sudo ACCEPT_EULA=Y apt-get install msodbcsql18 -y
162+
163+
- name: Run ddbctest
164+
env:
165+
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
166+
POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
167+
MSSQL_PORT: ${{ job.services.mssql.ports[1433] }}
168+
run: dub run --config=test
169+
160170
- name: Build The Example Project
161171
working-directory: ./example
162172
run: dub build
@@ -185,5 +195,4 @@ jobs:
185195
env:
186196
PORT: ${{ job.services.mssql.ports[1433] }}
187197
run: |
188-
sudo ACCEPT_EULA=Y apt-get install msodbcsql17 -y
189-
./ddbctest --connection=odbc://127.0.0.1:$PORT --database=dbo --user=SA --password=MSbbk4k77JKH88g54 --driver="ODBC Driver 17 for SQL Server" --trusted_connection=yes
198+
./ddbctest --connection=odbc://127.0.0.1:$PORT --user=SA --password=MSbbk4k77JKH88g54 --driver="ODBC Driver 18 for SQL Server" --trusted_connection=yes

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Thumbs.db
99
.idea/
1010
*.iml
1111

12+
#Ignore project files by Visual Studio
13+
*.sln
14+
*.visualdproj
15+
1216
#Ignore files build by Visual Studio
1317
*.user
1418
*.aps
@@ -28,7 +32,6 @@ Thumbs.db
2832
obj/
2933
[Rr]elease*/
3034
_ReSharper*/
31-
code.visualdproj
3235
HibernatedTest/*
3336
Unittest/*
3437

CONTRIBUTING.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
DDBC aims to support a range of compiler versions across from dmd 2.097 and above across a range of databases; SQLite, MySQL/MariaDB, Postgres, SQL Server, and Oracle.
2+
3+
## Tests
4+
5+
To help with testing there is a *docker-compose.yml* file in the root of the project so that multiple databases can be run locally for testing.
6+
7+
When making changes to DDBC please ensure that unit tests (test not requiring a working database) remain in the project source and any integration tests (those running against a local database) are placed the test project (under `./test/ddbctest/`).
8+
9+
unit tests can br run in the usual way with `dub test` and integration tests are run with `dub run --config=test`.
10+
11+
## Requirements for developing
12+
13+
Apart from a D compiler such as dmd or ldc and the dub package manager, you'll need to have docker and docker-compose installed. If you want to test against an Oracle container you'll also need to have a login for [container-registry.oracle.com](https://container-registry.oracle.com) and have accepted their terms & conditions. There's also some libraries you'll need to have installed.
14+
15+
On Fedora Linux you can do this using:
16+
17+
```
18+
sudo dnf install openssl-devel sqlite-devel libpq-devel -y
19+
```
20+
21+
### Installing Microsoft's odbc driver
22+
23+
On Linux you can potentially use [FreeTDS](https://www.freetds.org/) as the ODBC driver when connecting to SQL Server. However, Microsoft do provide their own odbc driver and that is what's used for testing against SQL Server during CI.
24+
25+
On Fedora Linux you can find packages under [packages.microsoft.com/config/rhel/](https://packages.microsoft.com/config/rhel/). See the documentation [here](https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver16#redhat18) for more details.The basic steps are:
26+
27+
```
28+
# curl https://packages.microsoft.com/config/rhel/8/prod.repo > /etc/yum.repos.d/mssql-release.repo
29+
30+
sudo yum remove unixODBC-utf16 unixODBC-utf16-devel
31+
sudo ACCEPT_EULA=Y dnf install -y unixODBC unixODBC-devel msodbcsql18 mssql-tools18
32+
33+
sudo cat /etc/odbcinst.ini
34+
```
35+
36+
## Installing databases locally (non-containerised)
37+
38+
### MySQL (local)
39+
40+
To allow unit tests using MySQL server,
41+
run mysql client using admin privileges, e.g. for MySQL server on localhost:
42+
43+
```
44+
> mysql -uroot
45+
```
46+
47+
Create test user and test DB:
48+
49+
```
50+
mysql> CREATE DATABASE IF NOT EXISTS testdb;
51+
mysql> CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'passw0rd';
52+
mysql> GRANT ALL PRIVILEGES ON testdb.* TO 'testuser'@'localhost';
53+
54+
mysql> CREATE USER 'testuser'@'localhost';
55+
mysql> GRANT ALL PRIVILEGES ON testdb.* TO 'testuser'@'localhost' IDENTIFIED BY 'passw0rd';
56+
mysql> FLUSH PRIVILEGES;
57+
```
58+
59+
### Postgres (local)
60+
61+
To allow unit tests using PostgreSQL server,
62+
run postgres client using admin privileges, e.g. for postgres server on localhost:
63+
64+
```
65+
sudo -u postgres psql
66+
```
67+
68+
Then create a user and test database:
69+
70+
```
71+
postgres=# CREATE USER testuser WITH ENCRYPTED PASSWORD 'passw0rd';
72+
postgres=# CREATE DATABASE testdb WITH OWNER testuser ENCODING 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8' TEMPLATE template0;
73+
```

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ ddbc:mysql://127.0.0.1:3306
138138

139139
```
140140
ddbc:postgresql://127.0.0.1:5432
141+
142+
or
143+
144+
ddbc:postgresql://hostname:5432/dbname
141145
```
142146

143147
### Microsoft SQL Server (via ODBC)

ddbc.sln

-54
This file was deleted.

0 commit comments

Comments
 (0)