Skip to content

Commit

Permalink
Adding tests to verify that the ExternalProviders specified in a Test…
Browse files Browse the repository at this point in the history
…Case or TestStep are being used when TestStep.ConfigDirectory is specified (#150)
  • Loading branch information
bendbennett committed Jul 19, 2023
1 parent 80c09f5 commit 516e68b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

resource "random_id" "test" {
byte_length = 8
resource "random_password" "test" {
length = 8

numeric = false
}
55 changes: 51 additions & 4 deletions helper/resource/teststep_providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -585,8 +586,31 @@ func TestTest_TestCase_ExternalProviders_ConfigDirectory(t *testing.T) {
},
Steps: []TestStep{
{
ConfigDirectory: `../fixtures/random_id_byte_length`,
Check: TestCheckResourceAttrSet("random_id.test", "id"),
ConfigDirectory: `../fixtures/random_password`,
Check: TestCheckResourceAttrSet("random_password.test", "id"),
},
},
})
}

// TestTest_TestCase_ExternalProviders_ConfigDirectory_AttributeDoesNotExist uses Terraform
// configuration specifying a "numeric" attribute that was introduced in v3.3.0 of the
// random provider password resource. This test confirms that the TestCase ExternalProviders
// is being used when ConfigDirectory is set.
func TestTest_TestCase_ExternalProviders_ConfigDirectory_AttributeDoesNotExist(t *testing.T) {
t.Parallel()

Test(t, TestCase{
ExternalProviders: map[string]ExternalProvider{
"random": {
Source: "registry.terraform.io/hashicorp/random",
VersionConstraint: "3.2.0",
},
},
Steps: []TestStep{
{
ConfigDirectory: `../fixtures/random_password`,
ExpectError: regexp.MustCompile(`.*An argument named "numeric" is not expected here.`),
},
},
})
Expand All @@ -604,8 +628,31 @@ func TestTest_TestStep_ExternalProviders_ConfigDirectory(t *testing.T) {
VersionConstraint: "3.5.1",
},
},
ConfigDirectory: `../fixtures/random_id_byte_length`,
Check: TestCheckResourceAttrSet("random_id.test", "id"),
ConfigDirectory: `../fixtures/random_password`,
Check: TestCheckResourceAttrSet("random_password.test", "id"),
},
},
})
}

// TestTest_TestCase_ExternalProviders_ConfigDirectory_AttributeDoesNotExist uses Terraform
// configuration specifying a "numeric" attribute that was introduced in v3.3.0 of the
// random provider password resource. This test confirms that the TestStep ExternalProviders
// is being used when ConfigDirectory is set.
func TestTest_TestStep_ExternalProviders_ConfigDirectory_AttributeDoesNotExist(t *testing.T) {
t.Parallel()

Test(t, TestCase{
Steps: []TestStep{
{
ExternalProviders: map[string]ExternalProvider{
"random": {
Source: "registry.terraform.io/hashicorp/random",
VersionConstraint: "3.2.0",
},
},
ConfigDirectory: `../fixtures/random_password`,
ExpectError: regexp.MustCompile(`.*An argument named "numeric" is not expected here.`),
},
},
})
Expand Down

0 comments on commit 516e68b

Please sign in to comment.