Exemplo n.º 1
0
def test_medium_load_config_ingore_configuration_error(tmp_path):
    (tmp_path / CONFIG_FILE_NAME).write_text("test-host.example.com:remote/dir")
    (tmp_path / IGNORE_FILE_NAME).write_text("one\ntwo\nthree\nboth:\nbuild")
    medium = ClassicConfigurationMedium()

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

    assert "Few ignore patters were listed in .remoteignore before the first section both appeared" in str(e.value)
Exemplo n.º 2
0
def test_medium_load_config_connections_configuration_error(tmp_path):
    medium = ClassicConfigurationMedium()

    # Config is malformed
    (tmp_path / CONFIG_FILE_NAME).write_text("some-host")
    with pytest.raises(ConfigurationError) as e:
        medium.load_config(tmp_path)

    assert "The configuration string is malformed" in str(e.value)

    # Some unsupported env variables
    (tmp_path / CONFIG_FILE_NAME).write_text("some-host:some/dir SOME_ENV=123")
    with pytest.raises(ConfigurationError) as e:
        medium.load_config(tmp_path)

    assert "Config line some-host:some/dir SOME_ENV=123 contains unexpected env variables" in str(e.value)
Exemplo n.º 3
0
def test_medium_load_config_index_configuration_error(tmp_path, monkeypatch):
    (tmp_path /
     CONFIG_FILE_NAME).write_text("test-host.example.com:remote/dir")
    medium = ClassicConfigurationMedium()

    # Index is too big
    (tmp_path / INDEX_FILE_NAME).write_text("2")
    with pytest.raises(ConfigurationError) as e:
        medium.load_config(tmp_path)

    assert "Configuration #2 requested but there are only 1 declared" in str(
        e.value)

    # Index is not a number
    (tmp_path / INDEX_FILE_NAME).write_text("d")
    with pytest.raises(ConfigurationError) as e:
        medium.load_config(tmp_path)

    assert "remoteindex contains symbols other than numbers: 'd'" in str(
        e.value)

    # Index is not a number in env variable
    monkeypatch.setenv("REMOTE_HOST_INDEX", "a")
    with pytest.raises(ConfigurationError) as e:
        medium.load_config(tmp_path)

    assert "REMOTE_HOST_INDEX env variable contains symbols other than numbers: 'a'" in str(
        e.value)
Exemplo n.º 4
0
def test_medium_load_extensive_config(tmp_path):
    (tmp_path / CONFIG_FILE_NAME).write_text("""\
# First host
test-host.example.com:remote/dir

# Second host
other-host.example.com:other/dir RSHELL=bash RSHELL_OPTS=options

# Third host
third-host.example.com:.remote/dir RSHELL=zsh
""")
    (tmp_path / INDEX_FILE_NAME).write_text("3")
    (tmp_path / IGNORE_FILE_NAME).write_text(f"""\

push:
.git
*.pyc
__pycache__

pull:
src/generated

both:
build
{CONFIG_FILE_NAME}
{IGNORE_FILE_NAME}
""")
    medium = ClassicConfigurationMedium()

    config = medium.load_config(tmp_path)
    assert config.root == tmp_path
    assert config.default_configuration == 2
    assert len(config.configurations) == 3
    assert config.configurations == [
        RemoteConfig(host="test-host.example.com",
                     directory=Path("remote/dir"),
                     shell="sh",
                     shell_options=""),
        RemoteConfig(host="other-host.example.com",
                     directory=Path("other/dir"),
                     shell="bash",
                     shell_options="options"),
        RemoteConfig(host="third-host.example.com",
                     directory=Path(".remote/dir"),
                     shell="zsh",
                     shell_options=""),
    ]
    assert config.ignores == SyncIgnores(
        pull=["src/generated"],
        push=[".git", "*.pyc", "__pycache__"],
        both=["build", CONFIG_FILE_NAME, IGNORE_FILE_NAME, INDEX_FILE_NAME],
    )
Exemplo n.º 5
0
def test_medium_load_minimal_config(tmp_path):
    (tmp_path / CONFIG_FILE_NAME).write_text("test-host.example.com:remote/dir")
    medium = ClassicConfigurationMedium()

    config = medium.load_config(tmp_path)
    assert config.root == tmp_path
    assert config.default_configuration == 0
    assert len(config.configurations) == 1
    assert config.configurations[0] == RemoteConfig(
        host="test-host.example.com", directory=Path("remote/dir"), shell="sh", shell_options=""
    )
    # Ignore is always pre-populated even if it's empy in FS
    assert config.ignores == SyncRules(pull=[], push=[], both=[CONFIG_FILE_NAME, IGNORE_FILE_NAME, INDEX_FILE_NAME])