Skip to content

Latest commit

 

History

History

test

sql-client Unit Tests

This directory contains automated tests for the sql-client module.

These tests can be executed by running:

make test

(or make clean test, for good measure) from this module's root directory.

A test coverage report can be generated by running:

make coverage

(or make clean coverage) from that same directory.

While you can run this test suite without any external (non-Node.js-related) dependencies, several of the database-specific tests require an actual database instance to test against.

When you run this suite, those tests that require an external database will be skipped if the database is not accessible.

(When this happens, a prominent warning is printed to STDERR, directing you to this file.)

To set up the test database(s) and enable the tests, follow the instructions below.

PostgreSQL

To test the PostgreSQLClient classes, you'll need to create a user and database within an accessible instance of PostgreSQL.

Specifically, you'll need to create the account sqlclient_test_user and database sqclient_test_db in a local database instance. (More generally, the database to connect to is specified by the CONNECT_STRING variable defined in test-postgresql-client.coffee.)

Assuming you have a local instance of PostgreSQL running on the default port, you can create this account by running:

sudo su postgres -c "psql -Upostgres -f  ./test/create-postgresql-test-db.sql"

or, alternatively, something like:

psql -U<YOUR-USERNAME> -dpostgres -f  ./test/create-postgresql-test-db.sql

(if the postgres user is not recognized).

This will execute the create-postgresql-test-db.sql script.

Should you want to remove this test user and database, you can run:

sudo su postgres -c "psql -Upostgres -f  ./test/drop-postgresql-test-db.sql"

or:

psql -U<YOUR-USERNAME> -dpostgres -f  ./test/drop-postgresql-test-db.sql

which will execute the drop-postgresql-test-db.sql script.

MySQL

To test the MySQLClient classes, you'll need to create a user and database within an accessible instance of MySQL.

Specifically, you'll need to create the account sqlclient_test_u and database sqlclient_test_db in a local database instance. (More generally, the database to connect to is specified by the CONNECT_OPTS variable defined in test-mysql-client.coffee.)

Assuming you have a local instance of MySQL running you can create this account by running:

mysql -u root -p < ./test/create-mysql-test-db.sql

which will execute the create-mysql-test-db.sql script.

Should you want to remove this test user and database, you can run:

mysql -u root -p < ./test/drop-mysql-test-db.sql

which will execute the drop-mysql-test-db.sql script.

SQLite3

The SQLite tests use a transient, in-memory database. No other configuration is needed.