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
4 changes: 2 additions & 2 deletions ddev/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ddev.utils.github import GitHubManager
from ddev.utils.platform import Platform

from .helpers import APPLICATION, PLATFORM
from .helpers import APPLICATION, LOCAL_REPO_BRANCH, PLATFORM
from .helpers.git import ClonedRepo
from .helpers.runner import CliRunner

Expand Down Expand Up @@ -177,7 +177,7 @@ def local_clone(isolation, local_repo) -> Generator[ClonedRepo, None, None]:
PLATFORM.check_command_output(['git', 'worktree', 'add', 'wt', 'HEAD'])
PLATFORM.check_command_output(['git', 'worktree', 'add', '../wt2', 'HEAD'])

cloned_repo = ClonedRepo(cloned_repo_path, 'origin/master', 'ddev-testing')
cloned_repo = ClonedRepo(cloned_repo_path, 'origin/master', LOCAL_REPO_BRANCH)
cloned_repo.reset_branch()

yield cloned_repo
Expand Down
1 change: 1 addition & 0 deletions ddev/tests/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

PLATFORM = Platform()
APPLICATION = Application(lambda code: print(f"Applicatione exited with code: {code}"), 1, False, False)
LOCAL_REPO_BRANCH = "ddev-testing"
46 changes: 33 additions & 13 deletions ddev/tests/test__utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,36 @@
# This file is named with a double underscore so it comes first lexicographically


def test_cloned_repo(repository, local_repo):
integrations = {
entry.name for entry in repository.path.iterdir() if (repository.path / entry.name / 'manifest.json').is_file()
}
expected_integrations = {
entry.name for entry in local_repo.iterdir() if (local_repo / entry.name / 'manifest.json').is_file()
}

# Note: We are checking that the number of integrations is +- 1 from the `master`
# branch as a workaround for scenarios where the current branch adds/removes
# an integration and there has a different integration count than master.
if abs(len(integrations) - len(expected_integrations)) > 1:
assert integrations == expected_integrations
from ddev.utils.fs import Path
from ddev.utils.git import GitRepository
from tests.helpers import LOCAL_REPO_BRANCH
from tests.helpers.git import ClonedRepo


def commit_from_branch(repository: GitRepository, branch: str) -> str:
return repository.capture('rev-parse', branch).strip()


def ref_list(repository: GitRepository, left_ref: str, right_ref: str) -> list[str]:
return repository.capture('rev-list', f"{left_ref}..{right_ref}").strip().splitlines()


def test_cloned_repo(repository: ClonedRepo, local_repo: Path):
# The cloned repo (repository) should be a repository that is in the LOCAL_REPO_BRANCH
# branching of from the latest commit in origin master
# To validate this, we will get the current origin/master updated (in local_repo), check the rev-list
# between the current branch and origin/master and then validate that this is the same
# as the rev-list between the repository and local_repo.

current_repo = GitRepository(local_repo)
cloned_repo = GitRepository(repository.path)

current_repo.capture('fetch', 'origin', 'master')
current_repo_origin_master_ref = commit_from_branch(current_repo, 'origin/master')
current_repo_head_ref = commit_from_branch(current_repo, "HEAD")

current_repo_commit_list = ref_list(current_repo, current_repo_origin_master_ref, "HEAD")

cloned_repo_commit_list = ref_list(cloned_repo, LOCAL_REPO_BRANCH, current_repo_head_ref)

assert current_repo_commit_list == cloned_repo_commit_list
Loading