mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
Fix for tofu init failure when test have spaces in their name (#1489)
Signed-off-by: siddharthasonker95 <158144589+siddharthasonker95@users.noreply.github.com> Signed-off-by: Christian Mesh <christianmesh1@gmail.com> Co-authored-by: Christian Mesh <christianmesh1@gmail.com>
This commit is contained in:
committed by
GitHub
parent
34eac2e2da
commit
de30707b6b
@@ -7,6 +7,7 @@ NEW FEATURES:
|
||||
ENHANCEMENTS:
|
||||
|
||||
BUG FIXES:
|
||||
* Added a check in the `tofu test` to validate that the names of test run blocks do not contain spaces. ([#1489](https://github.com/opentofu/opentofu/pull/1489))
|
||||
|
||||
## Previous Releases
|
||||
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
run "test 01" { command = plan }
|
||||
run "test 02" { command = plan }
|
||||
run "test 03" { command = plan }
|
||||
run "test 04" { command = plan }
|
||||
run "test 05" { command = plan }
|
||||
run "test 06" { command = plan }
|
||||
run "test 07" { command = plan }
|
||||
run "test 08" { command = plan }
|
||||
run "test 09" { command = plan }
|
||||
run "test 10" { command = plan }
|
||||
run "test 11" { command = plan }
|
||||
run "test 12" { command = plan }
|
||||
run "test 13" { command = plan }
|
||||
run "test 14" { command = plan }
|
||||
run "test 15" { command = plan }
|
||||
run "test 16" { command = plan }
|
||||
run "test 17" { command = plan }
|
||||
run "test 18" { command = plan }
|
||||
run "test 19" { command = plan }
|
||||
run "test 20" { command = plan }
|
||||
run "test 21" { command = plan }
|
||||
run "test 22" { command = plan }
|
||||
run "test 23" { command = plan }
|
||||
run "test 24" { command = plan }
|
||||
run "test 25" { command = plan }
|
||||
run "test 26" { command = plan }
|
||||
run "test 27" { command = plan }
|
||||
run "test 28" { command = plan }
|
||||
run "test 29" { command = plan }
|
||||
run "test 30" { command = plan }
|
||||
run "test_01" { command = plan }
|
||||
run "test_02" { command = plan }
|
||||
run "test_03" { command = plan }
|
||||
run "test_04" { command = plan }
|
||||
run "test_05" { command = plan }
|
||||
run "test_06" { command = plan }
|
||||
run "test_07" { command = plan }
|
||||
run "test_08" { command = plan }
|
||||
run "test_09" { command = plan }
|
||||
run "test_10" { command = plan }
|
||||
run "test_11" { command = plan }
|
||||
run "test_12" { command = plan }
|
||||
run "test_13" { command = plan }
|
||||
run "test_14" { command = plan }
|
||||
run "test_15" { command = plan }
|
||||
run "test_16" { command = plan }
|
||||
run "test_17" { command = plan }
|
||||
run "test_18" { command = plan }
|
||||
run "test_19" { command = plan }
|
||||
run "test_20" { command = plan }
|
||||
run "test_21" { command = plan }
|
||||
run "test_22" { command = plan }
|
||||
run "test_23" { command = plan }
|
||||
run "test_24" { command = plan }
|
||||
run "test_25" { command = plan }
|
||||
run "test_26" { command = plan }
|
||||
run "test_27" { command = plan }
|
||||
run "test_28" { command = plan }
|
||||
run "test_29" { command = plan }
|
||||
run "test_30" { command = plan }
|
||||
|
||||
@@ -254,7 +254,7 @@ func TestTest_Full_Output(t *testing.T) {
|
||||
code: 1,
|
||||
},
|
||||
"is_sorted": {
|
||||
expected: "1.tftest.hcl... pass\n run \"1\"... pass\n2.tftest.hcl... pass\n run \"2\"... pass\n3.tftest.hcl... pass\n run \"3\"... pass",
|
||||
expected: "1.tftest.hcl... pass\n run \"a\"... pass\n2.tftest.hcl... pass\n run \"b\"... pass\n3.tftest.hcl... pass\n run \"c\"... pass",
|
||||
code: 0,
|
||||
args: []string{"-no-color"},
|
||||
},
|
||||
@@ -1196,3 +1196,63 @@ Success! 2 passed, 0 failed.
|
||||
t.Errorf("should have deleted all resources on completion but left %v", provider.ResourceString())
|
||||
}
|
||||
}
|
||||
|
||||
func TestTest_RunBlock(t *testing.T) {
|
||||
tcs := map[string]struct {
|
||||
expected string
|
||||
code int
|
||||
skip bool
|
||||
}{
|
||||
"invalid_run_block_name": {
|
||||
expected: `
|
||||
Error: Invalid run block name
|
||||
|
||||
on tests/main.tftest.hcl line 1, in run "sample run":
|
||||
1: run "sample run" {
|
||||
|
||||
A name must start with a letter or underscore and may contain only letters,
|
||||
digits, underscores, and dashes.
|
||||
`,
|
||||
code: 1,
|
||||
},
|
||||
}
|
||||
|
||||
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, close := newMockProviderSource(t, map[string][]string{
|
||||
"test": {"1.0.0"},
|
||||
})
|
||||
defer close()
|
||||
|
||||
streams, _ := 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 != tc.code {
|
||||
t.Fatalf("expected status code 0 but got %d: %s", code, ui.ErrorWriter)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
3
internal/command/testdata/test/invalid_run_block_name/main.tf
vendored
Normal file
3
internal/command/testdata/test/invalid_run_block_name/main.tf
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
provider "test" {
|
||||
value = "foo"
|
||||
}
|
||||
5
internal/command/testdata/test/invalid_run_block_name/tests/main.tftest.hcl
vendored
Normal file
5
internal/command/testdata/test/invalid_run_block_name/tests/main.tftest.hcl
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
run "sample run" {
|
||||
module {
|
||||
source = "./.."
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
run "1" {
|
||||
run "a" {
|
||||
assert {
|
||||
condition = test_resource.resource.value == null
|
||||
error_message = "should pass"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
run "2" {
|
||||
run "b" {
|
||||
assert {
|
||||
condition = test_resource.resource.value == null
|
||||
error_message = "should pass"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
run "3" {
|
||||
run "c" {
|
||||
assert {
|
||||
condition = test_resource.resource.value == null
|
||||
error_message = "should pass"
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/hashicorp/hcl/v2"
|
||||
"github.com/hashicorp/hcl/v2/gohcl"
|
||||
"github.com/hashicorp/hcl/v2/hclsyntax"
|
||||
|
||||
"github.com/opentofu/opentofu/internal/addrs"
|
||||
"github.com/opentofu/opentofu/internal/getmodules"
|
||||
@@ -252,6 +253,16 @@ func decodeTestRunBlock(block *hcl.Block) (*TestRun, hcl.Diagnostics) {
|
||||
NameDeclRange: block.LabelRanges[0],
|
||||
DeclRange: block.DefRange,
|
||||
}
|
||||
|
||||
if !hclsyntax.ValidIdentifier(r.Name) {
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
Severity: hcl.DiagError,
|
||||
Summary: "Invalid run block name",
|
||||
Detail: badIdentifierDetail,
|
||||
Subject: &block.LabelRanges[0],
|
||||
})
|
||||
}
|
||||
|
||||
for _, block := range content.Blocks {
|
||||
switch block.Type {
|
||||
case "assert":
|
||||
|
||||
@@ -11,7 +11,7 @@ provider "bar" {
|
||||
|
||||
run "default_should_be_fine" {}
|
||||
|
||||
run "bit_complicated_still_okay "{
|
||||
run "bit_complicated_still_okay"{
|
||||
|
||||
providers = {
|
||||
foo = foo
|
||||
|
||||
Reference in New Issue
Block a user