-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add version metadata #4874
Add version metadata #4874
Changes from all commits
42ccb88
ffe81db
294602f
4e3c315
755c960
dd10d0e
c600eb6
9c7ce54
fb9784a
962a8fa
ab8d4ea
5928819
f4022d3
7b0a249
81f9d5f
b7c9f74
0fe217d
5398b24
768a356
d12d774
a0401c6
6b3af0d
1cb0e14
2ce7e8a
c35f28a
837386d
0ddbb8a
ef4be98
e472798
4014058
6ab4df9
eafc603
359b537
fb0cba8
ea597b3
4240dc5
19f0d99
bcc3d40
9e3b95a
faf3b65
1b8435e
0960c7a
6ce4997
a217570
689f485
6c53573
eb0cdc2
143831d
1ddb84f
a4a31ac
d2efb46
7735c41
eb5611a
66916d3
c8eabed
33e2a00
f6d7718
e019e57
3673c05
d13bba4
7c08baf
a6a26e0
c024d2f
0626bef
91fe489
2eb7c12
0a751fa
f5dcb7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,44 +2,77 @@ | |
# All rights reserved | ||
# Licensed under Simplified BSD License (see LICENSE) | ||
import pytest | ||
from mock import MagicMock | ||
from semver import VersionInfo | ||
|
||
from datadog_checks.postgres.version_utils import get_version | ||
from datadog_checks.postgres.version_utils import parse_version, transform_version | ||
|
||
pytestmark = pytest.mark.unit | ||
|
||
|
||
def test_get_version(): | ||
def test_parse_version(): | ||
""" | ||
Test _get_version() to make sure the check is properly parsing Postgres versions | ||
""" | ||
db = MagicMock() | ||
|
||
# Test #.#.# style versions | ||
db.cursor().fetchone.return_value = ['9.5.3'] | ||
assert get_version(db) == VersionInfo(9, 5, 3) | ||
version = parse_version('9.5.3') | ||
assert version == VersionInfo(9, 5, 3) | ||
|
||
# Test #.# style versions | ||
db.cursor().fetchone.return_value = ['10.2'] | ||
assert get_version(db) == VersionInfo(10, 2, 0) | ||
v10_2 = parse_version('10.2') | ||
assert v10_2 == VersionInfo(10, 2, 0) | ||
|
||
v11 = parse_version('11') | ||
assert v11 == VersionInfo(11, 0, 0) | ||
|
||
# Test #beta# style versions | ||
db.cursor().fetchone.return_value = ['11beta3'] | ||
assert get_version(db) == VersionInfo(11, -1, 3) | ||
beta11 = parse_version('11beta3') | ||
assert beta11 == VersionInfo(11, 0, 0, prerelease='beta.3') | ||
|
||
assert v10_2 < beta11 | ||
assert v11 > beta11 | ||
|
||
# Test #rc# style versions | ||
db.cursor().fetchone.return_value = ['11rc1'] | ||
assert get_version(db) == VersionInfo(11, -1, 1) | ||
version = parse_version('11rc1') | ||
assert version == VersionInfo(11, 0, 0, prerelease='rc.1') | ||
|
||
# Test #nightly# style versions | ||
db.cursor().fetchone.return_value = ['11nightly3'] | ||
assert get_version(db) == VersionInfo(11, -1, 3) | ||
version = parse_version('11nightly3') | ||
assert version == VersionInfo(11, 0, 0, 'nightly.3') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (nit) This could be a parameterized test. Currently if the firs case fail, the following cases are not run. |
||
|
||
|
||
def test_throws_exception_for_unknown_version_format(): | ||
db = MagicMock() | ||
db.cursor().fetchone.return_value = ['dontKnow'] | ||
with pytest.raises(Exception) as e: | ||
get_version(db) | ||
parse_version('dontKnow') | ||
assert e.value.args[0] == "Cannot determine which version is dontKnow" | ||
|
||
|
||
def test_transform_version(): | ||
version = transform_version('11beta4') | ||
expected = { | ||
'version.raw': '11beta4', | ||
'version.major': '11', | ||
'version.minor': '0', | ||
'version.patch': '0', | ||
'version.release': 'beta.4', | ||
'version.scheme': 'semver', | ||
} | ||
assert expected == version | ||
|
||
version = transform_version('10.0') | ||
expected = { | ||
'version.raw': '10.0', | ||
'version.major': '10', | ||
'version.minor': '0', | ||
'version.patch': '0', | ||
'version.scheme': 'semver', | ||
} | ||
assert expected == version | ||
|
||
version = transform_version('10.5.4') | ||
expected = { | ||
'version.raw': '10.5.4', | ||
'version.major': '10', | ||
'version.minor': '5', | ||
'version.patch': '4', | ||
'version.scheme': 'semver', | ||
} | ||
assert expected == version | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (nit) This could be a parameterized test. Currently if the firs case fail, the following cases are not run. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) In this case, maybe we should just pass down the version as method parameter instead of caching it on self._version. Seems easier to understand and less error prone.