예제 #1
0
def test_parse_args_init_backend_false():  # noqa: D103
    args = tfwrapper.parse_args(["init", "--backend", "false"])
    assert args.subcommand == "init"
    assert args.func == tfwrapper.terraform_init
    assert args.backend == "false"

    args = tfwrapper.parse_args(["init", "--backend=false"])
    assert args.subcommand == "init"
    assert args.func == tfwrapper.terraform_init
    assert args.backend == "false"
예제 #2
0
def test_parse_args_init_plugin_cache_dir_arg(monkeypatch):  # noqa: D103
    monkeypatch.delenv("TF_PLUGIN_CACHE_DIR", raising=False)
    args = tfwrapper.parse_args(
        ["--plugin-cache-dir=/tmp/plugin-cache-dir", "init"])
    assert args.subcommand == "init"
    assert args.func == tfwrapper.terraform_init
    assert args.plugin_cache_dir == "/tmp/plugin-cache-dir"
예제 #3
0
def test_parse_args_init_plugin_cache_dir_default(monkeypatch):  # noqa: D103
    monkeypatch.delenv("TF_PLUGIN_CACHE_DIR", raising=False)
    args = tfwrapper.parse_args(["init"])
    assert args.subcommand == "init"
    assert args.func == tfwrapper.terraform_init
    assert args.plugin_cache_dir == "{}/.terraform.d/plugin-cache".format(
        home_dir)
예제 #4
0
def test_parse_args_foreach_command(monkeypatch):  # noqa: D103
    monkeypatch.setenv("SHELL", "mybash")
    args = tfwrapper.parse_args(["foreach", "--", "ls", "-l"])
    assert args.subcommand == "foreach"
    assert args.func == tfwrapper.foreach
    assert args.shell is False
    assert args.executable is None
    assert args.command == ["ls", "-l"]
예제 #5
0
def test_parse_args_foreach_command_shell(monkeypatch):  # noqa: D103
    monkeypatch.setenv("SHELL", "mybash")
    args = tfwrapper.parse_args(["foreach", "-c", "ls -l | head -1"])
    assert args.subcommand == "foreach"
    assert args.func == tfwrapper.foreach
    assert args.shell is True
    assert args.executable == "mybash"
    assert args.command == ["ls -l | head -1"]
예제 #6
0
def test_config_load_help():  # noqa: D103
    with pytest.raises(SystemExit) as e:
        tfwrapper.parse_args([])
    assert e.value.code == 0
예제 #7
0
def test_parse_args_foreach_command_shell_too_many_args():  # noqa: D103
    with pytest.raises(ValueError) as e:
        tfwrapper.parse_args(["foreach", "-c", "ls", "-l"])
    assert str(
        e.value
    ) == "foreach: error: -c must be followed by a single argument (hint: use quotes)"
예제 #8
0
def test_parse_args_foreach_shell_no_args():  # noqa: D103
    with pytest.raises(ValueError) as e:
        tfwrapper.parse_args(["foreach", "-c"])
    assert str(e.value) == "foreach: error: a command is required"
예제 #9
0
def test_parse_args_foreach_help(capsys):  # noqa: D103
    with pytest.raises(SystemExit) as e:
        tfwrapper.parse_args(["foreach", "-h"])
    assert e.value.code == 0
    captured = capsys.readouterr()
    assert "usage: tfwrapper foreach [-h] [-c] ..." in captured.out
예제 #10
0
def test_parse_args_init_no_args():  # noqa: D103
    args = tfwrapper.parse_args(["init"])
    assert args.subcommand == "init"
    assert args.func == tfwrapper.terraform_init
    assert args.backend == "true"
예제 #11
0
def test_parse_args_init_help(capsys):  # noqa: D103
    with pytest.raises(SystemExit) as e:
        tfwrapper.parse_args(["init", "-h"])
    assert e.value.code == 0
    captured = capsys.readouterr()
    assert "usage: tfwrapper init [-h] [--backend {true,false}] ..." in captured.out
예제 #12
0
def test_parse_args_no_args(capsys):  # noqa: D103
    with pytest.raises(SystemExit) as e:
        tfwrapper.parse_args([])
    assert e.value.code == 0
    captured = capsys.readouterr()
    assert "usage: tfwrapper [-h] [-d] [-V] [-c CONFDIR] [-a [ACCOUNT]]" in captured.err
예제 #13
0
def test_parse_args_version(capsys):  # noqa: D103
    with pytest.raises(SystemExit) as e:
        tfwrapper.parse_args(["-V"])
    assert e.value.code == 0
    captured = capsys.readouterr()
    assert re.match(r"^tfwrapper v\d+\.\d+\.\d+", captured.err)
예제 #14
0
def test_parse_args_http_cache_dir():  # noqa: D103
    args = tfwrapper.parse_args(["--http-cache-dir", ".webcache", "init"])
    assert args.subcommand == "init"
    assert args.func == tfwrapper.terraform_init
    assert args.http_cache_dir == ".webcache"