Exemplo n.º 1
0
def test_tf_teardown_register():
    fixture = tf.TerraformFixture(
        tf_bin="fakebin",
        plugin_cache="fakecache",
        scope="function",
        tf_root_module="fakeroot",
        test_dir="fakedir",
        replay=False,
        teardown=tf.td.ON,
    )

    fixture.runner = MagicMock()
    request = MagicMock()

    fixture.create(request, MagicMock())

    request.addfinalizer.assert_called()
Exemplo n.º 2
0
def test_tf_skip_teardown_register():
    fixture = tf.TerraformFixture(
        tf_bin="fakebin",
        plugin_cache="fakecache",
        scope="function",
        tf_root_module="fakeroot",
        test_dir="fakedir",
        replay=False,
        teardown=tf.td.OFF,
        pytest_config=MagicMock(),
    )

    request = MagicMock()
    fixture.runner = MagicMock()
    fixture.runner.apply.return_value = tf.TerraformState({}, {})

    fixture.create(request, MagicMock())

    request.addfinalizer.assert_not_called()
Exemplo n.º 3
0
def test_tf_hook_modify_state():
    pytest_config = MagicMock()
    fixture = tf.TerraformFixture(
        tf_bin="fakebin",
        plugin_cache="fakecache",
        scope="function",
        tf_root_module="fakeroot",
        test_dir="fakedir",
        replay=False,
        teardown=tf.td.DEFAULT,
        pytest_config=pytest_config,
    )

    fixture.runner = MagicMock()
    fixture.create(MagicMock(), MagicMock())

    tfstate_json = fixture.runner.apply.return_value.save.return_value
    hook = pytest_config.hook.pytest_terraform_modify_state
    hook.assert_called_with(tfstate=tfstate_json)
Exemplo n.º 4
0
def test_tf_teardown_exception():
    import subprocess

    fixture = tf.TerraformFixture(
        tf_bin="fakebin",
        plugin_cache="fakecache",
        scope="function",
        tf_root_module="fakeroot",
        test_dir="fakedir",
        replay=False,
        teardown=tf.td.ON,
    )

    request = MagicMock()
    fixture.runner = MagicMock()
    fixture.runner.destroy.side_effect = [
        subprocess.CalledProcessError(99, "test")
    ]

    fixture.create(request, MagicMock())
    pytest.raises(tf.TerraformCommandFailed, fixture.tear_down)
Exemplo n.º 5
0
def test_tf_teardown_register_ignore():

    fixture = tf.TerraformFixture(
        tf_bin="fakebin",
        plugin_cache="fakecache",
        scope="function",
        tf_root_module="fakeroot",
        test_dir="fakedir",
        replay=False,
        teardown=tf.td.IGNORE,
    )

    request = MagicMock()
    fixture.runner = MagicMock()
    fixture.runner.destroy.side_effect = [
        subprocess.CalledProcessError(99, "test")
    ]

    fixture.create(request, MagicMock())
    fixture.tear_down()

    request.addfinalizer.assert_called()