Ejemplo 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=[]),
    )
Ejemplo n.º 2
0
def test_medium_save_config(mock_home, global_text, local_text, config,
                            expected):
    global_config_file = mock_home / GLOBAL_CONFIG
    global_config_file.parent.mkdir(parents=True)
    if global_text:
        global_config_file.write_text(global_text)

    workspace = mock_home / "foo" / "bar"
    local_config_file = workspace / WORKSPACE_CONFIG
    local_config_file.parent.mkdir(parents=True)
    if local_text:
        local_config_file.write_text(local_text)

    config.root = workspace
    medium = TomlConfigurationMedium()
    medium.save_config(config)

    # Save function never touches the global config
    if not global_text:
        assert not global_config_file.exists()
    else:
        assert global_config_file.read_text() == global_text

    assert local_config_file.exists()
    assert local_config_file.read_text() == expected
Ejemplo n.º 3
0
def test_medium_generate_remote_directory(mock_home, workspace_config):
    medium = TomlConfigurationMedium()
    medium._global_config = GlobalConfig(general=GeneralConfig(
        allow_uninitiated_workspaces=False, remote_root="my-root-for-test"), )
    generated_dir = medium.generate_remote_directory(workspace_config)

    assert str(generated_dir).startswith("my-root-for-test/workspace_")
Ejemplo n.º 4
0
def test_medium_load_config_extension_overwrites_include_vsc_ignore_patterns(
        mock_home):
    global_config_file = mock_home / GLOBAL_CONFIG
    global_config_file.parent.mkdir(parents=True)
    global_config_file.write_text("""
[[hosts]]
host = "test-host.example.com"
default = true

[pull]
exclude = ["env"]
include_vsc_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("""
[extends.pull]
exclude = ["build"]
include_vsc_ignore_patterns = false
""")

    ignore_file = workspace / ".gitignore"
    ignore_file.write_text("*.pattern\npattern_two\n")

    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"))

    # config is loaded but no patterns are present
    assert config.ignores.pull == ["build", "env"]
Ejemplo n.º 5
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=[]),
    )
Ejemplo n.º 6
0
def test_medium_load_config_fails_on_no_hosts(mock_home):
    workspace = mock_home / "foo" / "bar"
    local_config_file = workspace / WORKSPACE_CONFIG
    local_config_file.parent.mkdir(parents=True)
    local_config_file.write_text("""\
[both]
exclude = []""")

    medium = TomlConfigurationMedium()

    with pytest.raises(ConfigurationError) as e:
        medium.load_config(workspace)

    assert str(
        e.value) == "You need to provide at least one remote host to connect"
Ejemplo n.º 7
0
def test_medium_load_config(mock_home, global_text, local_text, expected):
    global_config_file = mock_home / GLOBAL_CONFIG
    global_config_file.parent.mkdir(parents=True)
    if global_text:
        global_config_file.write_text(global_text)

    workspace = mock_home / "foo" / "bar"
    local_config_file = workspace / WORKSPACE_CONFIG
    local_config_file.parent.mkdir(parents=True)
    if local_text:
        local_config_file.write_text(local_text)

    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 == expected
Ejemplo n.º 8
0
def test_medium_is_workspace_root(mock_home):
    medium = TomlConfigurationMedium()
    global_config = GlobalConfig(general=GeneralConfig(
        allow_uninitiated_workspaces=False, remote_root="my-root-for-test"), )
    medium._global_config = global_config

    test_workspace = mock_home / "foo" / "bar"
    test_workspace.mkdir(parents=True)

    # No config - isn't workspace
    assert not medium.is_workspace_root(test_workspace)

    # Can find config - is workspace
    (test_workspace / WORKSPACE_CONFIG).write_text("[push]")
    assert medium.is_workspace_root(test_workspace)

    # No config, but uninitiated workspaces allowed - is workspace
    (test_workspace / WORKSPACE_CONFIG).unlink()
    global_config.general.allow_uninitiated_workspaces = True
    assert medium.is_workspace_root(test_workspace)