Skip to content

Commit

Permalink
Merge pull request #40366 from hashicorp/td-ci-teamcity-provider-acct…
Browse files Browse the repository at this point in the history
…ests

CI: Fixes "Process exited with code 1" error for non-service acceptance tests
  • Loading branch information
gdavison authored Dec 2, 2024
2 parents d6dfe89 + c6daa7c commit 1e8bfbc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .teamcity/scripts/provider_tests/acceptance_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ TF_ACC=1 go test \
./internal/types/... \
./internal/vault/... \
./internal/verify/... \
-json -v -count=1 -parallel "%ACCTEST_PARALLELISM%" -timeout=0 -run=TestAcc
-json -count=1 -parallel "%ACCTEST_PARALLELISM%" -timeout=0 -run=TestAcc
1 change: 1 addition & 0 deletions .teamcity/scripts/service_tests/acceptance_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -euo pipefail

TEST_LIST=$(./test-binary -test.list="%TEST_PATTERN%" 2>/dev/null)

# shellcheck disable=2157 # This isn't a constant string, it's a TeamCity variable substitution
if [[ -n "%TEST_EXCLUDE_PATTERN%" ]]; then
TEST_LIST=$(echo "${TEST_LIST}" | grep -vE "%TEST_EXCLUDE_PATTERN%")
fi
Expand Down
2 changes: 1 addition & 1 deletion internal/generate/teamcity/acceptance_tests.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ TF_ACC=1 go test \
{{- range . }}
./internal/{{ . }}/... \
{{- end }}
-json -v -count=1 -parallel "%ACCTEST_PARALLELISM%" -timeout=0 -run=TestAcc
-json -count=1 -parallel "%ACCTEST_PARALLELISM%" -timeout=0 -run=TestAcc
109 changes: 18 additions & 91 deletions internal/provider/provider_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"reflect"
"strings"
"testing"

"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -159,32 +158,6 @@ func TestAccProvider_DefaultAndIgnoreTags_emptyBlocks(t *testing.T) {
})
}

func TestAccProvider_endpoints(t *testing.T) {
ctx := acctest.Context(t)
var provider *schema.Provider
var endpoints strings.Builder

// Initialize each endpoint configuration with matching name and value
for _, serviceKey := range names.ProviderPackages() {
endpoints.WriteString(fmt.Sprintf("%s = \"http://%s\"\n", serviceKey, serviceKey))
}

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t),
ProtoV5ProviderFactories: testAccProtoV5ProviderFactoriesInternal(ctx, t, &provider),
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: testAccProviderConfig_endpoints(endpoints.String()),
Check: resource.ComposeTestCheckFunc(
testAccCheckEndpoints(ctx, &provider),
),
},
},
})
}

