-
Notifications
You must be signed in to change notification settings - Fork 23
assert.pass
binodnp edited this page Aug 14, 2014
·
6 revisions
Indicates that a test has passed a condition. Unline assert.ok
, there can be several assert.pass
on a test function.
#Example 1
This example contains multiple pass assertions. The test fails if the database was not vacuumed and analyzed in the last 24 hours.
DROP FUNCTION IF EXISTS unit_tests.assert_fail_example4();
CREATE FUNCTION unit_tests.assert_pass_example()
RETURNS test_result
AS
$$
DECLARE message test_result;
BEGIN
IF EXISTS(SELECT MAX(last_vacuum) FROM pg_stat_user_tables HAVING MAX(last_vacuum) > NOW() - interval '24 hours') THEN
SELECT assert.pass('Passed: vacuum was run in the last 24 hours.');
ELSE
SELECT assert.fail('Vacuum was not run since last 24 hours.') INTO message;
RETURN message;
END IF;
IF EXISTS(SELECT MAX(last_analyze) FROM pg_stat_user_tables HAVING MAX(last_analyze) > NOW() - interval '24 hours') THEN
SELECT assert.pass('Passed: database was analyzed in the last 24 hours.');
ELSE
SELECT assert.fail('Analyze was not run since last 24 hours.') INTO message;
RETURN message;
END IF;
SELECT assert.ok('End of test.') INTO message;
RETURN message;
END
$$
LANGUAGE plpgsql;
/*Use transaction if your test contains DML query.*/
--BEGIN TRANSACTION;
SELECT * FROM unit_tests.begin();
--ROLLBACK TRANSACTION;
##See Also assert.ok(text) assert.fail(text)