From e89852cd904435d028eee9e915064f281379345e Mon Sep 17 00:00:00 2001 From: Bruno Pimentel Date: Mon, 24 Jun 2024 18:15:49 -0300 Subject: [PATCH] Remove the restriction in using Go workspaces Since the support for workspaces was not properly implemented, we had a strict check on the existence of a "go.work" file in a repository, which would then trigger a failure in a request. Now that proper support is implemented, let's remove this check. Signed-off-by: Bruno Pimentel --- cachito/workers/tasks/gomod.py | 24 -------- tests/integration/test_gomod_packages.py | 27 --------- tests/test_workers/test_tasks/test_gomod.py | 63 --------------------- 3 files changed, 114 deletions(-) diff --git a/cachito/workers/tasks/gomod.py b/cachito/workers/tasks/gomod.py index f1b845e7a..3c0df771c 100644 --- a/cachito/workers/tasks/gomod.py +++ b/cachito/workers/tasks/gomod.py @@ -43,28 +43,6 @@ def _find_missing_gomod_files(bundle_dir, subpaths): return invalid_gomod_files -def _is_workspace(repo_root: Path, subpath: str): - current_path = repo_root / subpath - - while current_path != repo_root: - if (current_path / "go.work").exists(): - log.warning("go.work file found at %s", current_path) - return True - current_path = current_path.parent - - if (repo_root / "go.work").exists(): - log.warning("go.work file found at %s", repo_root) - return True - - return False - - -def _fail_if_bundle_dir_has_workspaces(bundle_dir: RequestBundleDir, subpaths: list[str]): - for subpath in subpaths: - if _is_workspace(bundle_dir.source_root_dir, subpath): - raise UnsupportedFeature("Go workspaces are not supported by Cachito.") - - def _fail_if_parent_replacement_not_included(packages_json_data: PackagesData) -> None: """ Fail if any dependency replacement refers to a parent dir that isn't included in this request. @@ -133,8 +111,6 @@ def fetch_gomod_source(request_id, dep_replacements=None, package_configs=None): # Default to the root of the application source subpaths = [os.curdir] - _fail_if_bundle_dir_has_workspaces(bundle_dir, subpaths) - invalid_gomod_files = _find_missing_gomod_files(bundle_dir, subpaths) if invalid_gomod_files: invalid_files_print = "; ".join(invalid_gomod_files) diff --git a/tests/integration/test_gomod_packages.py b/tests/integration/test_gomod_packages.py index 69d205286..73fe3f93b 100644 --- a/tests/integration/test_gomod_packages.py +++ b/tests/integration/test_gomod_packages.py @@ -69,33 +69,6 @@ def test_gomod_vendor_check_fail(env_name, test_env): ) -def test_gomod_workspace_check(test_env): - """ - Validate failing of gomod requests that contain workspaces. - - Checks: - * The request fails with expected error message - """ - env_data = utils.load_test_data("gomod_packages.yaml")["with_workspace"] - client = utils.Client(test_env["api_url"], test_env["api_auth_type"], test_env.get("timeout")) - initial_response = client.create_new_request( - payload={ - "repo": env_data["repo"], - "ref": env_data["ref"], - "pkg_managers": env_data["pkg_managers"], - }, - ) - completed_response = client.wait_for_complete_request(initial_response) - assert completed_response.status == 200 - assert completed_response.data["state"] == "failed" - error_msg = "Go workspaces are not supported by Cachito." - - assert error_msg in completed_response.data["state_reason"], ( - f"#{completed_response.id}: Request failed correctly, but with unexpected message: " - f"{completed_response.data['state_reason']}. Expected message was: {error_msg}" - ) - - def test_gomod_with_local_replacements_in_parent_dir_missing(test_env): """ Test that a gomod local replacement from a parent directory includes the parent module. diff --git a/tests/test_workers/test_tasks/test_gomod.py b/tests/test_workers/test_tasks/test_gomod.py index f897639a1..c9daad35f 100644 --- a/tests/test_workers/test_tasks/test_gomod.py +++ b/tests/test_workers/test_tasks/test_gomod.py @@ -68,7 +68,6 @@ ), ) @pytest.mark.parametrize("has_pkg_lvl_deps", (True, False)) -@mock.patch("cachito.workers.tasks.gomod._fail_if_bundle_dir_has_workspaces") @mock.patch("cachito.workers.tasks.gomod.RequestBundleDir") @mock.patch("cachito.workers.tasks.gomod.update_request_env_vars") @mock.patch("cachito.workers.tasks.gomod.set_request_state") @@ -80,7 +79,6 @@ def test_fetch_gomod_source( mock_set_request_state, mock_update_request_env_vars, mock_bundle_dir, - mock_fail_workspaces, dep_replacements, expect_state_update, pkg_config, @@ -268,7 +266,6 @@ def directory_present(*args, **kwargs): ), ), ) -@mock.patch("cachito.workers.tasks.gomod._fail_if_bundle_dir_has_workspaces") @mock.patch("cachito.workers.tasks.gomod.get_worker_config") @mock.patch("cachito.workers.tasks.gomod.RequestBundleDir") @mock.patch("cachito.workers.tasks.gomod.resolve_gomod") @@ -276,7 +273,6 @@ def test_fetch_gomod_source_no_go_mod_file( mock_resolve_gomod, mock_bundle_dir, mock_gwc, - mock_fail_workspaces, ignore_missing_gomod_file, exception_expected, pkg_config, @@ -308,65 +304,6 @@ def directory_present(*args, **kwargs): mock_resolve_gomod.assert_not_called() -@pytest.mark.parametrize( - "module_name, package_name, module_subpath, expect_subpath", - [ - ("github.com/foo", "github.com/foo", ".", "."), - ("github.com/foo", "github.com/foo", "bar", "bar"), - ("github.com/foo", "github.com/foo/bar", ".", "bar"), - ("github.com/foo", "github.com/foo/bar", "src", "src/bar"), - ], -) -def test_package_subpath(module_name, package_name, module_subpath, expect_subpath): - assert gomod._package_subpath(module_name, package_name, module_subpath) == expect_subpath - - -@pytest.mark.parametrize( - "repo, subpath, expected_result", - [ - ("repo", "workspace", True), - ("repo", "workspace/mod_a", True), - ("repo", "workspace/mod_b", True), - ("repo", "nonworspace", False), - ("repo", "nonworspace/mod_c", False), - ("repo", "randompath", False), - ("anotherrepo", ".", True), - ], -) -def test_is_workspace(repo, subpath, expected_result, tmpdir): - tmpdir.mkdir("repo") - tmpdir.mkdir("repo/workspace") - tmpdir.mkdir("repo/workspace/mod_a") - tmpdir.mkdir("repo/workspace/mod_b") - tmpdir.mkdir("repo/nonworspace") - tmpdir.mkdir("repo/nonworspace/mod_c") - tmpdir.mkdir("anotherrepo") - - Path(tmpdir / "repo/workspace" / "go.work").touch() - Path(tmpdir / "anotherrepo" / "go.work").touch() - - repo_root = Path(tmpdir / repo) - result = gomod._is_workspace(repo_root, subpath) - - assert result == expected_result - - -@pytest.mark.parametrize("add_go_work_file", [True, False]) -def test_fail_if_bundle_dir_has_workspaces(add_go_work_file, tmpdir): - tmpdir.mkdir("temp") - tmpdir.mkdir("temp/1") - tmpdir.mkdir("temp/1/app") - - bundle_dir = RequestBundleDir(1, tmpdir) - - if add_go_work_file: - Path(bundle_dir.source_root_dir / "go.work").touch() - with pytest.raises(UnsupportedFeature): - gomod._fail_if_bundle_dir_has_workspaces(bundle_dir, ["."]) - else: - gomod._fail_if_bundle_dir_has_workspaces(bundle_dir, ["."]) - - @pytest.mark.parametrize( "packages", [