Created
September 21, 2016 03:17
-
-
Save rgwozdz/efc31e87652b7a7dc246527a77bed9dd to your computer and use it in GitHub Desktop.
Psuedo Ansible Playbook for API/DB integration testing - Mocha.js, Express.js, PostgreSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: Run DB/API integration test suite | |
hosts: localhost | |
become: True | |
become_method: sudo | |
tasks: | |
- name: Use PSQL to Close Postgres DB connection to the master database | |
become: True | |
become_user: postgres | |
shell: psql -U postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND datname = '<master-db-name>';" | |
ignore_errors: True | |
- name: Delete integration test database (last copy of master), if it exists | |
postgresql_db: | |
name: <integration-test-db-name> | |
state: absent | |
login_password: "{{ postgres_user_password }}" | |
become_user: postgres | |
ignore_errors: True | |
- name: Create the new integration test DB, using the master DB as a template | |
postgresql_db: | |
name: <integration-test-db-name> | |
state: present | |
template: "<master-db-name>" | |
login_password: "{{ postgres_user_password }}" | |
become_user: postgres | |
- name: Execute SQL scripts integration database that truncate/insert data and provide a "known-state" | |
become: True | |
become_user: postgres | |
shell: psql -U postgres -d to_app_integration_tests -q -f /home/postgres/integration-test-setup.sql | |
register: shell_output | |
- name: Search the stderr for PSQL errors, and exit if any found | |
fail: msg="THERE WAS A PSQL ERROR" | |
when: '"ERROR" in shell_output.stderr' | |
- name: Execute Mocha.js Integration Tests | |
shell: (cd /path/to/your/api/installation && mocha ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment