Skip to content

Commit

Permalink
tests: Add tests for volume hostpaths which use ../
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathonReinhart committed Sep 13, 2023
1 parent d9e36ff commit c7082a2
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,40 @@ def test_volumes_hostpath_rel(self, monkeypatch, in_tmp_path) -> None:
assert_vol(config.volumes, "/scp", in_tmp_path / "snap" / "crackle" / "pop")
assert_vol(config.volumes, "/relvar", in_tmp_path / "spam" / "eggs")

def test_volumes_hostpath_rel_above(self, monkeypatch, in_tmp_path) -> None:
"""volume hostpath can be relative, above scuba_root (top dir)"""
# Directory structure:
#
# test-tmpdir/ # in_tmp_path
# |- foo_up_here/ # will be mounted at /foo
# |- way/
# |- down/
# |- here/ # scuba roo (found_topdir)
# |- .scuba.yml

# First, make a subdirectory and cd into it
project_dir = Path("way/down/here")
project_dir.mkdir(parents=True)
monkeypatch.chdir(project_dir)

# Now put .scuba.yml here
with open(".scuba.yml", "w") as f:
f.write(
r"""
image: na
volumes:
/foo: ../../../foo_up_here
"""
)

# Locate the config
found_topdir, found_rel, config = scuba.config.find_config()
assert found_topdir == in_tmp_path / project_dir
assert found_rel == Path()

assert config.volumes is not None
assert_vol(config.volumes, "/foo", in_tmp_path / "foo_up_here")

def test_volumes_hostpath_rel_req_dot_simple(
self, monkeypatch, in_tmp_path
) -> None:
Expand Down
37 changes: 37 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,3 +1092,40 @@ def test_volumes_host_path_rel(self) -> None:

out, _ = self.run_scuba(["cat", "/userdir/test.txt"])
assert out == test_message

def test_volumes_hostpath_rel_above(self) -> None:
"""Volume host paths can be relative, above the scuba root dir"""
# Directory structure:
#
# test-tmpdir/
# |- user/ # will be mounted at /userdir
# | |- test.txt
# |- my/
# |- cool/
# |- project/ # scuba root
# |- .scuba.yml

# Set up a subdir with a file to be read.
userdir = Path("./user")
userdir.mkdir(parents=True)

test_message = "Relative paths work"
(userdir / "test.txt").write_text(test_message)

# Set up a subdir for scuba
projdir = Path("my/cool/project")
projdir.mkdir(parents=True)

# Change to the project subdir and write the .scuba.yml file there.
os.chdir(projdir)
with open(".scuba.yml", "w") as f:
f.write(
f"""
image: {DOCKER_IMAGE}
volumes:
/userdir: ../../../{userdir}
"""
)

out, _ = self.run_scuba(["cat", "/userdir/test.txt"])
assert out == test_message

0 comments on commit c7082a2

Please sign in to comment.