From 07352c92d245beee9dbd05de4c1913c0ed6ca7a7 Mon Sep 17 00:00:00 2001 From: Apostolos Benisis Date: Wed, 19 May 2021 17:00:20 +0200 Subject: [PATCH 1/2] Replace testing.T with testing.TestingT (#904) --- modules/terraform/var-file.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/terraform/var-file.go b/modules/terraform/var-file.go index e5ff5b62b..b9aa1c912 100644 --- a/modules/terraform/var-file.go +++ b/modules/terraform/var-file.go @@ -5,7 +5,8 @@ import ( "fmt" "io/ioutil" "reflect" - "testing" + + "github.com/gruntwork-io/terratest/modules/testing" "github.com/hashicorp/hcl/v2/hclparse" "github.com/stretchr/testify/require" @@ -16,7 +17,7 @@ import ( // GetVariableAsStringFromVarFile Gets the string represention of a variable from a provided input file found in VarFile // For list or map, use GetVariableAsListFromVarFile or GetVariableAsMapFromVarFile, respectively. -func GetVariableAsStringFromVarFile(t *testing.T, fileName string, key string) string { +func GetVariableAsStringFromVarFile(t testing.TestingT, fileName string, key string) string { result, err := GetVariableAsStringFromVarFileE(t, fileName, key) require.NoError(t, err) @@ -26,7 +27,7 @@ func GetVariableAsStringFromVarFile(t *testing.T, fileName string, key string) s // GetVariableAsStringFromVarFileE Gets the string represention of a variable from a provided input file found in VarFile // Will return an error if GetAllVariablesFromVarFileE returns an error or the key provided does not exist in the file. // For list or map, use GetVariableAsListFromVarFile or GetVariableAsMapFromVarFile, respectively. -func GetVariableAsStringFromVarFileE(t *testing.T, fileName string, key string) (string, error) { +func GetVariableAsStringFromVarFileE(t testing.TestingT, fileName string, key string) (string, error) { var variables map[string]interface{} err := GetAllVariablesFromVarFileE(t, fileName, &variables) if err != nil { @@ -44,7 +45,7 @@ func GetVariableAsStringFromVarFileE(t *testing.T, fileName string, key string) // GetVariableAsMapFromVarFile Gets the map represention of a variable from a provided input file found in VarFile // Note that this returns a map of strings. For maps containing complex types, use GetAllVariablesFromVarFile. -func GetVariableAsMapFromVarFile(t *testing.T, fileName string, key string) map[string]string { +func GetVariableAsMapFromVarFile(t testing.TestingT, fileName string, key string) map[string]string { result, err := GetVariableAsMapFromVarFileE(t, fileName, key) require.NoError(t, err) return result @@ -53,7 +54,7 @@ func GetVariableAsMapFromVarFile(t *testing.T, fileName string, key string) map[ // GetVariableAsMapFromVarFileE Gets the map represention of a variable from a provided input file found in VarFile. // Note that this returns a map of strings. For maps containing complex types, use GetAllVariablesFromVarFile // Returns an error if GetAllVariablesFromVarFileE returns an error, the key provided does not exist, or the value associated with the key is not a map -func GetVariableAsMapFromVarFileE(t *testing.T, fileName string, key string) (map[string]string, error) { +func GetVariableAsMapFromVarFileE(t testing.TestingT, fileName string, key string) (map[string]string, error) { var variables map[string]interface{} err := GetAllVariablesFromVarFileE(t, fileName, &variables) if err != nil { @@ -79,7 +80,7 @@ func GetVariableAsMapFromVarFileE(t *testing.T, fileName string, key string) (ma // GetVariableAsListFromVarFile Gets the string list represention of a variable from a provided input file found in VarFile // Note that this returns a list of strings. For lists containing complex types, use GetAllVariablesFromVarFile. -func GetVariableAsListFromVarFile(t *testing.T, fileName string, key string) []string { +func GetVariableAsListFromVarFile(t testing.TestingT, fileName string, key string) []string { result, err := GetVariableAsListFromVarFileE(t, fileName, key) require.NoError(t, err) @@ -89,7 +90,7 @@ func GetVariableAsListFromVarFile(t *testing.T, fileName string, key string) []s // GetVariableAsListFromVarFileE Gets the string list represention of a variable from a provided input file found in VarFile // Note that this returns a list of strings. For lists containing complex types, use GetAllVariablesFromVarFile. // Will return error if GetAllVariablesFromVarFileE returns an error, the key provided does not exist, or the value associated with the key is not a list -func GetVariableAsListFromVarFileE(t *testing.T, fileName string, key string) ([]string, error) { +func GetVariableAsListFromVarFileE(t testing.TestingT, fileName string, key string) ([]string, error) { var variables map[string]interface{} err := GetAllVariablesFromVarFileE(t, fileName, &variables) if err != nil { @@ -115,7 +116,7 @@ func GetVariableAsListFromVarFileE(t *testing.T, fileName string, key string) ([ // GetAllVariablesFromVarFileE Parses all data from a provided input file found ind in VarFile and stores the result in // the value pointed to by out. -func GetAllVariablesFromVarFile(t *testing.T, fileName string, out interface{}) { +func GetAllVariablesFromVarFile(t testing.TestingT, fileName string, out interface{}) { err := GetAllVariablesFromVarFileE(t, fileName, out) require.NoError(t, err) } @@ -123,7 +124,7 @@ func GetAllVariablesFromVarFile(t *testing.T, fileName string, out interface{}) // GetAllVariablesFromVarFileE Parses all data from a provided input file found ind in VarFile and stores the result in // the value pointed to by out. Returns an error if the specified file does not exist, the specified file is not // readable, or the specified file cannot be decoded from HCL. -func GetAllVariablesFromVarFileE(t *testing.T, fileName string, out interface{}) error { +func GetAllVariablesFromVarFileE(t testing.TestingT, fileName string, out interface{}) error { fileContents, err := ioutil.ReadFile(fileName) if err != nil { return err From 31ed1484bb7ba4f8fcf1645190e87d0a00883f1b Mon Sep 17 00:00:00 2001 From: Apostolos Benisis Date: Wed, 19 May 2021 17:01:09 +0200 Subject: [PATCH 2/2] Fix typos in the comments --- modules/terraform/var-file.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/terraform/var-file.go b/modules/terraform/var-file.go index b9aa1c912..a81ec00a5 100644 --- a/modules/terraform/var-file.go +++ b/modules/terraform/var-file.go @@ -15,7 +15,7 @@ import ( ctyjson "github.com/zclconf/go-cty/cty/json" ) -// GetVariableAsStringFromVarFile Gets the string represention of a variable from a provided input file found in VarFile +// GetVariableAsStringFromVarFile Gets the string representation of a variable from a provided input file found in VarFile // For list or map, use GetVariableAsListFromVarFile or GetVariableAsMapFromVarFile, respectively. func GetVariableAsStringFromVarFile(t testing.TestingT, fileName string, key string) string { result, err := GetVariableAsStringFromVarFileE(t, fileName, key) @@ -24,7 +24,7 @@ func GetVariableAsStringFromVarFile(t testing.TestingT, fileName string, key str return result } -// GetVariableAsStringFromVarFileE Gets the string represention of a variable from a provided input file found in VarFile +// GetVariableAsStringFromVarFileE Gets the string representation of a variable from a provided input file found in VarFile // Will return an error if GetAllVariablesFromVarFileE returns an error or the key provided does not exist in the file. // For list or map, use GetVariableAsListFromVarFile or GetVariableAsMapFromVarFile, respectively. func GetVariableAsStringFromVarFileE(t testing.TestingT, fileName string, key string) (string, error) { @@ -43,7 +43,7 @@ func GetVariableAsStringFromVarFileE(t testing.TestingT, fileName string, key st return fmt.Sprintf("%v", variable), nil } -// GetVariableAsMapFromVarFile Gets the map represention of a variable from a provided input file found in VarFile +// GetVariableAsMapFromVarFile Gets the map representation of a variable from a provided input file found in VarFile // Note that this returns a map of strings. For maps containing complex types, use GetAllVariablesFromVarFile. func GetVariableAsMapFromVarFile(t testing.TestingT, fileName string, key string) map[string]string { result, err := GetVariableAsMapFromVarFileE(t, fileName, key) @@ -51,7 +51,7 @@ func GetVariableAsMapFromVarFile(t testing.TestingT, fileName string, key string return result } -// GetVariableAsMapFromVarFileE Gets the map represention of a variable from a provided input file found in VarFile. +// GetVariableAsMapFromVarFileE Gets the map representation of a variable from a provided input file found in VarFile. // Note that this returns a map of strings. For maps containing complex types, use GetAllVariablesFromVarFile // Returns an error if GetAllVariablesFromVarFileE returns an error, the key provided does not exist, or the value associated with the key is not a map func GetVariableAsMapFromVarFileE(t testing.TestingT, fileName string, key string) (map[string]string, error) { @@ -78,7 +78,7 @@ func GetVariableAsMapFromVarFileE(t testing.TestingT, fileName string, key strin return resultMap, nil } -// GetVariableAsListFromVarFile Gets the string list represention of a variable from a provided input file found in VarFile +// GetVariableAsListFromVarFile Gets the string list representation of a variable from a provided input file found in VarFile // Note that this returns a list of strings. For lists containing complex types, use GetAllVariablesFromVarFile. func GetVariableAsListFromVarFile(t testing.TestingT, fileName string, key string) []string { result, err := GetVariableAsListFromVarFileE(t, fileName, key) @@ -87,7 +87,7 @@ func GetVariableAsListFromVarFile(t testing.TestingT, fileName string, key strin return result } -// GetVariableAsListFromVarFileE Gets the string list represention of a variable from a provided input file found in VarFile +// GetVariableAsListFromVarFileE Gets the string list representation of a variable from a provided input file found in VarFile // Note that this returns a list of strings. For lists containing complex types, use GetAllVariablesFromVarFile. // Will return error if GetAllVariablesFromVarFileE returns an error, the key provided does not exist, or the value associated with the key is not a list func GetVariableAsListFromVarFileE(t testing.TestingT, fileName string, key string) ([]string, error) { @@ -114,7 +114,7 @@ func GetVariableAsListFromVarFileE(t testing.TestingT, fileName string, key stri return resultArray, nil } -// GetAllVariablesFromVarFileE Parses all data from a provided input file found ind in VarFile and stores the result in +// GetAllVariablesFromVarFile Parses all data from a provided input file found ind in VarFile and stores the result in // the value pointed to by out. func GetAllVariablesFromVarFile(t testing.TestingT, fileName string, out interface{}) { err := GetAllVariablesFromVarFileE(t, fileName, out)