-
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 support for TestStep.ConfigFile field (#150)
- Loading branch information
1 parent
6ab7111
commit e395077
Showing
29 changed files
with
1,064 additions
and
177 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package config | ||
|
||
// TestStepConfigFunc is the callback type used with acceptance tests to | ||
// specify a string which identifies a directory containing Terraform | ||
// configuration files, or a file that contains Terraform configuration. | ||
type TestStepConfigFunc func(TestStepConfigRequest) string | ||
|
||
// TestStepConfigRequest defines the request supplied to types | ||
// implementing TestStepConfigFunc. | ||
type TestStepConfigRequest struct { | ||
StepNumber int | ||
TestName string | ||
} | ||
|
||
// Exec executes TestStepConfigFunc if it is not nil, otherwise an | ||
// empty string is returned. | ||
func (f TestStepConfigFunc) Exec(req TestStepConfigRequest) string { | ||
if f != nil { | ||
return f(req) | ||
} | ||
|
||
return "" | ||
} |
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
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,48 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package config | ||
|
||
import ( | ||
"path/filepath" | ||
"strconv" | ||
) | ||
|
||
// StaticFile is a helper function that returns the supplied | ||
// file when TestStepConfigFunc is executed. | ||
func StaticFile(file string) func(TestStepConfigRequest) string { | ||
return func(_ TestStepConfigRequest) string { | ||
return file | ||
} | ||
} | ||
|
||
// TestNameFile returns the name of the test suffixed with the supplied | ||
// file name when TestStepConfigFunc is executed (e.g., "testdata/TestExampleCloudThing_basic/test.tf. | ||
// | ||
// For example, given test code: | ||
// | ||
// func TestExampleCloudThing_basic(t *testing.T) { | ||
// resource.Test(t, resource.TestCase{ | ||
// Steps: []resource.TestStep{ | ||
// { | ||
// ConfigFile: config.TestNameFile("test.tf"), | ||
// }, | ||
// }, | ||
// }) | ||
// } | ||
// | ||
// The testing configuration will be expected in the | ||
// testdata/TestExampleCloudThing_basic/test.tf file. | ||
func TestNameFile(file string) func(TestStepConfigRequest) string { | ||
return func(req TestStepConfigRequest) string { | ||
return filepath.Join("testdata", req.TestName, file) | ||
} | ||
} | ||
|
||
// TestStepFile returns the name of the test suffixed | ||
// with the test step number and the supplied file name. | ||
func TestStepFile(file string) func(TestStepConfigRequest) string { //nolint:paralleltest //Not a test | ||
return func(req TestStepConfigRequest) string { | ||
return filepath.Join("testdata", req.TestName, strconv.Itoa(req.StepNumber), file) | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
helper/resource/testdata/TestTest_ConfigFile_TestNameFile/random.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,19 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
terraform { | ||
required_providers { | ||
random = { | ||
source = "registry.terraform.io/hashicorp/random" | ||
version = "3.5.1" | ||
} | ||
} | ||
} | ||
|
||
provider "random" {} | ||
|
||
resource "random_password" "test" { | ||
length = 8 | ||
|
||
numeric = false | ||
} |
19 changes: 19 additions & 0 deletions
19
helper/resource/testdata/TestTest_ConfigFile_TestNameFile_AttributeDoesNotExist/random.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,19 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
terraform { | ||
required_providers { | ||
random = { | ||
source = "registry.terraform.io/hashicorp/random" | ||
version = "3.2.0" | ||
} | ||
} | ||
} | ||
|
||
provider "random" {} | ||
|
||
resource "random_password" "test" { | ||
length = 8 | ||
|
||
numeric = false | ||
} |
27 changes: 27 additions & 0 deletions
27
...r/resource/testdata/TestTest_ConfigFile_TestNameFile_AttributeDoesNotExist_Vars/random.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,27 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
terraform { | ||
required_providers { | ||
random = { | ||
source = "registry.terraform.io/hashicorp/random" | ||
version = "3.2.0" | ||
} | ||
} | ||
} | ||
|
||
provider "random" {} | ||
|
||
resource "random_password" "test" { | ||
length = var.length | ||
|
||
numeric = var.numeric | ||
} | ||
|
||
variable "length" { | ||
type = number | ||
} | ||
|
||
variable "numeric" { | ||
type = bool | ||
} |
27 changes: 27 additions & 0 deletions
27
helper/resource/testdata/TestTest_ConfigFile_TestNameFile_Vars/random.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,27 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
terraform { | ||
required_providers { | ||
random = { | ||
source = "registry.terraform.io/hashicorp/random" | ||
version = "3.5.1" | ||
} | ||
} | ||
} | ||
|
||
provider "random" {} | ||
|
||
resource "random_password" "test" { | ||
length = var.length | ||
|
||
numeric = var.numeric | ||
} | ||
|
||
variable "length" { | ||
type = number | ||
} | ||
|
||
variable "numeric" { | ||
type = bool | ||
} |
19 changes: 19 additions & 0 deletions
19
helper/resource/testdata/TestTest_ConfigFile_TestStepFile/1/random.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,19 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
terraform { | ||
required_providers { | ||
random = { | ||
source = "registry.terraform.io/hashicorp/random" | ||
version = "3.5.1" | ||
} | ||
} | ||
} | ||
|
||
provider "random" {} | ||
|
||
resource "random_password" "test" { | ||
length = 8 | ||
|
||
numeric = false | ||
} |
19 changes: 19 additions & 0 deletions
19
helper/resource/testdata/TestTest_ConfigFile_TestStepFile_AttributeDoesNotExist/1/random.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,19 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
terraform { | ||
required_providers { | ||
random = { | ||
source = "registry.terraform.io/hashicorp/random" | ||
version = "3.2.0" | ||
} | ||
} | ||
} | ||
|
||
provider "random" {} | ||
|
||
resource "random_password" "test" { | ||
length = 8 | ||
|
||
numeric = false | ||
} |
27 changes: 27 additions & 0 deletions
27
...resource/testdata/TestTest_ConfigFile_TestStepFile_AttributeDoesNotExist_Vars/1/random.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,27 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
terraform { | ||
required_providers { | ||
random = { | ||
source = "registry.terraform.io/hashicorp/random" | ||
version = "3.2.0" | ||
} | ||
} | ||
} | ||
|
||
provider "random" {} | ||
|
||
resource "random_password" "test" { | ||
length = var.length | ||
|
||
numeric = var.numeric | ||
} | ||
|
||
variable "length" { | ||
type = number | ||
} | ||
|
||
variable "numeric" { | ||
type = bool | ||
} |
27 changes: 27 additions & 0 deletions
27
helper/resource/testdata/TestTest_ConfigFile_TestStepFile_Vars/1/random.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,27 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
terraform { | ||
required_providers { | ||
random = { | ||
source = "registry.terraform.io/hashicorp/random" | ||
version = "3.5.1" | ||
} | ||
} | ||
} | ||
|
||
provider "random" {} | ||
|
||
resource "random_password" "test" { | ||
length = var.length | ||
|
||
numeric = var.numeric | ||
} | ||
|
||
variable "length" { | ||
type = number | ||
} | ||
|
||
variable "numeric" { | ||
type = bool | ||
} |
4 changes: 4 additions & 0 deletions
4
...r/resource/testdata/TestTest_TestStep_ProviderFactories_ConfigFile_TestNameFile/random.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,4 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
resource "random_id" "test" {} |
4 changes: 4 additions & 0 deletions
4
...resource/testdata/TestTest_TestStep_ProviderFactories_ConfigFile_TestStepFile/1/random.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,4 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
resource "random_id" "test" {} |
Oops, something went wrong.