mirror of https://github.com/pulumi/pulumi.git
70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
// Copyright 2024-2024, Pulumi Corporation.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package diy
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
"github.com/aws/aws-sdk-go-v2/config"
|
|
"github.com/aws/aws-sdk-go-v2/service/sts"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func getAwsCaller(t *testing.T) (context.Context, aws.Config) {
|
|
t.Helper()
|
|
ctx := context.Background()
|
|
cfg, err := config.LoadDefaultConfig(ctx)
|
|
if err != nil {
|
|
t.Logf("Skipping, could not load aws config: %s", err)
|
|
t.SkipNow()
|
|
}
|
|
|
|
stsClient := sts.NewFromConfig(cfg)
|
|
_, err = stsClient.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{})
|
|
if err != nil {
|
|
t.Logf("Skipping, couldn't use aws credentials to query identity: %s", err)
|
|
t.SkipNow()
|
|
}
|
|
|
|
return ctx, cfg
|
|
}
|
|
|
|
//nolint:paralleltest // this test sets the global login state
|
|
func TestAwsLogin(t *testing.T) {
|
|
err := os.Chdir("project")
|
|
require.NoError(t, err)
|
|
t.Cleanup(func() {
|
|
err := os.Chdir("..")
|
|
require.NoError(t, err)
|
|
})
|
|
|
|
t.Setenv("AWS_REGION", "us-west-2")
|
|
|
|
ctx, cfg := getAwsCaller(t)
|
|
|
|
creds, err := cfg.Credentials.Retrieve(ctx)
|
|
require.NoError(t, err)
|
|
|
|
t.Setenv("AWS_PROFILE", "")
|
|
t.Setenv("AWS_ACCESS_KEY_ID", creds.AccessKeyID)
|
|
t.Setenv("AWS_SECRET_ACCESS_KEY", creds.SecretAccessKey)
|
|
t.Setenv("AWS_SESSION_TOKEN", creds.SessionToken)
|
|
cloudURL := "s3://pulumitesting"
|
|
loginAndCreateStack(t, cloudURL)
|
|
}
|