pulumi/pkg/operations/operations_aws_test.go

52 lines
1.7 KiB
Go

// Copyright 2016-2018, 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 operations
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSessionCache(t *testing.T) {
t.Parallel()
// Create a default session in us-west-2.
sess1, err := getAWSSession("us-west-2", "", "", "", "", false)
assert.NoError(t, err)
assert.NotNil(t, sess1)
assert.Equal(t, "us-west-2", *sess1.Config.Region)
// Create a session with explicit credentials and ensure they're set.
sess2, err := getAWSSession("us-west-2", "AKIA123", "456", "xyz", "", false)
assert.NoError(t, err)
creds, err := sess2.Config.Credentials.Get()
assert.NoError(t, err)
assert.Equal(t, "AKIA123", creds.AccessKeyID)
assert.Equal(t, "456", creds.SecretAccessKey)
assert.Equal(t, "xyz", creds.SessionToken)
// Create a session with different creds and make sure they're different.
sess3, err := getAWSSession("us-west-2", "AKIA123", "456", "hij", "", false)
assert.NoError(t, err)
creds, err = sess3.Config.Credentials.Get()
assert.NoError(t, err)
assert.Equal(t, "AKIA123", creds.AccessKeyID)
assert.Equal(t, "456", creds.SecretAccessKey)
assert.Equal(t, "hij", creds.SessionToken)
}