Skip to content

Commit 4c45cd1

Browse files
committed
Add github actions because travis disappeared
1 parent 42e2f66 commit 4c45cd1

File tree

6 files changed

+181
-104
lines changed

6 files changed

+181
-104
lines changed

.github/workflows/ci.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: test
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
test:
11+
12+
runs-on: ubuntu-latest
13+
14+
env:
15+
CI: true
16+
TZ: utc
17+
NODE_ENV: test
18+
MYSQL_DB_URL: "mysql://root:[email protected]:3306/orm_test?"
19+
POSTGRES_DB_URL: "postgres://postgres:[email protected]:3306/orm_test?"
20+
REDSHIFT_DB_URL: "redshift://postgres:[email protected]:3306/orm_test?"
21+
SQLITE_DB_URL: "sqlite://?"
22+
23+
strategy:
24+
matrix:
25+
node-version: ['14']
26+
27+
name: test on nodejs ${{ matrix.node-version }}
28+
29+
services:
30+
mysql:
31+
image: mysql:5.7
32+
env:
33+
MYSQL_ROOT_PASSWORD: root
34+
options: >-
35+
--health-cmd="mysqladmin ping"
36+
--health-interval=10s
37+
--health-timeout=5s
38+
--health-retries=3
39+
ports:
40+
- 3306:3306
41+
42+
postgres:
43+
# Docker Hub image
44+
image: postgres
45+
# Set health checks to wait until postgres has started
46+
env:
47+
POSTGRES_PASSWORD: postgres
48+
options: >-
49+
--health-cmd pg_isready
50+
--health-interval 10s
51+
--health-timeout 5s
52+
--health-retries 5
53+
ports:
54+
- 5432:5432
55+
56+
steps:
57+
- name: create mysql DB
58+
run: mysql -uroot -proot -h 127.0.0.1 --port 3306 -e "CREATE DATABASE orm_test CHARACTER SET utf8mb4;"
59+
60+
- name: create postgres DB
61+
run: psql -U postgres -h 127.0.0.1 -c 'create database orm_test;'
62+
env:
63+
PGPASSWORD: postgres
64+
65+
- uses: actions/checkout@v2
66+
67+
- name: install node.js ${{ matrix.node-version }}
68+
uses: actions/setup-node@v2
69+
with:
70+
node-version: ${{ matrix.node-version }}
71+
cache: 'npm'
72+
73+
- uses: bahmutov/npm-install@v1
74+
75+
- name: run tests
76+
run: npm run test
77+
78+
test-success:
79+
name: Tests
80+
if: ${{ always() }}
81+
runs-on: ubuntu-latest
82+
needs: test
83+
steps:
84+
- name: Check build matrix status
85+
if: ${{ needs.test.result != 'success' }}
86+
run: exit 1

.travis.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/common.js

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var common = exports;
22
var path = require('path');
33
var async = require('async');
44
var _ = require('lodash');
5+
var url = require("url");
56
var util = require('util');
67
var querystring = require('querystring');
78
var Semver = require('semver');
@@ -13,8 +14,8 @@ common.protocol = function () {
1314
return process.env.ORM_PROTOCOL;
1415
};
1516

16-
common.isTravis = function() {
17-
return Boolean(process.env.CI);
17+
common.isCI = function() {
18+
return !!process.env.CI;
1819
};
1920

2021
common.createConnection = function(opts, cb) {
@@ -24,7 +25,7 @@ common.createConnection = function(opts, cb) {
2425
common.hasConfig = function (proto) {
2526
var config;
2627

27-
if (common.isTravis()) return 'found';
28+
if (common.isCI()) return 'found';
2829

2930
try {
3031
config = require("./config");
@@ -35,47 +36,47 @@ common.hasConfig = function (proto) {
3536
return (config.hasOwnProperty(proto) ? 'found' : 'not-defined');
3637
};
3738

38-
common.getConfig = function () {
39-
if (common.isTravis()) {
40-
switch (this.protocol()) {
41-
case 'mysql':
42-
return { user: "root", host: "localhost", database: "orm_test" };
43-
case 'postgres':
44-
case 'redshift':
45-
return { user: "postgres", port: 5433, database: "orm_test" };
46-
case 'sqlite':
47-
return {};
48-
case 'mongodb':
49-
return { host: "localhost", database: "test" };
50-
default:
51-
throw new Error("Unknown protocol");
52-
}
53-
} else {
54-
var config = require("./config")[this.protocol()];
55-
if (typeof config == "string") {
56-
config = require("url").parse(config);
57-
}
58-
if (config.hasOwnProperty("auth")) {
59-
if (config.auth.indexOf(":") >= 0) {
60-
config.user = config.auth.substr(0, config.auth.indexOf(":"));
61-
config.password = config.auth.substr(config.auth.indexOf(":") + 1);
62-
} else {
63-
config.user = config.auth;
64-
config.password = "";
65-
}
66-
}
67-
if (config.hostname) {
68-
config.host = config.hostname;
69-
}
39+
common.parseConnectionString = function (connString) {
40+
const config = url.parse(connString);
7041

71-
return config;
42+
if (config.auth) {
43+
if (config.auth.indexOf(":") >= 0) {
44+
config.user = config.auth.substr(0, config.auth.indexOf(":"));
45+
config.password = config.auth.substr(config.auth.indexOf(":") + 1);
46+
} else {
47+
config.user = config.auth;
48+
config.password = "";
49+
}
50+
}
51+
if (config.hostname) {
52+
config.host = config.hostname;
53+
}
54+
if (config.pathname) {
55+
config.database = config.pathname.slice(1);
7256
}
57+
58+
return config;
7359
};
7460

7561
common.getConnectionString = function (opts) {
76-
var config = this.getConfig();
77-
var protocol = this.protocol();
78-
var query;
62+
let protocol = this.protocol();
63+
const dbEnvVar = `${protocol.toUpperCase()}_DB_URL`;
64+
const dbEnvConnString = process.env[dbEnvVar];
65+
66+
let config;
67+
let query;
68+
69+
if (dbEnvConnString) {
70+
config = common.parseConnectionString(dbEnvConnString);
71+
} else {
72+
const testDBConfig = require("./config")[this.protocol()];
73+
74+
if (typeof config == "string") {
75+
config = common.parseConnectionString(testDBConfig);
76+
} else {
77+
config = _.cloneDeep(testDBConfig);
78+
}
79+
}
7980

8081
_.defaults(config, {
8182
user : { postgres: 'postgres', redshift: 'postgres', mongodb: '' }[protocol] || 'root',
@@ -94,10 +95,12 @@ common.getConnectionString = function (opts) {
9495
case 'postgres':
9596
case 'redshift':
9697
case 'mongodb':
97-
if (common.isTravis()) {
98+
if (common.isCI()) {
9899
if (protocol == 'redshift') protocol = 'postgres';
100+
const auth = [config.user, config.password].join(':');
101+
99102
return util.format("%s://%s@%s/%s?%s",
100-
protocol, config.user, config.host, config.database, query
103+
protocol, auth, config.host, config.database, query
101104
);
102105
} else {
103106
return util.format("%s://%s:%s@%s/%s?%s",
@@ -112,6 +115,10 @@ common.getConnectionString = function (opts) {
112115
}
113116
};
114117

118+
common.getConnectionConfig = function (opts) {
119+
return common.parseConnectionString(common.getConnectionString(opts));
120+
}
121+
115122
common.retry = function (before, run, until, done, args) {
116123
if (typeof until === "number") {
117124
var countDown = until;

test/integration/association-hasone-reverse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ describe("hasOne", function () {
222222
should.equal(Array.isArray(pets), true);
223223

224224
// This often fails for sqlite on travis
225-
if (common.isTravis() && common.protocol() != 'sqlite') {
225+
if (common.isCI() && common.protocol() != 'sqlite') {
226226
should.equal(pets.length, 1);
227227
should.equal(pets[0].name, 'Deco');
228228
}

test/integration/orm-exports.js

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ describe("ORM", function() {
182182
});
183183
});
184184

185-
it("should understand pool `'true'` from query string", function () {
185+
it("should understand pool `'1'` from query string", function () {
186186
var connString = connStr + "debug=1&pool=1";
187187
return ORM.connectAsync(connString)
188188
.then(function (db) {
@@ -191,32 +191,36 @@ describe("ORM", function() {
191191
});
192192
});
193193

194-
it("should understand pool `'true'` from query string", function () {
195-
var connCopy = _.cloneDeep(common.getConfig());
196-
var connOpts = _.extend(connCopy, {
197-
protocol: common.protocol(),
198-
query: {
199-
pool: true, debug: true
194+
it("should understand pool `'true'` from connection object", function () {
195+
const config = _.extend(
196+
common.parseConnectionString(connStr),
197+
{
198+
protocol: common.protocol(),
199+
query: {
200+
pool: true, debug: true
201+
}
200202
}
201-
});
203+
);
202204

203-
return ORM.connectAsync(connOpts)
205+
return ORM.connectAsync(config)
204206
.then(function (db) {
205207
should.strictEqual(db.driver.opts.pool, true);
206208
should.strictEqual(db.driver.opts.debug, true);
207209
});
208210
});
209211

210-
it("should understand pool `false` from query options", function () {
211-
var connCopy = _.cloneDeep(common.getConfig());
212-
var connOpts = _.extend(connCopy, {
213-
protocol: common.protocol(),
214-
query: {
215-
pool: false, debug: false
212+
it("should understand pool `false` from connection options", function () {
213+
const config = _.extend(
214+
common.parseConnectionString(connStr),
215+
{
216+
protocol: common.protocol(),
217+
query: {
218+
pool: false, debug: false
219+
}
216220
}
217-
});
221+
);
218222

219-
return ORM.connectAsync(connOpts)
223+
return ORM.connectAsync(config)
220224
.then(function (db) {
221225
should.strictEqual(db.driver.opts.pool, false);
222226
should.strictEqual(db.driver.opts.debug, false);
@@ -362,7 +366,7 @@ describe("ORM", function() {
362366
db.on("connect", function (err) {
363367
should.not.exist(err);
364368

365-
return done();
369+
db.close(done);
366370
});
367371
});
368372

@@ -382,9 +386,7 @@ describe("ORM", function() {
382386
});
383387

384388
it("should be able to ping the server", function (done) {
385-
db.ping(function () {
386-
return done();
387-
});
389+
db.ping(done);
388390
});
389391

390392
it("should be able to pingAsync the server", function () {
@@ -473,31 +475,37 @@ describe("ORM", function() {
473475
});
474476
});
475477

476-
it("should understand pool `true` from query options", function (done) {
477-
var connCopy = _.cloneDeep(common.getConfig());
478-
var connOpts = _.extend(connCopy, {
479-
protocol: common.protocol(),
480-
query: {
481-
pool: true, debug: true
478+
it("should understand pool `true` from connection options", function (done) {
479+
const config = _.extend(
480+
common.parseConnectionString(connStr),
481+
{
482+
protocol: common.protocol(),
483+
query: {
484+
pool: true, debug: true
485+
}
482486
}
483-
});
484-
ORM.connect(connOpts, function (err, db) {
487+
);
488+
489+
ORM.connect(config, function (err, db) {
485490
should.not.exist(err);
486491
should.strictEqual(db.driver.opts.pool, true);
487492
should.strictEqual(db.driver.opts.debug, true);
488493
done();
489494
});
490495
});
491496

492-
it("should understand pool `false` from query options", function (done) {
493-
var connCopy = _.cloneDeep(common.getConfig());
494-
var connOpts = _.extend(connCopy, {
495-
protocol: common.protocol(),
496-
query: {
497-
pool: false, debug: false
497+
it("should understand pool `false` from connection options", function (done) {
498+
const config = _.extend(
499+
common.parseConnectionString(connStr),
500+
{
501+
protocol: common.protocol(),
502+
query: {
503+
pool: false, debug: false
504+
}
498505
}
499-
});
500-
ORM.connect(connOpts, function (err, db) {
506+
);
507+
508+
ORM.connect(config, function (err, db) {
501509
should.not.exist(err);
502510
should.strictEqual(db.driver.opts.pool, false);
503511
should.strictEqual(db.driver.opts.debug, false);

0 commit comments

Comments
 (0)