github.com/aavshr/aws-sdk-go@v1.41.3/aws/credentials/plugincreds/provider_test.go (about)

     1  //go:build go1.8 && awsinclude
     2  // +build go1.8,awsinclude
     3  
     4  package plugincreds
     5  
     6  import (
     7  	"fmt"
     8  	"testing"
     9  
    10  	"github.com/aavshr/aws-sdk-go/aws/awserr"
    11  	"github.com/aavshr/aws-sdk-go/aws/credentials"
    12  )
    13  
    14  func TestProvider_Passthrough(t *testing.T) {
    15  	p := Provider{
    16  		RetrieveFn: func() (string, string, string, error) {
    17  			return "key", "secret", "token", nil
    18  		},
    19  		IsExpiredFn: func() bool {
    20  			return false
    21  		},
    22  	}
    23  
    24  	actual, err := p.Retrieve()
    25  	if err != nil {
    26  		t.Fatalf("expect no error, got %v", err)
    27  	}
    28  
    29  	expect := credentials.Value{
    30  		AccessKeyID:     "key",
    31  		SecretAccessKey: "secret",
    32  		SessionToken:    "token",
    33  		ProviderName:    ProviderName,
    34  	}
    35  	if expect != actual {
    36  		t.Errorf("expect %+v credentials, got %+v", expect, actual)
    37  	}
    38  }
    39  
    40  func TestProvider_Error(t *testing.T) {
    41  	expectErr := fmt.Errorf("expect error")
    42  
    43  	p := Provider{
    44  		RetrieveFn: func() (string, string, string, error) {
    45  			return "", "", "", expectErr
    46  		},
    47  		IsExpiredFn: func() bool {
    48  			return false
    49  		},
    50  	}
    51  
    52  	actual, err := p.Retrieve()
    53  	if err == nil {
    54  		t.Fatalf("expect error, got none")
    55  	}
    56  
    57  	aerr := err.(awserr.Error)
    58  	if e, a := ErrCodePluginProviderRetrieve, aerr.Code(); e != a {
    59  		t.Errorf("expect %s error code, got %s", e, a)
    60  	}
    61  
    62  	if e, a := expectErr, aerr.OrigErr(); e != a {
    63  		t.Errorf("expect %v cause error, got %v", e, a)
    64  	}
    65  
    66  	expect := credentials.Value{
    67  		ProviderName: ProviderName,
    68  	}
    69  	if expect != actual {
    70  		t.Errorf("expect %+v credentials, got %+v", expect, actual)
    71  	}
    72  }