Skip to content

Commit

Permalink
Fixed parsing of error messages in tests
Browse files Browse the repository at this point in the history
Slightly different error messages in Terraform v1.6 and OpenTofu v1.6.
  • Loading branch information
minamijoyo committed Nov 9, 2023
1 parent 45bd5ba commit be2841a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tfmigrate/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import "regexp"

// SwitchBackToRemoteFuncError tests verify error messages, but the
// error message for missing bucket key in the s3 backend differs
// depending on the Terraform version.
// depending on the Terraform version and OpenTofu version.
// Define a helper function to hide the difference.
const testBucketRequiredErrorLegacyTF = `Error: "bucket": required field is not set`
const testBucketRequiredErrorTF16 = `The attribute "bucket" is required by the backend`
const testBucketRequiredErrorLegacyTerraform = `Error: "bucket": required field is not set`
const testBucketRequiredErrorTerraform16 = `The attribute "bucket" is required by the backend`
const testBucketRequiredErrorOpenTofu16 = `The "bucket" attribute value must not be empty`

var testBucketRequiredErrorRE = regexp.MustCompile(testBucketRequiredErrorLegacyTF + `|` + testBucketRequiredErrorTF16)
var testBucketRequiredErrorRE = regexp.MustCompile(
testBucketRequiredErrorLegacyTerraform + `|` +
testBucketRequiredErrorTerraform16 + `|` +
testBucketRequiredErrorOpenTofu16)

func containsBucketRequiredError(err error) bool {
return testBucketRequiredErrorRE.MatchString(err.Error())
Expand Down

0 comments on commit be2841a

Please sign in to comment.