-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(kafka): Add Kraft to Kafka containers (#611)
Following a similar strategy as several other testcontainers implementations, this PR introduces the possibility to run Kafka in KRAft mode. ```py with KafkaContainer().with_kraft() as container: # Test something with/on KRaft mode ```
- Loading branch information
Showing
4 changed files
with
202 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from typing import Callable | ||
|
||
from packaging.version import Version | ||
|
||
|
||
class ComparableVersion: | ||
def __init__(self, version): | ||
self.version = Version(version) | ||
|
||
def __lt__(self, other: str): | ||
return self._apply_op(other, lambda x, y: x < y) | ||
|
||
def __le__(self, other: str): | ||
return self._apply_op(other, lambda x, y: x <= y) | ||
|
||
def __eq__(self, other: str): | ||
return self._apply_op(other, lambda x, y: x == y) | ||
|
||
def __ne__(self, other: str): | ||
return self._apply_op(other, lambda x, y: x != y) | ||
|
||
def __gt__(self, other: str): | ||
return self._apply_op(other, lambda x, y: x > y) | ||
|
||
def __ge__(self, other: str): | ||
return self._apply_op(other, lambda x, y: x >= y) | ||
|
||
def _apply_op(self, other: str, op: Callable[[Version, Version], bool]): | ||
other = Version(other) | ||
return op(self.version, other) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import pytest | ||
from packaging.version import InvalidVersion | ||
|
||
from testcontainers.core.version import ComparableVersion | ||
|
||
|
||
@pytest.fixture | ||
def version(): | ||
return ComparableVersion("1.0.0") | ||
|
||
|
||
@pytest.mark.parametrize("other_version, expected", [("0.9.0", False), ("1.0.0", False), ("1.1.0", True)]) | ||
def test_lt(version, other_version, expected): | ||
assert (version < other_version) == expected | ||
|
||
|
||
@pytest.mark.parametrize("other_version, expected", [("0.9.0", False), ("1.0.0", True), ("1.1.0", True)]) | ||
def test_le(version, other_version, expected): | ||
assert (version <= other_version) == expected | ||
|
||
|
||
@pytest.mark.parametrize("other_version, expected", [("0.9.0", False), ("1.0.0", True), ("1.1.0", False)]) | ||
def test_eq(version, other_version, expected): | ||
assert (version == other_version) == expected | ||
|
||
|
||
@pytest.mark.parametrize("other_version, expected", [("0.9.0", True), ("1.0.0", False), ("1.1.0", True)]) | ||
def test_ne(version, other_version, expected): | ||
assert (version != other_version) == expected | ||
|
||
|
||
@pytest.mark.parametrize("other_version, expected", [("0.9.0", True), ("1.0.0", False), ("1.1.0", False)]) | ||
def test_gt(version, other_version, expected): | ||
assert (version > other_version) == expected | ||
|
||
|
||
@pytest.mark.parametrize("other_version, expected", [("0.9.0", True), ("1.0.0", True), ("1.1.0", False)]) | ||
def test_ge(version, other_version, expected): | ||
assert (version >= other_version) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"invalid_version", | ||
[ | ||
"invalid", | ||
"1..0", | ||
], | ||
) | ||
def test_invalid_version_raises_error(invalid_version): | ||
with pytest.raises(InvalidVersion): | ||
ComparableVersion(invalid_version) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"invalid_version", | ||
[ | ||
"invalid", | ||
"1..0", | ||
], | ||
) | ||
def test_comparison_with_invalid_version_raises_error(version, invalid_version): | ||
with pytest.raises(InvalidVersion): | ||
assert version < invalid_version | ||
|
||
with pytest.raises(InvalidVersion): | ||
assert version <= invalid_version | ||
|
||
with pytest.raises(InvalidVersion): | ||
assert version == invalid_version | ||
|
||
with pytest.raises(InvalidVersion): | ||
assert version != invalid_version | ||
|
||
with pytest.raises(InvalidVersion): | ||
assert version > invalid_version | ||
|
||
with pytest.raises(InvalidVersion): | ||
assert version >= invalid_version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters