github.com/olli-ai/jx/v2@v2.0.400-0.20210921045218-14731b4dd448/pkg/cloud/amazon/ecr_test.go (about)

     1  // +build unit
     2  
     3  package amazon_test
     4  
     5  import (
     6  	"os"
     7  	"testing"
     8  
     9  	"github.com/olli-ai/jx/v2/pkg/cloud/amazon/testutils"
    10  
    11  	"github.com/olli-ai/jx/v2/pkg/cloud/amazon/session"
    12  
    13  	"github.com/stretchr/testify/assert"
    14  )
    15  
    16  func TestCreateNewSessionWithDefaultRegion(t *testing.T) {
    17  	// TODO Refactor for encapsulation
    18  	oldHome, err := testutils.SwitchAWSHome()
    19  	defer testutils.RestoreHome(oldHome)
    20  	os.Setenv("AWS_REGION", "")
    21  	os.Setenv("AWS_DEFAULT_REGION", "")
    22  	os.Setenv("AWS_PROFILE", "")
    23  	sess, err := session.NewAwsSessionWithoutOptions()
    24  	assert.Nil(t, err)
    25  	assert.Equal(t, "us-west-2", *sess.Config.Region)
    26  }
    27  
    28  func TestCreateNewSessionWithRegionFromAwsRegion(t *testing.T) {
    29  	// TODO Refactor for encapsulation
    30  	os.Setenv("AWS_REGION", "us-east-1")
    31  	os.Setenv("AWS_DEFAULT_REGION", "")
    32  	os.Setenv("AWS_PROFILE", "")
    33  	sess, err := session.NewAwsSessionWithoutOptions()
    34  	assert.Nil(t, err)
    35  	assert.Equal(t, "us-east-1", *sess.Config.Region)
    36  }