Skip to content

Commit

Permalink
Simplify configuration for tests to match Sails v1 conventions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikermcneil committed Feb 23, 2017
1 parent 4a25aff commit ed7f025
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 16 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ Please observe the guidelines and conventions laid out in the [Sails project con
[![NPM](https://nodei.co/npm/sails-mysql.png?downloads=true)](http://npmjs.com/package/sails-mysql)


#### Running the tests

To run the tests, point this adapter at your database by specifying connection URL and then use `npm test`:

```
WATERLINE_ADAPTER_TESTS_URL=mysql://root:myc00lP4ssw0rD@localhost/adapter_tests npm test
```

> For more info, see [**Reference > Configuration > sails.config.datastores > The connection URL**](http://sailsjs.com/documentation/reference/configuration/sails-config-datastores#?the-connection-url), or [ask for help](http://sailsjs.com/support).
## License

The [Sails framework](http://sailsjs.com) is free and open-source under the [MIT License](http://sailsjs.com/license).
This adapter, like the [Sails framework](http://sailsjs.com) is free and open-source under the [MIT License](http://sailsjs.com/license).

32 changes: 24 additions & 8 deletions test/adapter/integration/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,30 @@ new TestRunner({
adapter: Adapter,

// Default connection config to use.
config: {
host: process.env.MYSQL_PORT_3306_TCP_ADDR || process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost',
port: process.env.WATERLINE_ADAPTER_TESTS_PORT || 3306,
user: process.env.MYSQL_ENV_MYSQL_USER || process.env.WATERLINE_ADAPTER_TESTS_USER || 'root',
password: process.env.MYSQL_ENV_MYSQL_PASSWORD || process.env.WATERLINE_ADAPTER_TESTS_PASSWORD || process.env.MYSQL_PWD || '',
database: process.env.MYSQL_ENV_MYSQL_DATABASE || process.env.WATERLINE_ADAPTER_TESTS_DATABASE || 'adapter_tests',
schema: true
},
config: (function(){
var config = {
schema: true,
};

if (process.env.WATERLINE_ADAPTER_TESTS_URL) {
config.url = process.env.WATERLINE_ADAPTER_TESTS_URL;
return config;
}//‡-•
else if (process.env.MYSQL_PORT_3306_TCP_ADDR || process.env.WATERLINE_ADAPTER_TESTS_HOST || process.env.WATERLINE_ADAPTER_TESTS_PORT || process.env.MYSQL_ENV_MYSQL_USER || process.env.WATERLINE_ADAPTER_TESTS_USER || process.env.MYSQL_ENV_MYSQL_PASSWORD || process.env.WATERLINE_ADAPTER_TESTS_PASSWORD || process.env.MYSQL_PWD || process.env.MYSQL_ENV_MYSQL_DATABASE || process.env.WATERLINE_ADAPTER_TESTS_DATABASE) {
console.warn('Traditional env vars for configuring WAT (waterline adapter tests) are no longer supported. Instead, please use the `WATERLINE_ADAPTER_TESTS_URL` env var to specify a connection URL (e.g. `WATERLINE_ADAPTER_TESTS_URL=mysql://root@localhost:1337/adapter_tests npm test`). See **Reference > Configuration > sails.config.datastores** in the Sails docs for more information and examples on using connection URLs.');
console.warn('(Trying to make it work for you this time...)');
config.host = process.env.MYSQL_PORT_3306_TCP_ADDR || process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost';
config.port = process.env.WATERLINE_ADAPTER_TESTS_PORT || 3306;
config.user = process.env.MYSQL_ENV_MYSQL_USER || process.env.WATERLINE_ADAPTER_TESTS_USER || 'root';
config.password = process.env.MYSQL_ENV_MYSQL_PASSWORD || process.env.WATERLINE_ADAPTER_TESTS_PASSWORD || process.env.MYSQL_PWD || '';
config.database = process.env.MYSQL_ENV_MYSQL_DATABASE || process.env.WATERLINE_ADAPTER_TESTS_DATABASE || 'adapter_tests';
return config;
}//‡-•
else {
throw new Error('Please use the `WATERLINE_ADAPTER_TESTS_URL` env var to specify a connection URL (e.g. `WATERLINE_ADAPTER_TESTS_URL=mysql://root@localhost:1337/adapter_tests npm test`). See **Reference > Configuration > sails.config.datastores** in the Sails docs for more information and examples on using connection URLs.');
}

})(),

failOnError: true,
// The set of adapter interfaces to test against.
Expand Down
34 changes: 27 additions & 7 deletions test/support/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,33 @@ var adapter = require('../../lib/adapter');

var Support = module.exports = {};

Support.Config = {
host: process.env.MYSQL_PORT_3306_TCP_ADDR || process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost',
port: process.env.WATERLINE_ADAPTER_TESTS_PORT || 3306,
user: process.env.MYSQL_ENV_MYSQL_USER || process.env.WATERLINE_ADAPTER_TESTS_USER || 'root',
password: process.env.MYSQL_ENV_MYSQL_PASSWORD || process.env.WATERLINE_ADAPTER_TESTS_PASSWORD || process.env.MYSQL_PWD || '',
database: process.env.MYSQL_ENV_MYSQL_DATABASE || process.env.WATERLINE_ADAPTER_TESTS_DATABASE || 'adapter_tests'
};
// Determine config (using env vars).
Support.Config = (function(){
var config = {
schema: true,
};

if (process.env.WATERLINE_ADAPTER_TESTS_URL) {
config.url = process.env.WATERLINE_ADAPTER_TESTS_URL;
return config;
}//‡-•
else if (process.env.MYSQL_PORT_3306_TCP_ADDR || process.env.WATERLINE_ADAPTER_TESTS_HOST || process.env.WATERLINE_ADAPTER_TESTS_PORT || process.env.MYSQL_ENV_MYSQL_USER || process.env.WATERLINE_ADAPTER_TESTS_USER || process.env.MYSQL_ENV_MYSQL_PASSWORD || process.env.WATERLINE_ADAPTER_TESTS_PASSWORD || process.env.MYSQL_PWD || process.env.MYSQL_ENV_MYSQL_DATABASE || process.env.WATERLINE_ADAPTER_TESTS_DATABASE) {
console.warn();
console.warn('Traditional env vars for configuring WAT (waterline adapter tests) are no longer supported. Instead, please use the `WATERLINE_ADAPTER_TESTS_URL` env var to specify a connection URL (e.g. `WATERLINE_ADAPTER_TESTS_URL=mysql://root@localhost:1337/adapter_tests npm test`). See **Reference > Configuration > sails.config.datastores** in the Sails docs for more information and examples on using connection URLs.');
console.warn('(Trying to make it work for you this time...)');
console.warn();
config.host = process.env.MYSQL_PORT_3306_TCP_ADDR || process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost';
config.port = process.env.WATERLINE_ADAPTER_TESTS_PORT || 3306;
config.user = process.env.MYSQL_ENV_MYSQL_USER || process.env.WATERLINE_ADAPTER_TESTS_USER || 'root';
config.password = process.env.MYSQL_ENV_MYSQL_PASSWORD || process.env.WATERLINE_ADAPTER_TESTS_PASSWORD || process.env.MYSQL_PWD || '';
config.database = process.env.MYSQL_ENV_MYSQL_DATABASE || process.env.WATERLINE_ADAPTER_TESTS_DATABASE || 'adapter_tests';
return config;
}//‡-•
else {
throw new Error('Please use the `WATERLINE_ADAPTER_TESTS_URL` env var to specify a connection URL (e.g. `WATERLINE_ADAPTER_TESTS_URL=mysql://root@localhost:1337/adapter_tests npm test`). See **Reference > Configuration > sails.config.datastores** in the Sails docs for more information and examples on using connection URLs.');
}

})();

// Fixture Model Def
Support.Model = function model(name, def) {
Expand Down

0 comments on commit ed7f025

Please sign in to comment.