isothrum-runner 3.0.1

The Isothrum runner: runs a Compose project, a Vagrantfile or a Terraform module through its own tool (lifecycle, state and locks, the format drivers, events).
Documentation
//! A module's resource removed by its recorded id.

use super::*;

/// Removes the module's `aws_instance.vm`, recorded with id `i-1`.
async fn destroy_the_vm(stack: &Stack, fake: &FakeProcesses) -> Result<()> {
    with_cx(stack, fake, async |cx| {
        Terraform.destroy_by_id(cx, "aws_instance.vm", ResourceKind::Vm, "i-1").await
    })
    .await
}

#[tokio::test]
async fn destroy_by_id_targets_an_instance_the_state_holds() {
    let stack = stack().with_state();
    let fake = FakeProcesses::script()
        .expect("terraform init", Reply::ok(""))
        .expect("terraform show -json", Reply::ok(&show_of(&[("aws_instance", "vm", "i-1", false)])))
        .expect(
            &format!(
                "terraform destroy -auto-approve -input=false -json {} -target=aws_instance.vm",
                stack.state_flag()
            ),
            Reply::ok(DESTROYED_ONE),
        )
        .build();
    destroy_the_vm(&stack, &fake).await.expect("destroyed");
}

#[tokio::test]
async fn destroy_by_id_imports_an_instance_the_state_lost_first() {
    let stack = stack();
    let fake = FakeProcesses::script()
        .expect("terraform init", Reply::ok(""))
        .expect(
            &format!("terraform import -input=false -no-color {} aws_instance.vm i-1", stack.state_flag()),
            Reply::ok(""),
        )
        .expect("terraform destroy -auto-approve -input=false -json", Reply::ok(DESTROYED_ONE))
        .build();
    destroy_the_vm(&stack, &fake).await.expect("destroyed");
}

#[tokio::test]
async fn destroy_by_id_of_an_object_already_gone_is_done() {
    let stack = stack();
    let fake = FakeProcesses::script()
        .expect("terraform init", Reply::ok(""))
        .expect("terraform import", Reply::fail(1, "Error: Cannot import non-existent remote object"))
        .build();
    with_cx(&stack, &fake, async |cx| {
        Terraform.destroy_by_id(cx, "aws_instance.vm", ResourceKind::Vm, "i-1").await
    })
    .await
    .expect("nothing there is fine");
}

#[tokio::test]
async fn destroy_by_id_of_an_object_the_state_replaced_is_refused() {
    let stack = stack().with_state();
    let fake = FakeProcesses::script()
        .expect("terraform init", Reply::ok(""))
        .expect("terraform show -json", Reply::ok(&show_of(&[("aws_instance", "vm", "i-2", false)])))
        .build();
    let e = with_cx(&stack, &fake, async |cx| {
        Terraform.destroy_by_id(cx, "aws_instance.vm", ResourceKind::Vm, "i-1").await
    })
    .await
    .expect_err("another object");
    assert_eq!(e.code(), ErrorCode::Unsupported);
}