Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing guide #1584

Merged
merged 25 commits into from
May 14, 2021
Merged

Testing guide #1584

merged 25 commits into from
May 14, 2021

Conversation

molebox
Copy link
Contributor

@molebox molebox commented Apr 20, 2021

This PR create sa new Testing guide section which has 2 new pages:

  • Unit tetsing
  • Integration testing

The Unit testing page covers why and when to unit test as well as mocking the client using a singleton and depencency injection patterns, plus a couple of examples of actual unit test.

The Integration testing page covers setting up and using Docker to house a database to test against. It also includes soem examples of integration tests.

Fixes: #1293
Fixes: 5014

@molebox molebox marked this pull request as draft April 20, 2021 12:08
@molebox molebox marked this pull request as ready for review May 3, 2021 07:55
@mhwelander
Copy link
Contributor

💯 Added some comments and suggestions, I really like the general explanation followed by a concrete example!

@mhwelander mhwelander added the docs Documentation creation, updates or corrections label May 6, 2021
The `docker-compose.yml` file defines the following:

- The Postgres image (`postgres`) and version tag (`:13`). This will be downloaded if you do not have it locally available.
- The port `5433` is mapped to the internal (Postgres default) port `5432`. This will be the port number the database is exposed on externally.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not mapping both to 5432?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had issues with this and found that chaging the port solved it. I was going to document that but i cant find the reason why it didnt work. I though people might ask that exact question though....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it only helps if you already have a PostgreSQL database service started locally, Then the 5432 port is already occupied and Docker cannot use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh. Hmm. But i dont have anything else running on that port, i checked. Lemme double check again now and change port. It would make much more sense to map to the same port as thats what people expect too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it doesnt work for me. I cant authenticate

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker compose logs probably show something about the port if it's already used / cannot be used

Copy link
Contributor Author

@molebox molebox May 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, not that i can see at least

