2022-10-20 03:24:27 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from lightning_app.storage.mount import Mount
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_s3_mount_successfully():
|
2022-10-20 21:33:35 +00:00
|
|
|
mount = Mount(source="s3://foo/bar/", mount_path="/foo")
|
2022-10-20 03:24:27 +00:00
|
|
|
assert mount.source == "s3://foo/bar/"
|
2022-10-20 21:33:35 +00:00
|
|
|
assert mount.mount_path == "/foo"
|
2022-10-20 03:24:27 +00:00
|
|
|
assert mount.protocol == "s3://"
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_non_s3_mount_fails():
|
|
|
|
with pytest.raises(ValueError, match="Unknown protocol for the mount 'source' argument"):
|
2022-10-20 21:33:35 +00:00
|
|
|
Mount(source="foo/bar/", mount_path="/foo")
|
2022-10-20 03:24:27 +00:00
|
|
|
|
|
|
|
with pytest.raises(ValueError, match="Unknown protocol for the mount 'source' argument"):
|
2022-10-20 21:33:35 +00:00
|
|
|
Mount(source="gcs://foo/bar/", mount_path="/foo")
|
2022-10-20 03:24:27 +00:00
|
|
|
|
|
|
|
with pytest.raises(ValueError, match="Unknown protocol for the mount 'source' argument"):
|
2022-10-20 21:33:35 +00:00
|
|
|
Mount(source="3://foo/bar/", mount_path="/foo")
|
2022-10-20 03:24:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_create_s3_mount_without_directory_prefix_fails():
|
|
|
|
with pytest.raises(ValueError, match="S3 mounts must end in a trailing slash"):
|
2022-10-20 21:33:35 +00:00
|
|
|
Mount(source="s3://foo/bar", mount_path="/foo")
|
2022-10-20 03:24:27 +00:00
|
|
|
|
|
|
|
with pytest.raises(ValueError, match="S3 mounts must end in a trailing slash"):
|
2022-10-20 21:33:35 +00:00
|
|
|
Mount(source="s3://foo", mount_path="/foo")
|
2022-10-20 03:24:27 +00:00
|
|
|
|
|
|
|
|
2022-10-20 21:33:35 +00:00
|
|
|
def test_create_mount_without_mount_path_argument():
|
2022-10-20 03:24:27 +00:00
|
|
|
m = Mount(source="s3://foo/")
|
2022-10-20 21:33:35 +00:00
|
|
|
assert m.mount_path == "/data/foo"
|
2022-10-20 03:24:27 +00:00
|
|
|
|
|
|
|
m = Mount(source="s3://foo/bar/")
|
2022-10-20 21:33:35 +00:00
|
|
|
assert m.mount_path == "/data/bar"
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_mount_path_with_relative_path_errors():
|
|
|
|
with pytest.raises(ValueError, match="mount_path argument must be an absolute path"):
|
|
|
|
Mount(source="s3://foo/", mount_path="./doesnotwork")
|