Skip to content

Commit

Permalink
Fix unit tests, handle missing git version details when running make
Browse files Browse the repository at this point in the history
  • Loading branch information
rustprooflabs committed Nov 22, 2023
1 parent b64e63f commit b4a709b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
10 changes: 9 additions & 1 deletion docker/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,22 @@ def get_git_info(tag_only: bool=False) -> str:
git_info : str
"""
logger = logging.getLogger('pgosm-flex')
repo = git.Repo()

try:
repo = git.Repo()
except git.exc.InvalidGitRepositoryError:
# This error happens when running via make for some reason...
# This appears to fix it.
repo = git.Repo('../')

try:
sha = repo.head.object.hexsha
short_sha = repo.git.rev_parse(sha, short=True)
latest_tag = repo.git.describe('--abbrev=0', tags=True)
except ValueError:
git_info = 'Git info unavailable'
logger.error('Unable to get git information.')
return '-- (version unknown) --'

if tag_only:
git_info = latest_tag
Expand Down
7 changes: 6 additions & 1 deletion docker/import_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ def okay_to_run(self, prior_import: dict) -> bool:
# If current version is lower than prior version from latest import, stop.
prior_import_version = prior_import['pgosm_flex_version_no_hash']
git_tag = helpers.get_git_info(tag_only=True)
if parse_version(git_tag) < parse_version(prior_import_version):

if git_tag == '-- (version unknown) --':
msg = 'Unable to detect PgOSM Flex version from Git.'
msg += ' Not enforcing version check against prior version.'
self.logger.warning(msg)
elif parse_version(git_tag) < parse_version(prior_import_version):
msg = f'PgOSM Flex version ({git_tag}) is lower than latest import'
msg += f' tracked in the pgosm_flex table ({prior_import_version}).'
msg += f' Use PgOSM Flex version {prior_import_version} or newer'
Expand Down
12 changes: 9 additions & 3 deletions docker/tests/test_import_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def test_import_mode_okay_to_run_returns_false_when_prior_record_not_replication
This should return False to avoid overwriting data.
"""
replication = True
prior_import = {'replication': False}
prior_import = {'replication': False,
'pgosm_flex_version_no_hash': '99.99.99'
}
replication_update = False
update = None
force = False
Expand All @@ -170,7 +172,9 @@ def test_import_mode_okay_to_run_returns_true_when_replication_prior_record_repl
This should return True to allow replication to updated
"""
replication = True
prior_import = {'replication': True}
prior_import = {'replication': True,
'pgosm_flex_version_no_hash': '99.99.99'
}
replication_update = False
update = None
force = False
Expand All @@ -193,7 +197,9 @@ def test_import_mode_okay_to_run_returns_false_when_prior_import(self):
This should return False to protect the data.
"""
replication = False
prior_import = {'replication': False}
prior_import = {'replication': False,
'pgosm_flex_version_no_hash': '99.99.99'
}
replication_update = False
update = None
force = False
Expand Down

0 comments on commit b4a709b

Please sign in to comment.