From a57022e13cce47745181ed5af42adebd1380a537 Mon Sep 17 00:00:00 2001 From: fpellet Date: Sun, 19 Jan 2020 21:35:26 +0100 Subject: [PATCH] merge readme files --- plpgsql/README.md | 41 ++++++++++++++++++++++++++++++---------- plpgsql/pgunit/readme.md | 10 ---------- 2 files changed, 31 insertions(+), 20 deletions(-) delete mode 100644 plpgsql/pgunit/readme.md diff --git a/plpgsql/README.md b/plpgsql/README.md index 4ba245c2..984821f1 100644 --- a/plpgsql/README.md +++ b/plpgsql/README.md @@ -6,36 +6,57 @@ You'll need: To use remote / local dockerized database, add ``` --host --port --username``` parameters to plsql invocation. # Setup +## With docker +Run `docker-compose up -d ` to start, and `docker-compose exec bash` to enter in container. +`` is the testing framework name. Two values are possible: `pgunit` or `pgtap` + +## Without docker In shell: -- create database: ```createdb gilded_rose``` -- create item table (structure): ```psql -d gilded_rose -f ./structure/create.sql``` -- load code into database: ```psql -d gilded_rose -f ./src/update_quality.sql ``` +- create database: ```createdb kata``` +- create item table (structure): ```psql -d kata -f ./src/item.sql``` +- create procedure to help to add item: ```psql -d kata -f ./src/new_item.sql``` +- load code into database: ```psql -d kata -f ./src/update_quality.sql ``` If you get this message```LINE 1: CREATE OR REPLACE PROCEDURE public.update_quality()```, your PostgreSQL version may under 11, consider upgrading. -# Run +# Run In shell: -- load manual test data into database: ```psql -d gilded_rose -f ./test/manual/load.sql``` -- connect to CLI: ```psql -d gilded_rose``` +- connect to CLI: ```psql -d kata``` +- add item: ```CALL new_item('+5 Dexterity Vest', 10, 20);``` - check item state: ```SELECT * FROM item;``` - execute item update: ```CALL update_quality();``` - check item state: ```SELECT * FROM item;``` - empty table : ```TRUNCATE TABLE item;``` +# Kata +`src/update_quality.sql` contains code to refactor. # Test ## Using pgTAP - ### Requirements -Install pgTAP [instructions here](https://pgtap.org/documentation.html#installation) +Install pgTAP [instructions here](https://pgtap.org/documentation.html#installation) +It's already installed with docker ```item``` table is supposed to be empty. If not, it would cause a (false positive)[https://en.wikipedia.org/wiki/False_positives_and_false_negatives] ### Execute -In shell, execute ```pg_prove --dbname gilded_rose test/pgtap/*.sql```. -You should get ```test/pgtap/template.sql .. ok All tests successful.``` +In shell, execute ```psql -d kata -f src/update_quality.sql && pg_prove pgtap/test_*.sql```. +You should get ```pgtap/test_case_update_quality.sql .. ok All tests successful.``` If you get this message ```ERROR: function plan(integer) does not exist LINE 1: SELECT PLAN(1);```, pgTAP is not working => check your pgTAP installation. If you get this message ```Failed test: 2 Parse errors: Bad plan. You planned 1 tests but ran 2.```, the item table contains data, interfering with the test => empty it, then run test again. + +`pgtap/test_case_update_quality.sql` contains test examples. + +## Using pgunit +### Requirement +Unit test framework used : pgunit (https://github.com/adrianandrei-ca/pgunit) +It's already installed with docker + +### Execute +Run `docker-compose up -d pgunit` to start, and `docker-compose exec pgunit bash` to enter in container. +You can run `cat src/update_quality.sql pgunit/run_tests.sql | psql -d kata -f -` + +`pgunit/run_tests.sql` contains test examples. diff --git a/plpgsql/pgunit/readme.md b/plpgsql/pgunit/readme.md deleted file mode 100644 index 6421ed1c..00000000 --- a/plpgsql/pgunit/readme.md +++ /dev/null @@ -1,10 +0,0 @@ -## Requirement -Testing on postgres 12 -Unit test framework used : pgunit (https://github.com/adrianandrei-ca/pgunit) - -## Setup -Run `docker-compose up -d` to start, and `docker-compose exec database bash` to enter in container. -You can run `cat update_quality.sql run_tests.sql | psql -d kata -f -` - -## Kata -`update_quality.sql` contains code to refactor, and `run_tests.sql` contains test examples.