[QT-309] Resolve AWS config before testing ACC (#17949)
* Check to resolve AWS config before testing ACC * Adjust wording of error to be more clear
This commit is contained in:
parent
0624d8f36e
commit
aa74bd7ed7
|
@ -12,6 +12,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/config"
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
|
@ -195,6 +196,10 @@ func TestBackend_throttled(t *testing.T) {
|
|||
}
|
||||
|
||||
func testAccPreCheck(t *testing.T) {
|
||||
if !hasAWSCredentials() {
|
||||
t.Skip("Skipping because AWS credentials could not be resolved. See https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials for information on how to set up AWS credentials.")
|
||||
}
|
||||
|
||||
initSetup.Do(func() {
|
||||
if v := os.Getenv("AWS_DEFAULT_REGION"); v == "" {
|
||||
log.Println("[INFO] Test: Using us-west-2 as test region")
|
||||
|
@ -203,6 +208,23 @@ func testAccPreCheck(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func hasAWSCredentials() bool {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
cfg, err := config.LoadDefaultConfig(ctx)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
creds, err := cfg.Credentials.Retrieve(ctx)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return creds.HasKeys()
|
||||
}
|
||||
|
||||
func getAccountID() (string, error) {
|
||||
awsConfig := &aws.Config{
|
||||
Region: aws.String("us-east-1"),
|
||||
|
|
5
go.mod
5
go.mod
|
@ -33,6 +33,7 @@ require (
|
|||
github.com/armon/go-radix v1.0.0
|
||||
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef
|
||||
github.com/aws/aws-sdk-go v1.44.128
|
||||
github.com/aws/aws-sdk-go-v2/config v1.6.0
|
||||
github.com/axiomhq/hyperloglog v0.0.0-20220105174342-98591331716a
|
||||
github.com/cenkalti/backoff/v3 v3.2.2
|
||||
github.com/chrismalek/oktasdk-go v0.0.0-20181212195951-3430665dfaa0
|
||||
|
@ -240,11 +241,15 @@ require (
|
|||
github.com/apache/arrow/go/arrow v0.0.0-20210818145353-234c94e4ce64 // indirect
|
||||
github.com/aws/aws-sdk-go-v2 v1.8.0 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.3.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.4.0 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.4.0 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.2.0 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.2.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.2.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.5.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.12.0 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.3.2 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.6.1 // indirect
|
||||
github.com/aws/smithy-go v1.7.0 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/bgentry/speakeasy v0.1.0 // indirect
|
||||
|
|
Loading…
Reference in New Issue