Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions kubetest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def new_namespace(test_name: str) -> str:
Kubernetes namespace names follow a DNS-1123 label that consists of lower case
alphanumeric characters or '-' and must start with an alphanumeric.

The test name and current timestamp are formatted to comply to this spec and
appended to the 'kubetest' prefix.
The test name and current reversed timestamp are formatted to comply to this
spec and appended to the 'kubetest' prefix.

Args:
test_name: The name of the test case for the namespace.
Expand All @@ -27,7 +27,7 @@ def new_namespace(test_name: str) -> str:
The namespace name.
"""
prefix = "kubetest"
timestamp = str(int(time.time()))
reversed_timestamp = str(int(time.time()))[::-1]
test_name = test_name.replace("_", "-").lower()
test_name = test_name.replace("[", "-")
test_name = test_name.replace("]", "-")
Expand All @@ -36,12 +36,12 @@ def new_namespace(test_name: str) -> str:
# characters. Check the length of all components (+2 for the dashes
# joining the components). If the total length exceeds 63, truncate
# the test name.
name_len = len(prefix) + len(timestamp) + len(test_name) + 2
name_len = len(prefix) + len(reversed_timestamp) + len(test_name) + 2

if name_len > 63:
test_name = test_name[: -(name_len - 63)]

return "-".join((prefix, test_name, timestamp))
return "-".join((prefix, test_name, reversed_timestamp))


def selector_string(selectors: Mapping[str, str]) -> str:
Expand Down
18 changes: 9 additions & 9 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
@pytest.mark.parametrize(
"name,expected",
[
("", "kubetest--1536849367"),
("TestName", "kubetest-testname-1536849367"),
("TESTNAME", "kubetest-testname-1536849367"),
("Test-Name", "kubetest-test-name-1536849367"),
("Test1_FOO-BAR_2", "kubetest-test1-foo-bar-2-1536849367"),
("123456", "kubetest-123456-1536849367"),
("___", "kubetest-----1536849367"),
("", "kubetest--7639486351"),
("TestName", "kubetest-testname-7639486351"),
("TESTNAME", "kubetest-testname-7639486351"),
("Test-Name", "kubetest-test-name-7639486351"),
("Test1_FOO-BAR_2", "kubetest-test1-foo-bar-2-7639486351"),
("123456", "kubetest-123456-7639486351"),
("___", "kubetest-----7639486351"),
(
"test-" * 14,
"kubetest-test-test-test-test-test-test-test-test-tes-1536849367",
"kubetest-test-test-test-test-test-test-test-test-tes-7639486351",
),
("test[a]-foo", "kubetest-test-a--foo-1536849367"),
("test[a]-foo", "kubetest-test-a--foo-7639486351"),
],
)
def test_new_namespace(name, expected):
Expand Down