Skip to content

Commit 6b5ea89

Browse files
committed
chore(testinfra): more postgrest tests & add a TODO
1 parent f6804e2 commit 6b5ea89

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

docker/all-in-one/healthcheck.sh

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ fail2ban-client status
3838
curl -sSfI "http://localhost:$PGEXPORTER_PORT/metrics"
3939

4040
# vector is up (if starting logflare)
41+
# TODO: make this non-conditional once we set up local logflare for testinfra
4142
if [ -n "${LOGFLARE_API_KEY:-}" ]; then
4243
curl -sSfI "http://localhost:$VECTOR_API_PORT/health"
4344
fi

testinfra/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Prerequisites
44

55
```sh
6-
pip3 install docker pytest pytest-testinfra
6+
pip3 install docker pytest pytest-testinfra requests
77
```
88

99
## Running locally

testinfra/test_all_in_one.py

+27-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
from typing import cast
44
import docker
55
import pytest
6+
import requests
67
import subprocess
78
import testinfra
89

910
all_in_one_image_tag = "supabase/all-in-one:testinfra"
1011
all_in_one_envs = {
1112
"POSTGRES_PASSWORD": "postgres",
1213
"JWT_SECRET": "super-secret-jwt-token-with-at-least-32-characters-long",
13-
"ANON_KEY": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJhbm9uIiwKICAgICJpc3MiOiAic3VwYWJhc2UtZGVtbyIsCiAgICAiaWF0IjogMTY0MTc2OTIwMCwKICAgICJleHAiOiAxNzk5NTM1NjAwCn0.dc_X5iR_VP_qT0zsiyj_I_OZ2T9FtRU2BBNWN8Bu4GE",
14-
"SERVICE_ROLE_KEY": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q",
14+
"ANON_KEY": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlzcyI6InN1cGFiYXNlLWRlbW8iLCJpYXQiOjE2NDE3NjkyMDAsImV4cCI6MTc5OTUzNTYwMH0.F_rDxRTPE8OU83L_CNgEGXfmirMXmMMugT29Cvc8ygQ",
15+
"SERVICE_ROLE_KEY": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoic2VydmljZV9yb2xlIiwiaXNzIjoic3VwYWJhc2UtZGVtbyIsImlhdCI6MTY0MTc2OTIwMCwiZXhwIjoxNzk5NTM1NjAwfQ.5z-pJI1qwZg1LE5yavGLqum65WOnnaaI5eZ3V00pLww",
1516
"ADMIN_API_KEY": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoic3VwYWJhc2VfYWRtaW4iLCJpc3MiOiJzdXBhYmFzZS1kZW1vIiwiaWF0IjoxNjQxNzY5MjAwLCJleHAiOjE3OTk1MzU2MDB9.Y9mSNVuTw2TdfryoaqM5wySvwQemGGWfSe9ixcklVfM",
1617
"DATA_VOLUME_MOUNTPOINT": "/data",
1718
"MACHINE_TYPE": "shared_cpu_1x_512m",
@@ -74,6 +75,29 @@ def get_health(container: Container) -> str:
7475
container.remove(v=True, force=True)
7576

7677

77-
def test_postgrest_service(host):
78+
def test_postgrest_is_running(host):
7879
postgrest = host.supervisor("services:postgrest")
7980
assert postgrest.is_running
81+
82+
83+
def test_postgrest_responds_to_requests():
84+
res = requests.get(
85+
"http://localhost:8000/rest/v1/",
86+
headers={
87+
"apikey": all_in_one_envs["ANON_KEY"],
88+
"authorization": f"Bearer {all_in_one_envs['ANON_KEY']}",
89+
},
90+
)
91+
assert res.ok
92+
93+
94+
def test_postgrest_can_connect_to_db():
95+
res = requests.get(
96+
"http://localhost:8000/rest/v1/buckets",
97+
headers={
98+
"apikey": all_in_one_envs["SERVICE_ROLE_KEY"],
99+
"authorization": f"Bearer {all_in_one_envs['SERVICE_ROLE_KEY']}",
100+
"accept-profile": "storage",
101+
},
102+
)
103+
assert res.ok

0 commit comments

Comments
 (0)