I want to test functions of my PostgresSQL database and for this I use the DBFit Framework. In my tests I change values of columns of my tables and I now want a comparison between the OriginalRuntime (before I execute the function) and the UpdatedRuntime (after I execute the function).
Here is an example: In my original table the runtime of contracts is in months. My function multiplies each value of the column by a factor of 30 and overwrites the values of the column so that in the Updated table all values are displayed in days instead of months.
This is my function in Postgres:
CREATE OR REPLACE FUNCTION multiply_and_update_runtime()
RETURNS VOID AS
$$
BEGIN
UPDATE my_table
SET runtime = runtime * 30;
END;
$$
LANGUAGE plpgsql;
In DBFit I tried to write two queries and save the original value before I executed the function and then compare it with the updated value after I executed the function.
!|Store Query|Select laufzeit from my_table where some_attribute = 1003|OriginalRuntime|
!|Execute Procedure|multiply_and_update_runtime|
!|Store Query|Select laufzeit from my_table where some_attribute = 1003|UpdatedRuntime|
!|Compare Stored Queries|OriginalRuntime|UpdatedRuntime|
|36|1080|
My result should be: OriginalRuntime = 36; UpdatedRuntime = 1080 and the test should be green in DBFit.