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, pytest_config=MagicMock(), ) fixture.runner = MagicMock() fixture.runner.apply.return_value = tf.TerraformState({}, {}) request = MagicMock() fixture.create(request, MagicMock()) request.addfinalizer.assert_called()
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, ) state = tf.TerraformState({"one": 2}, {"three": 4}) fixture.runner = MagicMock() fixture.runner.apply.return_value = state fixture.create(MagicMock(), MagicMock()) tfstate_json = state.save() hook = pytest_config.hook.pytest_terraform_modify_state hook.assert_called_with(tfstate=tfstate_json)
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, pytest_config=MagicMock(), ) request = MagicMock() fixture.runner = MagicMock() fixture.runner.apply.return_value = tf.TerraformState({}, {}) fixture.runner.destroy.side_effect = [ subprocess.CalledProcessError(99, "test") ] fixture.create(request, MagicMock()) pytest.raises(tf.TerraformCommandFailed, fixture.tear_down)
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, pytest_config=MagicMock(), ) request = MagicMock() fixture.runner = MagicMock() fixture.runner.apply.return_value = tf.TerraformState({}, {}) fixture.runner.destroy.side_effect = [ subprocess.CalledProcessError(99, "test") ] fixture.create(request, MagicMock()) fixture.tear_down() request.addfinalizer.assert_called()