-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding checks for absolute filepath in configurationDirectory and con…
…figurationFile HasProviderBlock, HasTerraformBlock and Write methods (#150) * Adding test coverage for configurationDirectory and configurationFile HasProviderBlock method
- Loading branch information
1 parent
0c4a1fe
commit 36dd090
Showing
13 changed files
with
293 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package teststep | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
) | ||
|
||
func TestConfigurationDirectory_HasProviderBlock(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := map[string]struct { | ||
configDirectory configurationDirectory | ||
expected bool | ||
}{ | ||
"no-config": { | ||
configDirectory: configurationDirectory{ | ||
directory: "testdata/empty_dir", | ||
}, | ||
expected: false, | ||
}, | ||
"provider-meta-attribute": { | ||
configDirectory: configurationDirectory{ | ||
directory: "testdata/provider_meta_attribute", | ||
}, | ||
expected: false, | ||
}, | ||
"provider-object-attribute": { | ||
configDirectory: configurationDirectory{ | ||
directory: "testdata/provider_object_attribute", | ||
}, | ||
expected: false, | ||
}, | ||
"provider-string-attribute": { | ||
configDirectory: configurationDirectory{ | ||
directory: "testdata/provider_string_attribute", | ||
}, | ||
expected: false, | ||
}, | ||
"provider-block-quoted-with-attributes": { | ||
configDirectory: configurationDirectory{ | ||
directory: "testdata/provider_block_quoted_with_attributes", | ||
}, | ||
expected: true, | ||
}, | ||
"provider-block-unquoted-with-attributes": { | ||
configDirectory: configurationDirectory{ | ||
directory: "testdata/provider_block_unquoted_with_attributes", | ||
}, | ||
expected: true, | ||
}, | ||
"provider-block-quoted-without-attributes": { | ||
configDirectory: configurationDirectory{ | ||
directory: "testdata/provider_block_quoted_without_attributes", | ||
}, | ||
expected: true, | ||
}, | ||
"provider-block-unquoted-without-attributes": { | ||
configDirectory: configurationDirectory{ | ||
directory: "testdata/provider_block_unquoted_without_attributes", | ||
}, | ||
expected: true, | ||
}, | ||
} | ||
|
||
for name, testCase := range testCases { | ||
name, testCase := name, testCase | ||
|
||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
got, err := testCase.configDirectory.HasProviderBlock(context.Background()) | ||
|
||
if err != nil { | ||
t.Errorf("unexpected error: %s", err) | ||
} | ||
|
||
if testCase.expected != got { | ||
t.Errorf("expected %t, got %t", testCase.expected, got) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package teststep | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
) | ||
|
||
func TestConfigurationFile_HasProviderBlock(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := map[string]struct { | ||
configFile configurationFile | ||
expected bool | ||
}{ | ||
"no-config": { | ||
configFile: configurationFile{ | ||
file: "testdata/empty_file/main.tf", | ||
}, | ||
expected: false, | ||
}, | ||
"provider-meta-attribute": { | ||
configFile: configurationFile{ | ||
file: "testdata/provider_meta_attribute/main.tf", | ||
}, | ||
expected: false, | ||
}, | ||
"provider-object-attribute": { | ||
configFile: configurationFile{ | ||
file: "testdata/provider_object_attribute/main.tf", | ||
}, | ||
expected: false, | ||
}, | ||
"provider-string-attribute": { | ||
configFile: configurationFile{ | ||
file: "testdata/provider_string_attribute/main.tf", | ||
}, | ||
expected: false, | ||
}, | ||
"provider-block-quoted-with-attributes": { | ||
configFile: configurationFile{ | ||
file: "testdata/provider_block_quoted_with_attributes/main.tf", | ||
}, | ||
expected: true, | ||
}, | ||
"provider-block-unquoted-with-attributes": { | ||
configFile: configurationFile{ | ||
file: "testdata/provider_block_unquoted_with_attributes/main.tf", | ||
}, | ||
expected: true, | ||
}, | ||
"provider-block-quoted-without-attributes": { | ||
configFile: configurationFile{ | ||
file: "testdata/provider_block_quoted_without_attributes/main.tf", | ||
}, | ||
expected: true, | ||
}, | ||
"provider-block-unquoted-without-attributes": { | ||
configFile: configurationFile{ | ||
file: "testdata/provider_block_unquoted_without_attributes/main.tf", | ||
}, | ||
expected: true, | ||
}, | ||
} | ||
|
||
for name, testCase := range testCases { | ||
name, testCase := name, testCase | ||
|
||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
got, err := testCase.configFile.HasProviderBlock(context.Background()) | ||
|
||
if err != nil { | ||
t.Errorf("unexpected error: %s", err) | ||
} | ||
|
||
if testCase.expected != got { | ||
t.Errorf("expected %t, got %t", testCase.expected, got) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
8 changes: 8 additions & 0 deletions
8
internal/teststep/testdata/provider_block_quoted_with_attributes/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" {} |
6 changes: 6 additions & 0 deletions
6
internal/teststep/testdata/provider_block_quoted_without_attributes/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" {} |
8 changes: 8 additions & 0 deletions
8
internal/teststep/testdata/provider_block_unquoted_with_attributes/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" {} |
6 changes: 6 additions & 0 deletions
6
internal/teststep/testdata/provider_block_unquoted_without_attributes/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" {} |
Oops, something went wrong.