github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/operations/operations_aws_test.go (about)

     1  // Copyright 2016-2018, Pulumi Corporation.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package operations
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/assert"
    21  )
    22  
    23  func TestSessionCache(t *testing.T) {
    24  	t.Parallel()
    25  
    26  	// Create a default session in us-west-2.
    27  	sess1, err := getAWSSession("us-west-2", "", "", "")
    28  	assert.NoError(t, err)
    29  	assert.NotNil(t, sess1)
    30  	assert.Equal(t, "us-west-2", *sess1.Config.Region)
    31  
    32  	// Create a session with explicit credentials and ensure they're set.
    33  	sess2, err := getAWSSession("us-west-2", "AKIA123", "456", "xyz")
    34  	assert.NoError(t, err)
    35  
    36  	creds, err := sess2.Config.Credentials.Get()
    37  	assert.NoError(t, err)
    38  	assert.Equal(t, "AKIA123", creds.AccessKeyID)
    39  	assert.Equal(t, "456", creds.SecretAccessKey)
    40  	assert.Equal(t, "xyz", creds.SessionToken)
    41  
    42  	// Create a session with different creds and make sure they're different.
    43  	sess3, err := getAWSSession("us-west-2", "AKIA123", "456", "hij")
    44  	assert.NoError(t, err)
    45  
    46  	creds, err = sess3.Config.Credentials.Get()
    47  	assert.NoError(t, err)
    48  	assert.Equal(t, "AKIA123", creds.AccessKeyID)
    49  	assert.Equal(t, "456", creds.SecretAccessKey)
    50  	assert.Equal(t, "hij", creds.SessionToken)
    51  }