From 1886845ec5f50163606938b5c47acf0a819df071 Mon Sep 17 00:00:00 2001 From: Austin Valle Date: Wed, 1 Mar 2023 08:42:18 -0500 Subject: [PATCH 1/3] add tests w/ downgrade --- go.mod | 2 +- go.sum | 2 ++ helper/resource/testing_new_config_test.go | 28 +++++++++++++++++++ .../resource/testing_new_import_state_test.go | 23 +++++++++++++++ helper/resource/wait_test.go | 4 +-- 5 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 helper/resource/testing_new_config_test.go diff --git a/go.mod b/go.mod index aa077a147..ffff96191 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/hashicorp/hc-install v0.5.0 github.com/hashicorp/hcl/v2 v2.16.1 github.com/hashicorp/logutils v1.0.0 - github.com/hashicorp/terraform-exec v0.18.0 + github.com/hashicorp/terraform-exec v0.17.3 github.com/hashicorp/terraform-json v0.15.0 github.com/hashicorp/terraform-plugin-go v0.14.3 github.com/hashicorp/terraform-plugin-log v0.8.0 diff --git a/go.sum b/go.sum index 780ad7619..a7863c517 100644 --- a/go.sum +++ b/go.sum @@ -99,6 +99,8 @@ github.com/hashicorp/hcl/v2 v2.16.1 h1:BwuxEMD/tsYgbhIW7UuI3crjovf3MzuFWiVgiv57i github.com/hashicorp/hcl/v2 v2.16.1/go.mod h1:JRmR89jycNkrrqnMmvPDMd56n1rQJ2Q6KocSLCMCXng= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/hashicorp/terraform-exec v0.17.3 h1:MX14Kvnka/oWGmIkyuyvL6POx25ZmKrjlaclkx3eErU= +github.com/hashicorp/terraform-exec v0.17.3/go.mod h1:+NELG0EqQekJzhvikkeQsOAZpsw0cv/03rbeQJqscAI= github.com/hashicorp/terraform-exec v0.18.0 h1:BJa6/Fhxnb0zvsEGqUrFSybcnhAiBVSUgG7s09b6XlI= github.com/hashicorp/terraform-exec v0.18.0/go.mod h1:6PMRgg0Capig5Fn0zW9/+WM3vQsdwotwa8uxDVzLpHE= github.com/hashicorp/terraform-json v0.15.0 h1:/gIyNtR6SFw6h5yzlbDbACyGvIhKtQi8mTsbkNd79lE= diff --git a/helper/resource/testing_new_config_test.go b/helper/resource/testing_new_config_test.go new file mode 100644 index 000000000..278cebf7e --- /dev/null +++ b/helper/resource/testing_new_config_test.go @@ -0,0 +1,28 @@ +package resource + +import ( + "regexp" + "testing" +) + +func TestTest_TestStep_ExpectError_NewConfig(t *testing.T) { + t.Parallel() + + Test(t, TestCase{ + ExternalProviders: map[string]ExternalProvider{ + "random": { + Source: "registry.terraform.io/hashicorp/random", + VersionConstraint: "3.4.3", + }, + }, + Steps: []TestStep{ + { + Config: `resource "random_string" "one" { + length = 2 + min_upper = 4 + }`, + ExpectError: regexp.MustCompile(`Error: Invalid Attribute Value`), + }, + }, + }) +} diff --git a/helper/resource/testing_new_import_state_test.go b/helper/resource/testing_new_import_state_test.go index 868531b51..f864792ff 100644 --- a/helper/resource/testing_new_import_state_test.go +++ b/helper/resource/testing_new_import_state_test.go @@ -6,6 +6,7 @@ package resource import ( "context" "fmt" + "regexp" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -197,3 +198,25 @@ func TestTest_TestStep_ImportStateVerifyIgnore(t *testing.T) { }, }) } + +func TestTest_TestStep_ExpectError_ImportState(t *testing.T) { + t.Parallel() + + Test(t, TestCase{ + ExternalProviders: map[string]ExternalProvider{ + "random": { + Source: "registry.terraform.io/hashicorp/time", + VersionConstraint: "0.9.1", + }, + }, + Steps: []TestStep{ + { + Config: `resource "time_static" "one" {}`, + ImportStateId: "invalid time string", + ResourceName: "time_static.one", + ImportState: true, + ExpectError: regexp.MustCompile(`Error: Import time static error`), + }, + }, + }) +} diff --git a/helper/resource/wait_test.go b/helper/resource/wait_test.go index 07f523ad4..72c745f07 100644 --- a/helper/resource/wait_test.go +++ b/helper/resource/wait_test.go @@ -30,9 +30,9 @@ func TestRetry(t *testing.T) { } // make sure a slow StateRefreshFunc is allowed to complete after timeout +// +//nolint:paralleltest // This test tends to fail when run in parallel and w/ test explorer func TestRetry_grace(t *testing.T) { - t.Parallel() - f := func() *RetryError { time.Sleep(1 * time.Second) return nil From a7fa0765628c4e9014e60ff1d56c357517006bda Mon Sep 17 00:00:00 2001 From: Austin Valle Date: Wed, 1 Mar 2023 08:43:49 -0500 Subject: [PATCH 2/3] showing errors with v0.18.0 --- go.mod | 2 +- go.sum | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ffff96191..aa077a147 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/hashicorp/hc-install v0.5.0 github.com/hashicorp/hcl/v2 v2.16.1 github.com/hashicorp/logutils v1.0.0 - github.com/hashicorp/terraform-exec v0.17.3 + github.com/hashicorp/terraform-exec v0.18.0 github.com/hashicorp/terraform-json v0.15.0 github.com/hashicorp/terraform-plugin-go v0.14.3 github.com/hashicorp/terraform-plugin-log v0.8.0 diff --git a/go.sum b/go.sum index a7863c517..780ad7619 100644 --- a/go.sum +++ b/go.sum @@ -99,8 +99,6 @@ github.com/hashicorp/hcl/v2 v2.16.1 h1:BwuxEMD/tsYgbhIW7UuI3crjovf3MzuFWiVgiv57i github.com/hashicorp/hcl/v2 v2.16.1/go.mod h1:JRmR89jycNkrrqnMmvPDMd56n1rQJ2Q6KocSLCMCXng= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= -github.com/hashicorp/terraform-exec v0.17.3 h1:MX14Kvnka/oWGmIkyuyvL6POx25ZmKrjlaclkx3eErU= -github.com/hashicorp/terraform-exec v0.17.3/go.mod h1:+NELG0EqQekJzhvikkeQsOAZpsw0cv/03rbeQJqscAI= github.com/hashicorp/terraform-exec v0.18.0 h1:BJa6/Fhxnb0zvsEGqUrFSybcnhAiBVSUgG7s09b6XlI= github.com/hashicorp/terraform-exec v0.18.0/go.mod h1:6PMRgg0Capig5Fn0zW9/+WM3vQsdwotwa8uxDVzLpHE= github.com/hashicorp/terraform-json v0.15.0 h1:/gIyNtR6SFw6h5yzlbDbACyGvIhKtQi8mTsbkNd79lE= From 05caca041ef20a2d8d7865507b49ec8fcfd29b2d Mon Sep 17 00:00:00 2001 From: Austin Valle Date: Wed, 1 Mar 2023 08:50:00 -0500 Subject: [PATCH 3/3] upgrade dependency --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index aa077a147..3a37ba6f1 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/hashicorp/hc-install v0.5.0 github.com/hashicorp/hcl/v2 v2.16.1 github.com/hashicorp/logutils v1.0.0 - github.com/hashicorp/terraform-exec v0.18.0 + github.com/hashicorp/terraform-exec v0.18.1 github.com/hashicorp/terraform-json v0.15.0 github.com/hashicorp/terraform-plugin-go v0.14.3 github.com/hashicorp/terraform-plugin-log v0.8.0 diff --git a/go.sum b/go.sum index 780ad7619..94f494b4e 100644 --- a/go.sum +++ b/go.sum @@ -101,6 +101,8 @@ github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/terraform-exec v0.18.0 h1:BJa6/Fhxnb0zvsEGqUrFSybcnhAiBVSUgG7s09b6XlI= github.com/hashicorp/terraform-exec v0.18.0/go.mod h1:6PMRgg0Capig5Fn0zW9/+WM3vQsdwotwa8uxDVzLpHE= +github.com/hashicorp/terraform-exec v0.18.1 h1:LAbfDvNQU1l0NOQlTuudjczVhHj061fNX5H8XZxHlH4= +github.com/hashicorp/terraform-exec v0.18.1/go.mod h1:58wg4IeuAJ6LVsLUeD2DWZZoc/bYi6dzhLHzxM41980= github.com/hashicorp/terraform-json v0.15.0 h1:/gIyNtR6SFw6h5yzlbDbACyGvIhKtQi8mTsbkNd79lE= github.com/hashicorp/terraform-json v0.15.0/go.mod h1:+L1RNzjDU5leLFZkHTFTbJXaoqUC6TqXlFgDoOXrtvk= github.com/hashicorp/terraform-plugin-go v0.14.3 h1:nlnJ1GXKdMwsC8g1Nh05tK2wsC3+3BL/DBBxFEki+j0=