func TestAccProvider_customEndpoint(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand Down Expand Up @@ -508,6 +481,9 @@ func TestAccProvider_IgnoreTagsKeyPrefixes_envVarMerged(t *testing.T) {
}

func TestAccProvider_Region_c2s(t *testing.T) {
// When using `AWS_PROFILE` for authentication, `skip_credentials_validation` is ignored
// https://github.com/hashicorp/aws-sdk-go-base/issues/453
t.Skip()
ctx := acctest.Context(t)
var provider *schema.Provider

Expand All @@ -531,6 +507,9 @@ func TestAccProvider_Region_c2s(t *testing.T) {
}

func TestAccProvider_Region_china(t *testing.T) {
// When using `AWS_PROFILE` for authentication, `skip_credentials_validation` is ignored
// https://github.com/hashicorp/aws-sdk-go-base/issues/453
t.Skip()
ctx := acctest.Context(t)
var provider *schema.Provider

Expand All @@ -554,6 +533,9 @@ func TestAccProvider_Region_china(t *testing.T) {
}

func TestAccProvider_Region_commercial(t *testing.T) {
// When using `AWS_PROFILE` for authentication, `skip_credentials_validation` is ignored
// https://github.com/hashicorp/aws-sdk-go-base/issues/453
t.Skip()
ctx := acctest.Context(t)
var provider *schema.Provider

Expand All @@ -577,6 +559,9 @@ func TestAccProvider_Region_commercial(t *testing.T) {
}

func TestAccProvider_Region_govCloud(t *testing.T) {
// When using `AWS_PROFILE` for authentication, `skip_credentials_validation` is ignored
// https://github.com/hashicorp/aws-sdk-go-base/issues/453
t.Skip()
ctx := acctest.Context(t)
var provider *schema.Provider

Expand All @@ -600,6 +585,9 @@ func TestAccProvider_Region_govCloud(t *testing.T) {
}

func TestAccProvider_Region_sc2s(t *testing.T) {
// When using `AWS_PROFILE` for authentication, `skip_credentials_validation` is ignored
// https://github.com/hashicorp/aws-sdk-go-base/issues/453
t.Skip()
ctx := acctest.Context(t)
var provider *schema.Provider

Expand All @@ -623,6 +611,9 @@ func TestAccProvider_Region_sc2s(t *testing.T) {
}

func TestAccProvider_Region_stsRegion(t *testing.T) {
// When using `AWS_PROFILE` for authentication, `skip_credentials_validation` is ignored
// https://github.com/hashicorp/aws-sdk-go-base/issues/453
t.Skip()
ctx := acctest.Context(t)
var provider *schema.Provider

Expand Down Expand Up @@ -983,55 +974,6 @@ func testAccCheckProviderDefaultTags_Tags(ctx context.Context, t *testing.T, p *
}
}

func testAccCheckEndpoints(_ context.Context, p **schema.Provider) resource.TestCheckFunc {
return func(s *terraform.State) error {
if p == nil || *p == nil || (*p).Meta() == nil || (*p).Meta().(*conns.AWSClient) == nil {
return fmt.Errorf("provider not initialized")
}

providerClient := (*p).Meta().(*conns.AWSClient)

for _, serviceKey := range names.Aliases() {
methodName := serviceClient(serviceKey)
method := reflect.ValueOf(providerClient).MethodByName(methodName)
if !method.IsValid() {
continue
}
if method.Kind() != reflect.Func {
return fmt.Errorf("value %q is not a function", methodName)
}
if !funcHasConnFuncSignature(method) {
return fmt.Errorf("function %q does not match expected signature", methodName)
}

result := method.Call([]reflect.Value{
reflect.ValueOf(context.Background()),
})
if l := len(result); l != 1 {
return fmt.Errorf("expected 1 result, got %d", l)
}
providerClientField := result[0]

if !providerClientField.IsValid() {
return fmt.Errorf("unable to match conns.AWSClient struct field name for endpoint name: %s", serviceKey)
}

if !reflect.Indirect(providerClientField).FieldByName("Config").IsValid() {
continue // currently unknown how to do this check for v2 clients
}

actualEndpoint := reflect.Indirect(reflect.Indirect(providerClientField).FieldByName("Config").FieldByName("Endpoint")).String()
expectedEndpoint := fmt.Sprintf("http://%s", serviceKey)

if actualEndpoint != expectedEndpoint {
return fmt.Errorf("expected endpoint (%s) value (%s), got: %s", serviceKey, expectedEndpoint, actualEndpoint)
}
}

return nil
}
}

func testAccCheckUnusualEndpoints(_ context.Context, p **schema.Provider, unusual unusualEndpoint) resource.TestCheckFunc {
return func(s *terraform.State) error {
if p == nil || *p == nil || (*p).Meta() == nil || (*p).Meta().(*conns.AWSClient) == nil {
Expand Down Expand Up @@ -1117,21 +1059,6 @@ data "aws_service" "provider_test" {
}
`

func testAccProviderConfig_endpoints(endpoints string) string {
//lintignore:AT004
return acctest.ConfigCompose(testAccProviderConfig_base, fmt.Sprintf(`
provider "aws" {
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
endpoints {
%[1]s
}
}
`, endpoints))
}

func testAccProviderConfig_customS3Endpoint(endpoint, rName string) string {
//lintignore:AT004
return acctest.ConfigCompose(testAccProviderConfig_base, fmt.Sprintf(`
Expand Down

0 comments on commit 1e8bfbc

Please sign in to comment.