Skip to content

Commit 040ee6c

Browse files
authored
Plugin version comparison should work for all cases (#599)
1 parent 5137188 commit 040ee6c

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

aws_gate/decorators.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
from subprocess import PIPE
44

5+
from packaging.version import parse as parse_version
56
from wrapt import decorator
67

78
from aws_gate.constants import PLUGIN_INSTALL_PATH, PLUGIN_NAME
@@ -43,9 +44,7 @@ def wrapper(
4344
required_version,
4445
)
4546

46-
if version and int(version.replace(".", "")) < int(
47-
required_version.replace(".", "")
48-
):
47+
if version and parse_version(version) < parse_version(required_version):
4948
raise ValueError("Invalid plugin version: {}".format(version))
5049

5150
return wrapped_function(*args, **kwargs)

requirements/requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
boto3~=1.15.15
2+
cryptography==3.1.1
23
marshmallow==3.8.0
4+
packaging==20.4
35
PyYAML>=5.1,<5.4
46
requests==2.24.0
5-
cryptography==3.1.1
6-
wrapt==1.12.1
77
unix-ar==0.2.1
8+
wrapt==1.12.1

tests/unit/test_decorators.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ def test_function():
4141
test_function()
4242

4343

44-
def test_plugin_version(mocker):
45-
m = mocker.patch("aws_gate.decorators.execute_plugin", return_value="1.1.23.0")
44+
@pytest.mark.parametrize("version", ["1.1.23.0", "1.2.7.0"])
45+
def test_plugin_version(mocker, version):
46+
m = mocker.patch("aws_gate.decorators.execute_plugin", return_value=version)
4647

4748
@plugin_version("1.1.23.0")
4849
def test_function():
@@ -52,10 +53,11 @@ def test_function():
5253
assert m.call_args == mocker.call(["--version"], stdout=PIPE, stderr=PIPE)
5354

5455

55-
def test_plugin_version_bad_version(mocker):
56+
@pytest.mark.parametrize("version", ["1.1.25.0", "1.2.7.0"])
57+
def test_plugin_version_bad_version(mocker, version):
5658
mocker.patch("aws_gate.decorators.execute_plugin", return_value="1.1.23.0")
5759

58-
@plugin_version("1.1.25.0")
60+
@plugin_version(version)
5961
def test_function():
6062
return "executed"
6163

0 commit comments

Comments
 (0)