github.com/diggerhq/digger/libs@v0.0.0-20240604170430-9d61cdf01cc5/locking/aws/envprovider/envprovider_test.go (about)

     1  package envprovider
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/aws/aws-sdk-go-v2/aws"
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestRetrieve(t *testing.T) {
    13  	t.Parallel()
    14  	tests := map[string]struct {
    15  		key    string
    16  		secret string
    17  	}{
    18  		"digger prefix": {key: "DIGGER_AWS_ACCESS_KEY_ID", secret: "DIGGER_AWS_SECRET_ACCESS_KEY"},
    19  		"no prefix":     {key: "AWS_ACCESS_KEY_ID", secret: "AWS_SECRET_ACCESS_KEY"},
    20  		"other":         {key: "AWS_ACCESS_KEY", secret: "AWS_SECRET_KEY"},
    21  	}
    22  
    23  	for name, tc := range tests {
    24  		t.Run(name, func(t *testing.T) {
    25  			os.Setenv(tc.key, "key")
    26  			os.Setenv(tc.secret, "secret")
    27  			e := EnvProvider{}
    28  			act, _ := e.Retrieve(context.TODO())
    29  			exp := aws.Credentials{AccessKeyID: "key", SecretAccessKey: "secret", SessionToken: ""}
    30  			assert.Equal(t, exp, act)
    31  		})
    32  	}
    33  }