Skip to content

Commit

Permalink
Modify regex to detect other legitimate forms of provider block decla…
Browse files Browse the repository at this point in the history
…ration (#264)
  • Loading branch information
bendbennett committed Jan 8, 2024
1 parent 0ea9ddd commit 678b30e
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/teststep/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
)

var (
providerConfigBlockRegex = regexp.MustCompile(`provider "?[a-zA-Z0-9_-]+"? {`)
providerConfigBlockRegex = regexp.MustCompile(`provider(\s*"[a-zA-Z0-9_-]+"\s*|\s+[a-zA-Z0-9_-]+\s*){`)
terraformConfigBlockRegex = regexp.MustCompile(`terraform {`)
)

Expand Down
24 changes: 24 additions & 0 deletions internal/teststep/directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,48 @@ func TestConfigurationDirectory_HasProviderBlock(t *testing.T) {
},
expected: true,
},
"provider-block-quoted-with-attributes-no-spaces": {
configDirectory: configurationDirectory{
directory: "testdata/provider_block_quoted_with_attributes_no_spaces",
},
expected: true,
},
"provider-block-unquoted-with-attributes": {
configDirectory: configurationDirectory{
directory: "testdata/provider_block_unquoted_with_attributes",
},
expected: true,
},
"provider-block-unquoted-with-attributes_no-trailing-space": {
configDirectory: configurationDirectory{
directory: "testdata/provider_block_unquoted_with_attributes_no_trailing_space",
},
expected: true,
},
"provider-block-quoted-without-attributes": {
configDirectory: configurationDirectory{
directory: "testdata/provider_block_quoted_without_attributes",
},
expected: true,
},
"provider-block-quoted-without-attributes-no-spaces": {
configDirectory: configurationDirectory{
directory: "testdata/provider_block_quoted_without_attributes_no_spaces",
},
expected: true,
},
"provider-block-unquoted-without-attributes": {
configDirectory: configurationDirectory{
directory: "testdata/provider_block_unquoted_without_attributes",
},
expected: true,
},
"provider-block-unquoted-without-attributes-no-trailing-space": {
configDirectory: configurationDirectory{
directory: "testdata/provider_block_unquoted_without_attributes_no_trailing_space",
},
expected: true,
},
}

for name, testCase := range testCases {
Expand Down
24 changes: 24 additions & 0 deletions internal/teststep/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,48 @@ func TestConfigurationFile_HasProviderBlock(t *testing.T) {
},
expected: true,
},
"provider-block-quoted-with-attributes-no-spaces": {
configFile: configurationFile{
file: "testdata/provider_block_quoted_with_attributes_no_spaces/main.tf",
},
expected: true,
},
"provider-block-unquoted-with-attributes": {
configFile: configurationFile{
file: "testdata/provider_block_unquoted_with_attributes/main.tf",
},
expected: true,
},
"provider-block-unquoted-with-attributes-no-trailing-space": {
configFile: configurationFile{
file: "testdata/provider_block_unquoted_with_attributes_no_trailing_space/main.tf",
},
expected: true,
},
"provider-block-quoted-without-attributes": {
configFile: configurationFile{
file: "testdata/provider_block_quoted_without_attributes/main.tf",
},
expected: true,
},
"provider-block-quoted-without-attributes-no-spaces": {
configFile: configurationFile{
file: "testdata/provider_block_quoted_without_attributes_no_spaces/main.tf",
},
expected: true,
},
"provider-block-unquoted-without-attributes": {
configFile: configurationFile{
file: "testdata/provider_block_unquoted_without_attributes/main.tf",
},
expected: true,
},
"provider-block-unquoted-without-attributes-no-trailing-space": {
configFile: configurationFile{
file: "testdata/provider_block_unquoted_without_attributes_no_trailing_space/main.tf",
},
expected: true,
},
}

for name, testCase := range testCases {
Expand Down
44 changes: 44 additions & 0 deletions internal/teststep/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ provider "test" {
test = true
}
resource "test_test" "test" {}
`,
},
expected: true,
},
"provider-block-quoted-with-attributes-no-spaces": {
configRaw: configurationString{
raw: `
provider"test"{
test = true
}
resource "test_test" "test" {}
`,
},
Expand All @@ -77,6 +89,18 @@ provider test {
test = true
}
resource "test_test" "test" {}
`,
},
expected: true,
},
"provider-block-unquoted-with-attributes-no-trailing-space": {
configRaw: configurationString{
raw: `
provider test{
test = true
}
resource "test_test" "test" {}
`,
},
Expand All @@ -87,6 +111,16 @@ resource "test_test" "test" {}
raw: `
provider "test" {}
resource "test_test" "test" {}
`,
},
expected: true,
},
"provider-block-quoted-without-attributes-no-spaces": {
configRaw: configurationString{
raw: `
provider"test"{}
resource "test_test" "test" {}
`,
},
Expand All @@ -97,6 +131,16 @@ resource "test_test" "test" {}
raw: `
provider test {}
resource "test_test" "test" {}
`,
},
expected: true,
},
"provider-block-unquoted-without-attributes-no-trailing-space": {
configRaw: configurationString{
raw: `
provider test{}
resource "test_test" "test" {}
`,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

provider"test"{
test = true
}

resource "test_test" "test" {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

provider"test"{}

resource "test_test" "test" {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

provider test{
test = true
}

resource "test_test" "test" {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

provider test{}

resource "test_test" "test" {}

0 comments on commit 678b30e

Please sign in to comment.