restructure existing test

pull/35903/head
Daniel Schmidt 2 years ago
parent 79a35f3968
commit f4ff263d24
No known key found for this signature in database
GPG Key ID: 377C3A4D62FBBBE2

@ -23,12 +23,14 @@ import (
"github.com/hashicorp/terraform/internal/addrs"
"github.com/hashicorp/terraform/internal/collections"
"github.com/hashicorp/terraform/internal/command/views"
"github.com/hashicorp/terraform/internal/configs/configschema"
"github.com/hashicorp/terraform/internal/plans"
"github.com/hashicorp/terraform/internal/providers"
testing_provider "github.com/hashicorp/terraform/internal/providers/testing"
"github.com/hashicorp/terraform/internal/states"
"github.com/hashicorp/terraform/internal/states/statemgr"
"github.com/hashicorp/terraform/internal/terminal"
"github.com/hashicorp/terraform/internal/tfdiags"
)
@ -992,65 +994,78 @@ func TestApply_planVarsEphemeral_applyTime(t *testing.T) {
statePath := testTempFile(t)
p := applyFixtureProvider()
view, done := testView(t)
c := &ApplyCommand{
Meta: Meta{
testingOverrides: metaOverridesForProvider(p),
View: view,
},
}
var view *views.View
var done func(t *testing.T) *terminal.TestOutput
var c *ApplyCommand
var args []string
var code int
var output *terminal.TestOutput
// Test first that an apply supplying only the apply-time variable "foo"
// succeeds.
args := []string{
"-state", statePath,
"-var", "foo=bar",
planPath,
}
code := c.Run(args)
output := done(t)
if code != 0 {
t.Fatal("should've succeeded: ", output.Stderr())
}
t.Run("only passing ephemeral variable", func(t *testing.T) {
view, done = testView(t)
c = &ApplyCommand{
Meta: Meta{
testingOverrides: metaOverridesForProvider(p),
View: view,
},
}
args = []string{
"-state", statePath,
"-var", "foo=bar",
planPath,
}
code = c.Run(args)
output = done(t)
if code != 0 {
t.Fatal("should've succeeded: ", output.Stderr())
}
})
// Now test that supplying "bar", which is not an apply-time variable, fails.
view, done = testView(t)
c = &ApplyCommand{
Meta: Meta{
testingOverrides: metaOverridesForProvider(p),
View: view,
},
}
args = []string{
"-state", statePath,
"-var", "foo=bar",
"-var", "bar=bar",
planPath,
}
code = c.Run(args)
output = done(t)
if code == 0 {
t.Fatal("should've failed: ", output.Stdout())
}
t.Run("passing non-ephemeral variable", func(t *testing.T) {
view, done = testView(t)
c = &ApplyCommand{
Meta: Meta{
testingOverrides: metaOverridesForProvider(p),
View: view,
},
}
args = []string{
"-state", statePath,
"-var", "foo=bar",
"-var", "bar=bar",
planPath,
}
code = c.Run(args)
output = done(t)
if code == 0 {
t.Fatal("should've failed: ", output.Stdout())
}
})
// Finally, test that the apply also fails if we do *not* supply a value for
// the apply-time variable foo.
view, done = testView(t)
c = &ApplyCommand{
Meta: Meta{
testingOverrides: metaOverridesForProvider(p),
View: view,
},
}
args = []string{
"-state", statePath,
planPath,
}
code = c.Run(args)
output = done(t)
if code == 0 {
t.Fatal("should've failed: ", output.Stdout())
}
t.Run("missing ephemeral variable", func(t *testing.T) {
view, done = testView(t)
c = &ApplyCommand{
Meta: Meta{
testingOverrides: metaOverridesForProvider(p),
View: view,
},
}
args = []string{
"-state", statePath,
planPath,
}
code = c.Run(args)
output = done(t)
if code == 0 {
t.Fatal("should've failed: ", output.Stdout())
}
})
}
// we should be able to apply a plan file with no other file dependencies

Loading…
Cancel
Save