mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-08 15:13:56 -06:00
3472cab7d6
Fixes #10042 Fixes #9989 Another panic was found with this resource. IT essentially was causing a panic when no certificates were found. This was due to the casting of status to []string There are times when there are no statuses passed in. Made the error message a lot more generic now rather than having something like this ``` No certificate with statuses [] for domain mytestdomain.com found in this region. ``` This now becomes: ``` No certificate for domain mytestdomain.com found in this region. ``` Also, added a test to show that the panic is gone ``` % make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAwsAcmCertificateDataSource_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/11/11 15:11:33 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAwsAcmCertificateDataSource_ -timeout 120m === RUN TestAccAwsAcmCertificateDataSource_noMatchReturnsError --- PASS: TestAccAwsAcmCertificateDataSource_noMatchReturnsError (6.07s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws6.094s ```
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package aws
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
)
|
|
|
|
func TestAccAwsAcmCertificateDataSource_noMatchReturnsError(t *testing.T) {
|
|
domain := "hashicorp.com"
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() {
|
|
testAccPreCheck(t)
|
|
},
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccCheckAwsAcmCertificateDataSourceConfig(domain),
|
|
ExpectError: regexp.MustCompile(`No certificate for domain`),
|
|
},
|
|
{
|
|
Config: testAccCheckAwsAcmCertificateDataSourceConfigWithStatus(domain),
|
|
ExpectError: regexp.MustCompile(`No certificate for domain`),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckAwsAcmCertificateDataSourceConfig(domain string) string {
|
|
return fmt.Sprintf(`
|
|
data "aws_acm_certificate" "test" {
|
|
domain = "%s"
|
|
}
|
|
`, domain)
|
|
}
|
|
|
|
func testAccCheckAwsAcmCertificateDataSourceConfigWithStatus(domain string) string {
|
|
return fmt.Sprintf(`
|
|
data "aws_acm_certificate" "test" {
|
|
domain = "%s"
|
|
statuses = ["ISSUED"]
|
|
}
|
|
`, domain)
|
|
}
|