Skip to content

Commit

Permalink
check-version should ignore snapshot (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
ottobackwards committed Nov 12, 2020
1 parent d94a821 commit 8e770c5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 18 additions & 3 deletions nipyapi/utils.py
Expand Up @@ -8,6 +8,7 @@
from __future__ import absolute_import, unicode_literals
import logging
import json
import re
import time
from copy import copy
from functools import reduce
Expand Down Expand Up @@ -436,11 +437,26 @@ def start_docker_containers(docker_containers, network_name='demo'):
))


def strip_snapshot(java_version):
"""
Strips the -SNAPSHOT suffix from a version string
Args:
java_version (str): the version string
"""
assert isinstance(java_version, six.string_types)
return re.sub("-SNAPSHOT", "", java_version)


def check_version(base, comparator=None, service='nifi'):
"""
Compares version 'a' against either version 'b', or the version of the
currently connected service instance.
Since NiFi is java, it may return a version with -SNAPSHOT as part of it.
As such, that will be stripped from either the comparator version or
the version returned from NiFi
Args:
base (str): The base version for the comparison test
comparator (optional[str]): The version to compare against
Expand All @@ -457,12 +473,11 @@ def check_version(base, comparator=None, service='nifi'):
ver_a = version.parse(base)
if comparator:
# if b is set, we compare the passed versions
comparator = strip_snapshot(comparator)
ver_b = version.parse(comparator)
else:
# if b not set, we compare a against the connected nifi instance
ver_b = version.parse(
nipyapi.system.get_nifi_version_info().ni_fi_version
)
ver_b = version.parse(strip_snapshot(nipyapi.system.get_nifi_version_info().ni_fi_version))
if ver_b > ver_a:
return -1
if ver_b < ver_a:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_utils.py
Expand Up @@ -135,6 +135,10 @@ def test_check_version(regress_nifi):
assert utils.check_version('1.2.3', '0.2.3') == 1
# Check RC
assert utils.check_version('1.0.0-rc1', '1.0.0') == -1
# Check that snapshots are disregarded
assert utils.check_version('1.11.0', '1.13.0-SNAPSHOT') == -1
assert utils.check_version('1.11.0', "1.11.0-SNAPSHOT") == 0
assert utils.check_version('1.11.0', "1.10.0-SNAPSHOT") == 1
# Check current version
assert utils.check_version(
system.get_nifi_version_info().ni_fi_version
Expand Down

0 comments on commit 8e770c5

Please sign in to comment.