/**
 * Test for view monitoring_follower_wal_status
 *
 * NOTE: This view is only working on a follower node, on a primary it will
 * throw an error
 *
 * Every test does raise division by zero if it failes
 *
 * @author: "Stefanie Janine Stölting"<stefanie@proopensource.eu>
 * @license: PostgreSQL https://opensource.org/licenses/postgresql
 */

-- Test if the function exists
WITH test AS
	(
		SELECT COUNT(*) AS exist
			, 0 AS zero
		FROM pg_catalog.pg_views
		WHERE viewname = 'monitoring_follower_wal_status'
	)
SELECT
	CASE
		WHEN 1 / test.exist = 1 THEN
			TRUE
		ELSE
			(1 / zero)::BOOLEAN
	END AS res
FROM test
;

/** Testing the view is not done as it would only work on a follower
-- Test if the view runs without errors
SELECT *
FROM monitoring_follower_wal_status
;
*/
