-
Notifications
You must be signed in to change notification settings - Fork 24
/
test_helpers.py
68 lines (57 loc) · 3.07 KB
/
test_helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from chartpress import GITHUB_TOKEN_KEY
from chartpress import git_remote
from chartpress import image_needs_pushing
from chartpress import latest_tag_or_mod_commit
from chartpress import render_build_args
from chartpress import _strip_identifiers_build_suffix
from chartpress import _get_identifier
from ruamel.yaml import YAML
# use safe roundtrip yaml loader
yaml = YAML(typ='rt')
yaml.preserve_quotes = True ## avoid mangling of quotes
yaml.indent(mapping=2, offset=2, sequence=4)
def test__strip_identifiers_build_suffix():
assert _strip_identifiers_build_suffix(identifier="0.1.2-n005.hasdf1234") == "0.1.2"
assert _strip_identifiers_build_suffix(identifier="0.1.2-alpha.1.n005.hasdf1234") == "0.1.2-alpha.1"
def test__get_identifier():
assert _get_identifier(tag="0.1.2", n_commits="0", commit="asdf123", long=True) == "0.1.2-n000.hasdf123"
assert _get_identifier(tag="0.1.2", n_commits="0", commit="asdf123", long=False) == "0.1.2"
assert _get_identifier(tag="0.1.2", n_commits="5", commit="asdf123", long=False) == "0.1.2-n005.hasdf123"
assert _get_identifier(tag="0.1.2-alpha.1", n_commits="0", commit="asdf1234", long=True) == "0.1.2-alpha.1.n000.hasdf1234"
assert _get_identifier(tag="0.1.2-alpha.1", n_commits="0", commit="asdf1234", long=False) == "0.1.2-alpha.1"
assert _get_identifier(tag="0.1.2-alpha.1", n_commits="5", commit="asdf1234", long=False) == "0.1.2-alpha.1.n005.hasdf1234"
def test_git_remote(monkeypatch):
monkeypatch.setenv(GITHUB_TOKEN_KEY, "test-github-token")
assert git_remote("jupyterhub/helm-chart") == "https://test-github-token@github.com/jupyterhub/helm-chart"
monkeypatch.delenv(GITHUB_TOKEN_KEY)
assert git_remote("jupyterhub/helm-chart") == "git@github.com:jupyterhub/helm-chart"
def test_image_needs_pushing():
assert image_needs_pushing("jupyterhub/image-not-to-be-found:latest")
assert not image_needs_pushing("jupyterhub/k8s-hub:0.8.2")
def test_latest_tag_or_mod_commit(git_repo):
open('tag-mod.txt', "w").close()
git_repo.index.add("tag-mod.txt")
tag_commit = git_repo.index.commit("tag commit")
git_repo.create_tag("1.0.0", message="1.0.0")
open('post-tag-mod.txt', "w").close()
git_repo.index.add("post-tag-mod.txt")
post_tag_commit = git_repo.index.commit("post tag commit")
assert latest_tag_or_mod_commit("chartpress.yaml") == tag_commit.hexsha[:7]
assert latest_tag_or_mod_commit("tag-mod.txt") == tag_commit.hexsha[:7]
assert latest_tag_or_mod_commit("post-tag-mod.txt") == post_tag_commit.hexsha[:7]
def test_render_build_args(git_repo):
with open('chartpress.yaml') as f:
config = yaml.load(f)
for chart in config["charts"]:
for name, options in chart["images"].items():
build_args = render_build_args(
options,
{
'LAST_COMMIT': "sha",
'TAG': "tag",
},
)
assert build_args == {
'TEST_STATIC_BUILD_ARG': 'test',
'TEST_DYNAMIC_BUILD_ARG': 'tag-sha',
}