mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
add command test for errored plan
This commit is contained in:
parent
bb5f360747
commit
76d5e4a9cb
@ -18,6 +18,7 @@ import (
|
||||
|
||||
"github.com/hashicorp/terraform/internal/addrs"
|
||||
backendinit "github.com/hashicorp/terraform/internal/backend/init"
|
||||
"github.com/hashicorp/terraform/internal/checks"
|
||||
"github.com/hashicorp/terraform/internal/configs/configschema"
|
||||
"github.com/hashicorp/terraform/internal/plans"
|
||||
"github.com/hashicorp/terraform/internal/providers"
|
||||
@ -275,6 +276,54 @@ func TestPlan_outPathNoChange(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlan_outPathWithError(t *testing.T) {
|
||||
td := t.TempDir()
|
||||
testCopyDir(t, testFixturePath("plan-fail-condition"), td)
|
||||
defer testChdir(t, td)()
|
||||
|
||||
outPath := filepath.Join(td, "test.plan")
|
||||
|
||||
p := planFixtureProvider()
|
||||
view, done := testView(t)
|
||||
c := &PlanCommand{
|
||||
Meta: Meta{
|
||||
testingOverrides: metaOverridesForProvider(p),
|
||||
View: view,
|
||||
},
|
||||
}
|
||||
|
||||
p.PlanResourceChangeResponse = &providers.PlanResourceChangeResponse{
|
||||
PlannedState: cty.NullVal(cty.EmptyObject),
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"-out", outPath,
|
||||
}
|
||||
code := c.Run(args)
|
||||
output := done(t)
|
||||
if code == 0 {
|
||||
t.Fatal("expected non-zero exit status", output)
|
||||
}
|
||||
|
||||
plan := testReadPlan(t, outPath) // will call t.Fatal itself if the file cannot be read
|
||||
if !plan.Errored {
|
||||
t.Fatal("plan should be marked with Errored")
|
||||
}
|
||||
|
||||
if plan.Checks == nil {
|
||||
t.Fatal("plan contains no checks")
|
||||
}
|
||||
|
||||
// the checks should only contain one failure
|
||||
results := plan.Checks.ConfigResults.Elements()
|
||||
if len(results) != 1 {
|
||||
t.Fatal("incorrect number of check results", len(results))
|
||||
}
|
||||
if results[0].Value.Status != checks.StatusFail {
|
||||
t.Errorf("incorrect status, got %s", results[0].Value.Status)
|
||||
}
|
||||
}
|
||||
|
||||
// When using "-out" with a backend, the plan should encode the backend config
|
||||
func TestPlan_outBackend(t *testing.T) {
|
||||
// Create a temporary working directory that is empty
|
||||
|
15
internal/command/testdata/plan-fail-condition/main.tf
vendored
Normal file
15
internal/command/testdata/plan-fail-condition/main.tf
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
locals {
|
||||
ami = "bar"
|
||||
}
|
||||
|
||||
resource "test_instance" "foo" {
|
||||
ami = local.ami
|
||||
|
||||
lifecycle {
|
||||
precondition {
|
||||
// failing condition
|
||||
condition = local.ami != "bar"
|
||||
error_message = "ami is bar"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user