Esempio n. 1
0
def test_medium_load_config_no_directory(mock_home):
    global_config_file = mock_home / GLOBAL_CONFIG
    global_config_file.parent.mkdir(parents=True)
    global_config_file.write_text(
        """
    [general]
allow_uninitiated_workspaces = true
remote_root = "my-remotes"

[[hosts]]
host = "test-host.example.com"
"""
    )
    workspace = mock_home / "foo" / "bar"

    medium = TomlConfigurationMedium()
    config = medium.load_config(workspace)
    # The path is randomly generated so we need to replace it
    config.root = Path(str(config.root).replace(str(mock_home), "/root"))

    assert config == WorkspaceConfig(
        root=Path("/root/foo/bar"),
        configurations=[
            RemoteConfig(
                host="test-host.example.com",
                directory=Path(f"my-remotes/bar_{hash_path(workspace)}"),
                shell="sh",
                shell_options="",
            )
        ],
        default_configuration=0,
        ignores=SyncRules(pull=[], push=[], both=[".remote.toml"]),
        includes=SyncRules(pull=[], push=[], both=[]),
    )
Esempio n. 2
0
def test_medium_load_config_picks_up_vsc_ignore_files(mock_home):
    text = """
[[hosts]]
host = "test-host.example.com"
port = 2022
directory = ".remotes/workspace"
default = true

[push]
exclude = ["env", ".git"]

[pull]
include_vsc_ignore_patterns = true

[both]
exclude = ["build"]
include_vcs_ignore_patterns = true
"""
    workspace = mock_home / "foo" / "bar"
    local_config_file = workspace / WORKSPACE_CONFIG
    local_config_file.parent.mkdir(parents=True)
    local_config_file.write_text(text)

    ignore_file = workspace / ".gitignore"
    ignore_file.write_text("""
# comment
# Comment
*.pattern

# comment

pattern_two

""")

    medium = TomlConfigurationMedium()

    config = medium.load_config(workspace)

    # The path is randomly generated so we need to replace it
    config.root = Path(str(config.root).replace(str(mock_home), "/root"))

    assert config == WorkspaceConfig(
        root=Path("/root/foo/bar"),
        configurations=[
            RemoteConfig(host="test-host.example.com",
                         directory=Path(".remotes/workspace"),
                         port=2022)
        ],
        default_configuration=0,
        ignores=SyncRules(
            pull=["*.pattern", "pattern_two"],
            push=[".git", "env"],
            both=["build", ".remote.toml", "*.pattern", "pattern_two"],
        ),
        includes=SyncRules(pull=[], push=[], both=[]),
    )
Esempio n. 3
0
def workspace_config(tmp_path):
    # a workspace with one remote host and all default values
    workspace_root = tmp_path / "workspace"
    workspace_root.mkdir()
    config = WorkspaceConfig.empty(workspace_root)
    config.configurations.append(
        RemoteConfig(host="test-host.example.com", directory=Path("remote/dir"), shell="sh", shell_options="")
    )
    return config
Esempio n. 4
0
def test_add_host_to_workspace(tmp_path):
    config = WorkspaceConfig.empty(tmp_path)
    added, index = config.add_remote_host("test-host", Path("remote/dir"))
    assert added
    assert index == 0
    assert config.default_configuration == 0
    assert len(config.configurations) == 1
    assert config.configurations[0] == RemoteConfig(
        host="test-host",
        directory=Path("remote/dir"),
        shell="sh",
        shell_options="")
Esempio n. 5
0
[push]
exclude = ["env", ".git"]
include = ["env"]

[pull]
exclude = ["src/generated"]

[both]
exclude = ["build"]
""",
            None,
            WorkspaceConfig(
                root=Path("/root/foo/bar"),
                configurations=[
                    RemoteConfig(host="test-host.example.com", directory=Path("my-remotes/foo/bar",), label="bar"),
                    RemoteConfig(host="other-host.example.com", directory=Path("my-remotes/foo/bar"), label="foo"),
                ],
                default_configuration=1,
                ignores=SyncRules(pull=["src/generated"], push=[".git", "env"], both=["build", ".remote.toml"]),
                includes=SyncRules(pull=[], push=["env"], both=[]),
            ),
        ),
        # Settings from local config overwrite global ones
        (
            """\
[general]
use_relative_remote_paths = true

[[hosts]]
host = "other-host.example.com"
default = true
label = "bar"