From 14a0bc7ffe17ebd86ca7a1194f1137f7c1faeea4 Mon Sep 17 00:00:00 2001 From: Brian C Date: Sun, 16 Jul 2017 17:48:38 -0500 Subject: [PATCH] Updated Testing (markdown) --- Testing.md | 57 +----------------------------------------------------- 1 file changed, 1 insertion(+), 56 deletions(-) diff --git a/Testing.md b/Testing.md index 6480b14..23d102b 100644 --- a/Testing.md +++ b/Testing.md @@ -21,59 +21,4 @@ If you're manually managing your own __Client__ instances without using __pg__ t client.on('drain', client.end.bind(client)); //auto disconnect client after last query ends ``` -_Note: as mentioned other places...do not create a new client instance for each http request you receive. You **will** exhaust available connections to your PostgreSQL server and you **will** be sorry._ - -# Internal Testing of node-postgres -In case you want to contribute.... - -## Unit tests - -Unit tests do not depend on having access to a running PostgreSQL server. They run in memory by stubbing out the layer below the object under test. If the [[Client]] object is being tests, the lower level [[Connection]] object is stubbed out and controlled within the test. This allows to simulate specifically timed error events and more complex interactions between the [[Client]] and the [[Connection]] such as when executing a [[Prepared Statement|Prepared-Statements]]. All unit test files exist under `test/unit/` and by convention end with `-tests.js`. They can be executed either by `make test`, `make test-unit`, or `npm test pg` - -## Integration tests - -The integration tests operate on an actual PostgreSQL server instance. You can supply credentials via a quick and dirty command line option parser which is executed before any test is run. Also, the integration tests require populating your database with some test data. The script is located at `node-postgres/script/create-test-tables.js`. All integration tests files exist under `test/integration/` and by convention end with `-tests.js`. Further instructions below... - -## Running tests - -You can run any test file directly by doing the `node test/unit/connection/inbound-parser-tests.js` or something of the like. - -However, you can specify command line arguments after the file and they will be picked up and used in the tests. None of the arguments are used in _unit_ tests since they have no external dependencies, so you're safe to just blast away with the command like above, but if you'd like to execute an _integration_ test, you should specify the database and user to use for testing, and optionally a password. - -To do so you would do something like so: - - node test/integration/client/simple-query-tests.js pg://user:password@host:port/databaseName - -If you'd like to execute all the unit or integration tests at one time, you can do so with the `Makefile`. - -## Makefile -The make file is used as a shortcut to running all the tests. Since many of the integration tests slam the database with load/connection-pool based testing, the tests are executed sequentially file-by-file. This ensures each file finishes before the next begins, reduces test complexity, and raises test isolation. The command line parameters passed to individual test files can be passed to the Makefile which will in turn pass them along to each test file. - -### Run all unit tests - - make test-unit - -or optionally, since `test-unit` is the default: - -_(Note: This means integration tests under `test/integration` do **not** run with the default Makefile task)_ - - make test - -### Run all integration tests - - make test-integration connectionString=pg://user:password@host:port/databaseName - -### Run all the tests! (unit, integration, native, and binary) - - make test-all connectionString=pg://user:password@host:port/databaseName - -In short, I tried to make executing the tests as easy as possible. Hopefully this will encourage you to fork, hack, and do whatever you please as you've got a nice, big safety net under you. - -### Test data - -In order for the integration tests to not take ages to run, I've pulled out the script used to generate test data. This way you can generate a "test" database once and don't have to up/down the tables every time an integration test runs. To run the generation script, execute the script with the same command ine arguments passed to any other test script. - - node script/create-test-tables.js pg://user:password@host:port/databaseName - -*** -[[◄ Back (Query Queue)|Queryqueue]] ` ` [[Next (Todo) ►|Todo]] \ No newline at end of file +_Note: as mentioned other places...do not create a new client instance for each http request you receive. You **will** exhaust available connections to your PostgreSQL server and you **will** be sorry._ \ No newline at end of file