Skip to content

Commit

Permalink
Merge pull request #145 from minrk/dev-tags
Browse files Browse the repository at this point in the history
Add tests with dev tags and backport branches
  • Loading branch information
consideRatio authored Feb 22, 2022
2 parents 0156268 + 9da35be commit 7d53daf
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 5 deletions.
72 changes: 68 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import os
import shutil
import sys
import tempfile
from distutils.dir_util import copy_tree
from functools import partial

import git
import pytest

import chartpress

if sys.version_info >= (3, 8):
copy_tree = partial(shutil.copytree, dirs_exist_ok=True)
else:
# use deprecated distutils on Python < 3.8
# when shutil.copytree added dirs_exist_ok support
from distutils.dir_util import copy_tree


def pytest_configure(config):
config.addinivalue_line(
"markers", "registry: mark a test that modifies a container registry"
)


@pytest.fixture(scope="function")
@pytest.fixture
def git_repo(monkeypatch):
"""
This fixture provides a temporary git repo with two branches initialized.
Expand Down Expand Up @@ -52,7 +60,7 @@ def git_repo(monkeypatch):
yield r


@pytest.fixture(scope="function")
@pytest.fixture
def git_repo_bare_minimum(monkeypatch, git_repo):
"""
This fixture modifies the default git_repo fixture to use another the
Expand All @@ -68,7 +76,63 @@ def git_repo_bare_minimum(monkeypatch, git_repo):
yield r


@pytest.fixture(scope="function")
@pytest.fixture
def git_repo_dev_tag(git_repo):
"""
This fixture modifies the default git_repo fixture
to create a repo with a dev tag on the default branch
and a '1.x' backport branch
Both branches have a tag only on that branch,
and both branches have one commit since the latest tag:
main 1.x
| |
@2.0.0-dev @1.0.1
| /
@1.0.0
"""
r = git_repo
r.git.tag("1.0.0")
r.git.branch("1.x")
r.git.checkout("1.x")
image_file = os.path.join("image", "test.txt")

with open(image_file, "w") as f:
f.write("1.0.1")
r.git.add(image_file)
r.index.commit("add file for 1.0.1")
r.git.tag("1.0.1")

with open(image_file, "w") as f:
f.write("1.x")
r.git.add(image_file)
r.index.commit("add file for 1.x")

r.git.checkout("main")
with open(image_file, "w") as f:
f.write("2.0.0-dev")
r.git.add(image_file)
r.index.commit("add file for 2.0.0-dev")
r.git.tag("2.0.0-dev")

with open(image_file, "w") as f:
f.write("2.x")
r.git.add(image_file)
r.index.commit("add file for 2.x")

yield r


@pytest.fixture
def git_repo_backport_branch(git_repo_dev_tag):
"""Git repo with a backport branch currently checked out"""
r = git_repo_dev_tag
r.git.checkout("1.x")
yield r


@pytest.fixture
def git_repo_alternative(monkeypatch, git_repo):
"""
This fixture modifies the default git_repo fixture to use another the
Expand Down
27 changes: 26 additions & 1 deletion tests/test_repo_interactions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import sys
import re

import chartpress

Expand Down Expand Up @@ -304,3 +304,28 @@ def _capture_output(args, capfd, expect_output=False):
assert out == ""

return err


def test_dev_tag(git_repo_dev_tag, capfd):
r = git_repo_dev_tag
out = _capture_output(["--skip-build"], capfd)
version_string = re.search(r"version:\s+(.+)", out, re.MULTILINE).group(1)
chartpress._fix_chart_version(version_string, strict=True)
v, _, pre = version_string.partition("-")
# make sure we make a correct prerelease tag
# when merging with an existing '-pre' tag
# (i.e. join with '.', not multiple '-' separators)
assert "-" not in pre
assert v == "2.0.0"
assert pre.split(".")[:2] == ["dev", "n001"]


def test_backport_branch(git_repo_backport_branch, capfd):
r = git_repo_backport_branch
out = _capture_output(["--skip-build"], capfd)
version_string = re.search(r"version:\s+(.+)", out, re.MULTILINE).group(1)
chartpress._fix_chart_version(version_string, strict=True)
v, _, pre = version_string.partition("-")
assert "-" not in pre
assert v == "1.0.1"
assert pre.split(".")[:1] == ["n001"]

0 comments on commit 7d53daf

Please sign in to comment.