mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
Allowed variable to pass inside variables block (#1488)
Signed-off-by: siddharthasonker95 <158144589+siddharthasonker95@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
1fecaef9aa
commit
9138470a67
@@ -1132,48 +1132,13 @@ Condition expression could not be evaluated at this time.
|
||||
}
|
||||
|
||||
func TestTest_LocalVariables(t *testing.T) {
|
||||
td := t.TempDir()
|
||||
testCopyDir(t, testFixturePath(path.Join("test", "pass_with_local_variable")), td)
|
||||
defer testChdir(t, td)()
|
||||
|
||||
provider := testing_command.NewProvider(nil)
|
||||
|
||||
providerSource, close := newMockProviderSource(t, map[string][]string{
|
||||
"test": {"1.0.0"},
|
||||
})
|
||||
defer close()
|
||||
|
||||
streams, done := terminal.StreamsForTesting(t)
|
||||
view := views.NewView(streams)
|
||||
ui := new(cli.MockUi)
|
||||
|
||||
meta := Meta{
|
||||
testingOverrides: metaOverridesForProvider(provider.Provider),
|
||||
Ui: ui,
|
||||
View: view,
|
||||
Streams: streams,
|
||||
ProviderSource: providerSource,
|
||||
}
|
||||
|
||||
init := &InitCommand{
|
||||
Meta: meta,
|
||||
}
|
||||
|
||||
if code := init.Run(nil); code != 0 {
|
||||
t.Fatalf("expected status code 0 but got %d: %s", code, ui.ErrorWriter)
|
||||
}
|
||||
|
||||
c := &TestCommand{
|
||||
Meta: meta,
|
||||
}
|
||||
code := c.Run([]string{"-verbose", "-no-color"})
|
||||
output := done(t)
|
||||
|
||||
if code != 0 {
|
||||
t.Errorf("expected status code 0 but got %d", code)
|
||||
}
|
||||
|
||||
expected := `tests/test.tftest.hcl... pass
|
||||
tcs := map[string]struct {
|
||||
expected string
|
||||
code int
|
||||
skip bool
|
||||
}{
|
||||
"pass_with_local_variable": {
|
||||
expected: `tests/test.tftest.hcl... pass
|
||||
run "first"... pass
|
||||
|
||||
|
||||
@@ -1188,16 +1153,91 @@ OpenTofu has compared your real infrastructure against your configuration and
|
||||
found no differences, so no changes are needed.
|
||||
|
||||
Success! 2 passed, 0 failed.
|
||||
`
|
||||
`,
|
||||
code: 0,
|
||||
},
|
||||
"pass_var_inside_variables": {
|
||||
expected: `main.tftest.hcl... pass
|
||||
run "first"... pass
|
||||
|
||||
actual := output.All()
|
||||
|
||||
if diff := cmp.Diff(actual, expected); len(diff) > 0 {
|
||||
t.Errorf("output didn't match expected:\nexpected:\n%s\nactual:\n%s\ndiff:\n%s", expected, actual, diff)
|
||||
Outputs:
|
||||
|
||||
sss = "false"
|
||||
|
||||
Success! 1 passed, 0 failed.
|
||||
`,
|
||||
code: 0,
|
||||
},
|
||||
"pass_var_with_default_value_inside_variables": {
|
||||
expected: `main.tftest.hcl... pass
|
||||
run "first"... pass
|
||||
|
||||
|
||||
Outputs:
|
||||
|
||||
sss = "true"
|
||||
|
||||
Success! 1 passed, 0 failed.
|
||||
`,
|
||||
code: 0,
|
||||
},
|
||||
}
|
||||
|
||||
if provider.ResourceCount() > 0 {
|
||||
t.Errorf("should have deleted all resources on completion but left %v", provider.ResourceString())
|
||||
for name, tc := range tcs {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
if tc.skip {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
file := name
|
||||
|
||||
td := t.TempDir()
|
||||
testCopyDir(t, testFixturePath(path.Join("test", file)), td)
|
||||
defer testChdir(t, td)()
|
||||
|
||||
provider := testing_command.NewProvider(nil)
|
||||
providerSource, providerClose := newMockProviderSource(t, map[string][]string{
|
||||
"test": {"1.0.0"},
|
||||
})
|
||||
defer providerClose()
|
||||
|
||||
streams, done := terminal.StreamsForTesting(t)
|
||||
view := views.NewView(streams)
|
||||
ui := new(cli.MockUi)
|
||||
meta := Meta{
|
||||
testingOverrides: metaOverridesForProvider(provider.Provider),
|
||||
Ui: ui,
|
||||
View: view,
|
||||
Streams: streams,
|
||||
ProviderSource: providerSource,
|
||||
}
|
||||
|
||||
init := &InitCommand{
|
||||
Meta: meta,
|
||||
}
|
||||
|
||||
if code := init.Run(nil); code != 0 {
|
||||
t.Fatalf("expected status code 0 but got %d: %s", code, ui.ErrorWriter)
|
||||
}
|
||||
|
||||
command := &TestCommand{
|
||||
Meta: meta,
|
||||
}
|
||||
|
||||
code := command.Run([]string{"-verbose", "-no-color"})
|
||||
output := done(t)
|
||||
|
||||
if code != tc.code {
|
||||
t.Errorf("expected status code %d but got %d: %s", tc.code, code, output.All())
|
||||
}
|
||||
|
||||
actual := output.All()
|
||||
|
||||
if diff := cmp.Diff(actual, tc.expected); len(diff) > 0 {
|
||||
t.Errorf("output didn't match expected:\nexpected:\n%s\nactual:\n%s\ndiff:\n%s", tc.expected, actual, diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user