add unittests for not matching environment

pull/324/head
Rizky Maulana Nugraha 2021-08-18 23:25:42 +00:00 zatwierdzone przez GitHub
rodzic b04d3f8a26
commit ce208079ed
3 zmienionych plików z 25 dodań i 4 usunięć

Wyświetl plik

@ -112,7 +112,7 @@ services:
- ./tests:/tests
- ../utils:/lib/utils
environment:
TEST_CLASS: TestCustomWALdir
TEST_CLASS: TestCustomWALdirNotMatch
DATADIR: /opt/mypostgis/data
POSTGRES_INITDB_WALDIR: /opt/waldir
POSTGRES_PASS: 'docker'
@ -132,7 +132,7 @@ services:
- ./tests:/tests
- ../utils:/lib/utils
environment:
TEST_CLASS: TestCustomWALdir
TEST_CLASS: TestCustomWALdirNotMatch
DATADIR: /opt/mypostgis/data
POSTGRES_INITDB_WALDIR: /opt/waldir
POSTGRES_PASS: 'docker'

Wyświetl plik

@ -101,7 +101,7 @@ sleep 60
warning_text="Can't proceed because \"/opt/mypostgis/data/pg_wal\" directory is empty."
while true; do
if [[ -n "$(docker-compose logs $service | grep 'Error')" && \
-n "$(docker-compose logs $service | grep \"$warning_text\")" ]]; then
-n "$(docker-compose logs $service | grep "$warning_text")" ]]; then
break
fi
sleep 5

Wyświetl plik

@ -88,5 +88,26 @@ class TestCustomWALdir(TestCollationBase):
with self.db.cursor() as c:
datadir_location = self.fetch_datadir_location(c)
pg_wal_symlink = os.path.join(datadir_location, 'pg_wal')
# In this correct setup, pg_wal symlink must resolve to the
# correct POSTGRES_INITDB_WALDIR location
self.assertTrue(
Path(pg_wal_symlink).resolve().match(postgres_initdb_waldir))
class TestCustomWALdirNotMatch(TestCollationBase):
def test_check_pg_wal_symlink(self):
self.db.conn.autocommit = True
postgres_initdb_waldir = os.environ.get('POSTGRES_INITDB_WALDIR')
with self.db.cursor() as c:
datadir_location = self.fetch_datadir_location(c)
pg_wal_symlink = os.path.join(datadir_location, 'pg_wal')
# In this wrong setup, pg_wal symlink and POSTGRES_INITDB_WALDIR
# must resolve to a different path to raise the warning
self.assertFalse(
Path(pg_wal_symlink).resolve().match(postgres_initdb_waldir))
# It has different path, but if this unittests runs, that means
# postgres was able to start and the pg_wal symlink contains correct
# data
self.assertTrue(os.listdir(pg_wal_symlink))