# Makefile for pg_knoe_auth integration tests (pg_regress style)
# Run with: make installcheck
#
# Prerequisites: PG18 running with pg_knoe_auth loaded, mock_jwks.py running.
# See README.md for full setup instructions.

PGPORT     ?= 5432
PGHOST     ?= localhost
PGUSER     ?= postgres
MOCK_PORT  ?= 9999
MOCK_URL    = http://localhost:$(MOCK_PORT)

# pg_regress test list (order matters — cache tests must run after valid_token)
REGRESS = valid_token \
          expired_token \
          wrong_iss \
          wrong_aud_string \
          wrong_aud_array \
          right_aud_array \
          tampered_sig \
          kid_unknown \
          jwks_unreachable_first_call \
          jwks_unreachable_after_cache

PG_REGRESS = $(shell pg_config --pgxs 2>/dev/null | xargs -I{} dirname {} | xargs -I{} echo {}/../../src/test/regress/pg_regress 2>/dev/null || echo pg_regress)

installcheck: sql/valid_token.sql
	$(PG_REGRESS) \
	    --inputdir=. \
	    --outputdir=results \
	    --host=$(PGHOST) \
	    --port=$(PGPORT) \
	    --user=$(PGUSER) \
	    $(REGRESS)

clean:
	rm -rf results/

.PHONY: installcheck clean
