Skip to content

Commit d606e98

Browse files
committed
add tests
1 parent 2277181 commit d606e98

File tree

5 files changed

+92
-1
lines changed

5 files changed

+92
-1
lines changed

tests/cli/test_migrate.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,27 @@ def test_migrate_project(isolated_runner, old_project, with_injection):
5353
assert project_context.project.name
5454

5555

56+
@pytest.mark.migration
57+
@pytest.mark.parametrize(
58+
"old_project",
59+
[
60+
"v9-migration-docker-version-change.git",
61+
"v9-migration-docker-mult-changes.git",
62+
],
63+
indirect=["old_project"],
64+
)
65+
def test_migrate_old_project_with_docker_change(isolated_runner, old_project, with_injection):
66+
"""Test migrating projects with changes to the Dockerfile."""
67+
result = isolated_runner.invoke(cli, ["migrate", "--strict"])
68+
assert 0 == result.exit_code, format_result_exception(result)
69+
assert not old_project.repository.is_dirty()
70+
assert "Updated dockerfile" in result.output
71+
72+
with project_context.with_path(old_project.path), with_injection():
73+
assert project_context.project
74+
assert project_context.project.name
75+
76+
5677
@pytest.mark.migration
5778
@pytest.mark.serial
5879
def test_migration_check(isolated_runner, project):
30.2 KB
Binary file not shown.
30.3 KB
Binary file not shown.

tests/service/fixtures/service_integration.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from renku.core import errors
2727
from renku.infrastructure.repository import Repository
28-
from tests.utils import format_result_exception, modified_environ
28+
from tests.utils import clone_compressed_repository, format_result_exception, modified_environ
2929

3030

3131
@contextlib.contextmanager
@@ -272,6 +272,57 @@ def _parse(href):
272272
pass
273273

274274

275+
@pytest.fixture
276+
def old_local_remote_project(request, svc_client, tmp_path, mock_redis, identity_headers, real_sync):
277+
"""Fixture for testing service with project tarfiles containing old projects."""
278+
from renku.domain_model import git
279+
from renku.ui.service.cache import cache as redis_cache
280+
from renku.ui.service.gateways.repository_cache import LocalRepositoryCache
281+
from renku.ui.service.serializers.headers import RequiredIdentityHeaders
282+
283+
name = request.param
284+
remote_repo_path = tmp_path / name
285+
remote_repo = clone_compressed_repository(base_path=tmp_path, name=name)
286+
remote_repo_path = remote_repo_path / "repository"
287+
remote_repo_checkout_path = tmp_path / "remote_repo_checkout"
288+
remote_repo_checkout_path.mkdir()
289+
290+
remote_repo_checkout = Repository.clone_from(url=remote_repo_path, path=remote_repo_checkout_path)
291+
292+
# NOTE: Mock GitURL parsing for local URL
293+
def _parse(href):
294+
return git.GitURL(href=href, regex="", owner="dummy", name="project", slug="project", path=remote_repo_path)
295+
296+
original_giturl_parse = git.GitURL.parse
297+
git.GitURL.parse = _parse
298+
299+
home = tmp_path / "user_home"
300+
home.mkdir()
301+
302+
user_data = RequiredIdentityHeaders().load(identity_headers)
303+
user = redis_cache.ensure_user(user_data)
304+
remote_url = f"file://{remote_repo_path}"
305+
306+
project = LocalRepositoryCache().get(redis_cache, remote_url, branch=None, user=user, shallow=False)
307+
308+
project_id = project.project_id
309+
310+
try:
311+
yield svc_client, identity_headers, project_id, remote_repo, remote_repo_checkout, remote_url
312+
finally:
313+
git.GitURL.parse = original_giturl_parse
314+
315+
try:
316+
shutil.rmtree(remote_repo_path)
317+
except OSError:
318+
pass
319+
320+
try:
321+
shutil.rmtree(remote_repo_checkout_path)
322+
except OSError:
323+
pass
324+
325+
275326
@pytest.fixture
276327
def quick_cache_synchronization(mocker):
277328
"""Forces cache to synchronize on every request."""

tests/service/views/test_cache_views.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,25 @@ def test_execute_migrations(svc_client_setup):
704704
assert not response.json["result"]["errors"]
705705

706706

707+
@pytest.mark.service
708+
@pytest.mark.parametrize(
709+
"old_local_remote_project",
710+
[
711+
"v9-migration-docker-version-change.git",
712+
"v9-migration-docker-mult-changes.git",
713+
],
714+
indirect=["old_local_remote_project"],
715+
)
716+
def test_migrate_old_project(old_local_remote_project):
717+
"""Test migrating old projects with docker file changes."""
718+
svc_client, identity_headers, project_id, remote_repo, remote_repo_checkout, remote_url = old_local_remote_project
719+
720+
response = svc_client.post("/cache.migrate", data=json.dumps(dict(git_url=remote_url)), headers=identity_headers)
721+
assert response
722+
assert 200 == response.status_code
723+
assert response.json.get("result", {}).get("docker_migrated", False)
724+
725+
707726
@pytest.mark.service
708727
@pytest.mark.integration
709728
def test_execute_migrations_job(svc_client_setup):

0 commit comments

Comments
 (0)