$ docker-compose logs -f -t
Attaching to integration-tests-prisma
integration-tests-prisma | 2021-05-12T09:27:28.866263300Z The files belonging to this database system will be owned by user "postgres".
integration-tests-prisma | 2021-05-12T09:27:28.866310600Z This user must also own the server process.
integration-tests-prisma | 2021-05-12T09:27:28.866314000Z
integration-tests-prisma | 2021-05-12T09:27:28.866316600Z The database cluster will be initialized with locale "en_US.utf8".
integration-tests-prisma | 2021-05-12T09:27:28.866319000Z The default database encoding has accordingly been set to "UTF8".
integration-tests-prisma | 2021-05-12T09:27:28.866321400Z The default text search configuration will be set to "english".
integration-tests-prisma | 2021-05-12T09:27:28.866323500Z
integration-tests-prisma | 2021-05-12T09:27:28.866325500Z Data page checksums are disabled.
integration-tests-prisma | 2021-05-12T09:27:28.866327500Z
integration-tests-prisma | 2021-05-12T09:27:28.866329400Z fixing permissions on existing directory /var/lib/postgresql/data ... ok
integration-tests-prisma | 2021-05-12T09:27:28.867173800Z creating subdirectories ... ok
integration-tests-prisma | 2021-05-12T09:27:28.867261600Z selecting dynamic shared memory implementation ... posix
integration-tests-prisma | 2021-05-12T09:27:28.878419700Z selecting default max_connections ... 100
integration-tests-prisma | 2021-05-12T09:27:28.892358200Z selecting default shared_buffers ... 128MB
integration-tests-prisma | 2021-05-12T09:27:28.906787900Z selecting default time zone ... Etc/UTC
integration-tests-prisma | 2021-05-12T09:27:28.908146800Z creating configuration files ... ok
integration-tests-prisma | 2021-05-12T09:27:29.018818300Z running bootstrap script ... ok
integration-tests-prisma | 2021-05-12T09:27:29.350018100Z performing post-bootstrap initialization ... ok
integration-tests-prisma | 2021-05-12T09:27:29.685673500Z syncing data to disk ... ok
integration-tests-prisma | 2021-05-12T09:27:29.685710500Z
integration-tests-prisma | 2021-05-12T09:27:29.685714600Z
integration-tests-prisma | 2021-05-12T09:27:29.685717100Z Success. You can now start the database server using:
integration-tests-prisma | 2021-05-12T09:27:29.685719400Z
integration-tests-prisma | 2021-05-12T09:27:29.685721500Z     pg_ctl -D /var/lib/postgresql/data -l logfile start
integration-tests-prisma | 2021-05-12T09:27:29.685723700Z
integration-tests-prisma | 2021-05-12T09:27:29.685676500Z initdb: warning: enabling "trust" authentication for local connections
integration-tests-prisma | 2021-05-12T09:27:29.685731400Z You can change this by editing pg_hba.conf or using the option -A, or
integration-tests-prisma | 2021-05-12T09:27:29.685733500Z --auth-local and --auth-host, the next time you run initdb.
integration-tests-prisma | 2021-05-12T09:27:29.720693100Z waiting for server to start....2021-05-12 09:27:29.720 UTC [47] LOG:  starting PostgreSQL 13.2 (Debian 13.2-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
integration-tests-prisma | 2021-05-12T09:27:29.727427800Z 2021-05-12 09:27:29.727 UTC [47] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
integration-tests-prisma | 2021-05-12T09:27:29.750927700Z 2021-05-12 09:27:29.750 UTC [48] LOG:  database system was shut down at 2021-05-12 09:27:29 UTC
integration-tests-prisma | 2021-05-12T09:27:29.759384400Z 2021-05-12 09:27:29.759 UTC [47] LOG:  database system is ready to accept connections
integration-tests-prisma | 2021-05-12T09:27:29.794525900Z  done
integration-tests-prisma | 2021-05-12T09:27:29.794544600Z server started
integration-tests-prisma | 2021-05-12T09:27:30.064517200Z CREATE DATABASE
integration-tests-prisma | 2021-05-12T09:27:30.065018600Z
integration-tests-prisma | 2021-05-12T09:27:30.065259400Z
integration-tests-prisma | 2021-05-12T09:27:30.065299300Z /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
integration-tests-prisma | 2021-05-12T09:27:30.065302600Z
integration-tests-prisma | 2021-05-12T09:27:30.066200200Z 2021-05-12 09:27:30.066 UTC [47] LOG:  received fast shutdown request
integration-tests-prisma | 2021-05-12T09:27:30.073528400Z waiting for server to shut down....2021-05-12 09:27:30.073 UTC [47] LOG:  aborting any active transactions
integration-tests-prisma | 2021-05-12T09:27:30.074529600Z 2021-05-12 09:27:30.074 UTC [47] LOG:  background worker "logical replication launcher" (PID 54) exited with exit code 1
integration-tests-prisma | 2021-05-12T09:27:30.074697000Z 2021-05-12 09:27:30.074 UTC [49] LOG:  shutting down
integration-tests-prisma | 2021-05-12T09:27:30.116218600Z 2021-05-12 09:27:30.116 UTC [47] LOG:  database system is shut down
integration-tests-prisma | 2021-05-12T09:27:30.166455500Z  done
integration-tests-prisma | 2021-05-12T09:27:30.166491000Z server stopped
integration-tests-prisma | 2021-05-12T09:27:30.166639300Z
integration-tests-prisma | 2021-05-12T09:27:30.166648100Z PostgreSQL init process complete; ready for start up.
integration-tests-prisma | 2021-05-12T09:27:30.166650900Z
integration-tests-prisma | 2021-05-12T09:27:30.194092700Z 2021-05-12 09:27:30.193 UTC [1] LOG:  starting PostgreSQL 13.2 (Debian 13.2-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
integration-tests-prisma | 2021-05-12T09:27:30.194232400Z 2021-05-12 09:27:30.194 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
integration-tests-prisma | 2021-05-12T09:27:30.194335400Z 2021-05-12 09:27:30.194 UTC [1] LOG:  listening on IPv6 address "::", port 5432
integration-tests-prisma | 2021-05-12T09:27:30.208729200Z 2021-05-12 09:27:30.208 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
integration-tests-prisma | 2021-05-12T09:27:30.224341600Z 2021-05-12 09:27:30.224 UTC [75] LOG:  database system was shut down at 2021-05-12 09:27:30 UTC
integration-tests-prisma | 2021-05-12T09:27:30.234287700Z 2021-05-12 09:27:30.234 UTC [1] LOG:  database system is ready to accept connections

@molebox molebox merged commit 05a9564 into main May 14, 2021
@molebox molebox deleted the testing-guide branch May 14, 2021 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation creation, updates or corrections
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Testing guide Docs: Testing with Jest and Jest.Mock
3 participants