forked from jupyterhub/kubespawner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
let safe slug scheme live side-by-side with escape scheme
- add user_server to template namespace - add `safe_` prefixed fields to template namespace using new 'safe' slug scheme - add pod_name, namespace, pvc_name to template namespace
- Loading branch information
Showing
3 changed files
with
174 additions
and
77 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,61 @@ | ||
import pytest | ||
|
||
from kubespawner.slugs import safe_slug | ||
from kubespawner.slugs import is_valid_label, safe_slug | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"name, expected", | ||
[ | ||
("jupyter-alex", "jupyter-alex"), | ||
("jupyter-Alex", "jupyter-alex--3a1c285c"), | ||
("jupyter-üni", "jupyter-ni--a5aaf5dd"), | ||
("jupyter-Alex", "jupyter-alex---3a1c285c"), | ||
("jupyter-üni", "jupyter-ni---a5aaf5dd"), | ||
("endswith-", "endswith---165f1166"), | ||
("-start", "j-start--f587e2dc"), | ||
("j-start--f587e2dc", "j-start--f587e2dc--f007ef7c"), | ||
("x" * 65, "xxxxxxxxxxxxxxxxxxxxxxxx--9537c5fd"), | ||
("x" * 66, "xxxxxxxxxxxxxxxxxxxxxxxx--6eb879f1"), | ||
("-start", "start---f587e2dc"), | ||
("username--servername", "username-servername---d957f1de"), | ||
("start---f587e2dc", "start-f587e2dc---cc5bb9c9"), | ||
pytest.param("x" * 63, "x" * 63, id="x63"), | ||
pytest.param("x" * 64, "xxxxxxxxxxxxxxxxxxxxx---7ce10097", id="x64"), | ||
pytest.param("x" * 65, "xxxxxxxxxxxxxxxxxxxxx---9537c5fd", id="x65"), | ||
("", "x---e3b0c442"), | ||
], | ||
) | ||
def test_safe_slug(name, expected): | ||
slug = safe_slug(name) | ||
assert slug == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"max_length, length, expected", | ||
[ | ||
(16, 16, "x" * 16), | ||
(16, 17, "xxxxx---d04fd59f"), | ||
(11, 16, "error"), | ||
(12, 16, "x---9c572959"), | ||
], | ||
) | ||
def test_safe_slug_max_length(max_length, length, expected): | ||
name = "x" * length | ||
if expected == "error": | ||
with pytest.raises(ValueError): | ||
safe_slug(name, max_length=max_length) | ||
return | ||
|
||
slug = safe_slug(name, max_length=max_length) | ||
assert slug == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"name, expected", | ||
[ | ||
("", ""), | ||
("x", "x"), | ||
("-x", "x---a4209624"), | ||
("x-", "x---c8b60efc"), | ||
pytest.param("x" * 63, "x" * 63, id="x64"), | ||
pytest.param("x" * 64, "xxxxxxxxxxxxxxxxxxxxx---7ce10097", id="x64"), | ||
pytest.param("x" * 65, "xxxxxxxxxxxxxxxxxxxxx---9537c5fd", id="x65"), | ||
], | ||
) | ||
def test_safe_slug_label(name, expected): | ||
slug = safe_slug(name, is_valid=is_valid_label) | ||
assert slug == expected |