Skip to content

Commit 6f9aadb

Browse files
committedMay 3, 2021
run examples and hdtest during CI
1 parent ce7ad26 commit 6f9aadb

File tree

4 files changed

+137
-23
lines changed

4 files changed

+137
-23
lines changed
 

‎.github/workflows/dub.yml

+92-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- master
1212

1313
jobs:
14-
test:
14+
builds:
1515
name: ${{ matrix.compiler }} on ${{ matrix.os }}
1616
strategy:
1717
fail-fast: false
@@ -30,10 +30,6 @@ jobs:
3030
- dmd-2.088.1
3131
- dmd-2.087.1
3232
- dmd-2.086.1
33-
- dmd-2.085.1
34-
- dmd-2.084.1
35-
- dmd-2.083.1
36-
- dmd-2.082.1
3733
- ldc-1.25.1 # eq to dmd v2.095.1
3834
- ldc-1.24.0 # eq to dmd v2.094.1
3935
- ldc-1.23.0 # eq to dmd v2.093.1
@@ -42,10 +38,6 @@ jobs:
4238
- ldc-1.18.0 # eq to dmd v2.088.1
4339
- ldc-1.17.0 # eq to dmd v2.087
4440
- ldc-1.16.0 # eq to dmd v2.086.1
45-
- ldc-1.15.0 # eq to dmd v2.085.1
46-
- ldc-1.14.0 # eq to dmd v2.084.1
47-
- ldc-1.13.0 # eq to dmd v2.083.1
48-
- ldc-1.12.0 # eq to dmd v2.082.1
4941
runs-on: ${{ matrix.os }}
5042
steps:
5143
- uses: actions/checkout@v1
@@ -65,7 +57,95 @@ jobs:
6557

6658
- name: build with SQLite config
6759
run: dub build --config=SQLite
60+
61+
examples:
62+
name: Test ${{ matrix.compiler }} on ${{ matrix.os }}
63+
runs-on: ${{ matrix.os }}
64+
strategy:
65+
fail-fast: false
66+
matrix:
67+
os: [ ubuntu-latest, windows-latest, macos-latest ]
68+
compiler:
69+
- dmd-latest
70+
- ldc-latest
71+
steps:
72+
- uses: actions/checkout@v2
73+
74+
- name: Install D ${{ matrix.compiler }}
75+
uses: dlang-community/setup-dlang@v1
76+
with:
77+
compiler: ${{ matrix.compiler }}
78+
79+
- name: Install dependencies on Ubuntu
80+
if: startsWith(matrix.os, 'ubuntu')
81+
run: sudo apt-get update && sudo apt-get install libev-dev libpq-dev libevent-dev libsqlite3-dev -y
82+
83+
- name: Install dependencies on Mac OSX
84+
if: startsWith(matrix.os, 'macos')
85+
run: brew bundle
86+
87+
- name: Run example 1
88+
working-directory: examples/example1
89+
run: dub
90+
91+
integration-tests:
92+
name: Integration Tests
93+
runs-on: ubuntu-20.04
94+
95+
services:
96+
mysql:
97+
image: mysql:5.7
98+
ports: [3306]
99+
env:
100+
MYSQL_ROOT_PASSWORD: f48dfhw3Hd!Asah7i2aZ
101+
MYSQL_DATABASE: hdtest
102+
MYSQL_USER: testuser
103+
MYSQL_PASSWORD: passw0rd
104+
# Set health checks to wait until mysql service has started
105+
options: >-
106+
--health-cmd "mysqladmin ping"
107+
--health-interval 10s
108+
--health-timeout 3s
109+
--health-retries 4
110+
111+
postgres:
112+
image: postgres
113+
ports: [5432]
114+
env:
115+
POSTGRES_DB: hdtest
116+
POSTGRES_USER: testuser
117+
POSTGRES_PASSWORD: passw0rd
118+
# Set health checks to wait until postgres service has started
119+
options: >-
120+
--health-cmd pg_isready
121+
--health-interval 10s
122+
--health-timeout 3s
123+
--health-retries 3
124+
125+
steps:
126+
- uses: actions/checkout@v2
127+
128+
- name: Install latest DMD
129+
uses: dlang-community/setup-dlang@v1
130+
with:
131+
compiler: dmd-latest
132+
133+
- name: HD Test (SQLite)
134+
working-directory: ./hdtest
135+
run: |
136+
dub build --config=SQLite && ./bin/hdtest
137+
138+
- name: HD Test (MySQL)
139+
working-directory: ./hdtest
140+
env:
141+
PORT: ${{ job.services.mysql.ports[3306] }}
142+
run: |
143+
dub build --config=MySQL && ./bin/hdtest --host=127.0.0.1 --port=$PORT --database=hdtest --user=testuser --password=passw0rd
144+
145+
- name: HD Test (Postgres)
146+
working-directory: ./hdtest
147+
env:
148+
PORT: ${{ job.services.postgres.ports[5432] }}
149+
run: |
150+
dub build --config=PGSQL && ./bin/hdtest --host=127.0.0.1 --port=$PORT --database=hdtest --user=testuser --password=passw0rd
68151
69-
- name: run the hdtest project
70-
working-directory: hdtest
71-
run: dub --config=SQLite

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ __test__library__
3131
*.db
3232
dub.selections.json
3333
.dub/
34+
examples/example1/example1
3435

3536

3637
# Ignore code coverage:

‎examples/example1/dub.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "ddbctest",
2+
"name": "example1",
33
"description": "example1 for Hibernated",
44
"authors": ["Vadim Lopatin"],
55
"homepage": "https://github.com/buggins/hibernated",

‎hdtest/source/htestmain.d

+43-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
module htestmain;
22

3+
import std.algorithm;
34
import std.stdio;
45
import std.string;
56
import std.conv;
7+
import std.getopt;
68
import hibernated.core;
79
import std.traits;
810

@@ -68,26 +70,34 @@ class MyGroup {
6870
}
6971
}
7072

71-
void testHibernate() {
73+
void testHibernate(immutable string host, immutable ushort port, immutable string dbName, immutable string dbUser, immutable string dbPass) {
74+
7275
// setup DB connection
7376
version( USE_SQLITE )
7477
{
7578
import ddbc.drivers.sqliteddbc;
76-
SQLITEDriver driver = new SQLITEDriver();
7779
string[string] params;
78-
DataSource ds = new ConnectionPoolDataSourceImpl(driver, "zzz.db", params);
80+
DataSource ds = new ConnectionPoolDataSourceImpl(new SQLITEDriver(), "zzz.db", params);
7981
Dialect dialect = new SQLiteDialect();
8082
}
83+
else version( USE_MYSQL )
84+
{
85+
import ddbc.drivers.mysqlddbc;
86+
immutable string url = MySQLDriver.generateUrl(host, port, dbName);
87+
string[string] params = MySQLDriver.setUserAndPassword(dbUser, dbPass);
88+
DataSource ds = new ConnectionPoolDataSourceImpl(new MySQLDriver(), url, params);
89+
Dialect dialect = new MySQLDialect();
90+
}
8191
else version( USE_PGSQL )
8292
{
8393
import ddbc.drivers.pgsqlddbc;
84-
string url = PGSQLDriver.generateUrl( "/tmp", 5432, "testdb" );
94+
immutable string url = PGSQLDriver.generateUrl(host, port, dbName); // PGSQLDriver.generateUrl( "/tmp", 5432, "testdb" );
8595
string[string] params;
86-
params["user"] = "hdtest";
87-
params["password"] = "secret";
96+
params["user"] = dbUser;
97+
params["password"] = dbPass;
8898
params["ssl"] = "true";
89-
PGSQLDriver driver = new PGSQLDriver();
90-
DataSource ds = new ConnectionPoolDataSourceImpl(driver,url, params);
99+
100+
DataSource ds = new ConnectionPoolDataSourceImpl(new PGSQLDriver(), url, params);
91101
Dialect dialect = new PGSQLDialect();
92102
}
93103

@@ -238,7 +248,30 @@ void testHibernate() {
238248
//sess.remove(u11);
239249
}
240250

241-
void main()
251+
struct ConnectionParams
252+
{
253+
string host;
254+
ushort port;
255+
string database;
256+
string user;
257+
string pass;
258+
}
259+
260+
int main(string[] args)
242261
{
243-
testHibernate();
262+
ConnectionParams par;
263+
string URI;
264+
265+
try
266+
{
267+
getopt(args, "host",&par.host, "port",&par.port, "database",&par.database, "user",&par.user, "password",&par.pass);
268+
}
269+
catch (GetOptException)
270+
{
271+
stderr.writefln("Could not parse args");
272+
return 1;
273+
}
274+
testHibernate(par.host, par.port, par.database, par.user, par.pass);
275+
276+
return 0;
244277
}

0 commit comments

Comments
 (0)
Please sign in to comment.