Skip to content

Commit

Permalink
fix: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau committed Sep 12, 2024
1 parent 2d9d3df commit 5b6a9f3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ jobs:
sudo apt install -y python3-pip python3-setuptools python3-wheel python3-venv libapt-pkg-dev
- name: Setup LXD
uses: canonical/setup-lxd@v0.1.1
with:
channel: latest/stable
if: ${{ runner.os == 'Linux' }}
- name: Install skopeo (mac)
# This is only necessary for Linux until skopeo >= 1.11 is in repos.
Expand Down
39 changes: 32 additions & 7 deletions tests/integration/services/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,50 @@


@pytest.mark.skipif(sys.platform == "win32", reason="no cache on windows")
def test_locks_cache(
def test_lock_cache(
service_factory: services.CharmcraftServiceFactory,
tmp_path: pathlib.Path,
default_build_info: BuildInfo,
emitter: RecordingEmitter,
):
_maybe_lock_cache(tmp_path)
assert (tmp_path / "charmcraft.lock").exists()
cache_path = tmp_path / "cache"
cache_path.mkdir()
provider = service_factory.provider
provider_kwargs = {
"build_info": default_build_info,
"work_dir": pathlib.Path(__file__).parent,
"cache_path": tmp_path,
"cache_path": cache_path,
}
assert not (cache_path / "charmcraft.lock").exists()

with provider.instance(**provider_kwargs) as instance:
# Because we've already locked the cache, we shouldn't see the lockfile.
lock_test = instance.execute_run(["test", "-f", "/root/.cache/charmcraft.lock"])
assert lock_test.returncode == 1
# Test that the cache lock gets created
assert (cache_path / "charmcraft.lock").is_file()

(cache_path / "charmcraft.lock").write_text("Test that file isn't locked.")


@pytest.mark.skipif(sys.platform == "win32", reason="no cache on windows")
def test_locked_cache_no_cache(
service_factory: services.CharmcraftServiceFactory,
tmp_path: pathlib.Path,
default_build_info: BuildInfo,
emitter: RecordingEmitter,
):
cache_path = tmp_path / "cache"
cache_path.mkdir()
_maybe_lock_cache(cache_path)
assert (cache_path / "charmcraft.lock").exists()
provider = service_factory.provider
provider_kwargs = {
"build_info": default_build_info,
"work_dir": pathlib.Path(__file__).parent,
"cache_path": cache_path,
}

with provider.instance(**provider_kwargs) as instance:
# Because we've already locked the cache, we don't get a subdirectory in the cache.
assert list(cache_path.iterdir()) == [cache_path / "charmcraft.lock"]

# Create a file in the cache and ensure it's not visible in the outer fs
instance.execute_run(["touch", "/root/.cache/cache_cached"])
Expand Down

0 comments on commit 5b6a9f3

Please sign in to comment.