mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-10-13 17:49:25 +00:00
PL/pg SQL: add pgTAP test framework support
This commit is contained in:
1 parent
d2588417f5
commit
fbda756d73
3 files changed
+19
-102
No files matched your search
+19
-5
@@ -9,19 +9,33 @@ To use remote / local dockerized database, add ``` --host --port --username```
|
||||
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 ./code/update_quality.sql ```
|
||||
- load code into database: ```psql -d gilded_rose -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.
|
||||
|
||||
# Interactive run
|
||||
# Run
|
||||
In shell:
|
||||
- load test data into database: ```psql -d gilded_rose -f ./test/data/load.sql```
|
||||
- load manual test data into database: ```psql -d gilded_rose -f ./test/manual/load.sql```
|
||||
- connect to CLI: ```psql -d gilded_rose```
|
||||
- check item state: ```SELECT * FROM item;```
|
||||
- execute item update: ```CALL update_quality();```
|
||||
- check item state: ```SELECT * FROM item;```
|
||||
- empty table : ```TRUNCATE TABLE item;```
|
||||
|
||||
|
||||
# Test
|
||||
No test code provided, only a sample of test data
|
||||
TODO: [https://pgtap.org/](introduce TAP - xUnit for PL/pg SQL)
|
||||
|
||||
## Using pgTAP
|
||||
|
||||
### Requirements
|
||||
Install pgTAP [instructions here](https://pgtap.org/documentation.html#installation)
|
||||
|
||||
```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.```
|
||||
|
||||
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.
|
||||
Reference in new issue
Block a user