Skip to content

Commit

Permalink
Upgrade tfexec to v0.18.1 + add tests for ExpectError (#86)
Browse files Browse the repository at this point in the history
* add tests w/ downgrade

* showing errors with v0.18.0

* upgrade dependency
  • Loading branch information
austinvalle authored Mar 1, 2023
1 parent d542407 commit b65227b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
28 changes: 28 additions & 0 deletions helper/resource/testing_new_config_test.go
Original file line number Diff line number Diff line change
@@ -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`),
},
},
})
}
23 changes: 23 additions & 0 deletions helper/resource/testing_new_import_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package resource
import (
"context"
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -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`),
},
},
})
}
4 changes: 2 additions & 2 deletions helper/resource/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b65227b

Please sign in to comment.