...
1 package credentials
2
3 import (
4 "context"
5 "testing"
6
7 "github.com/aws/aws-sdk-go-v2/aws"
8 )
9
10 func TestStaticCredentialsProvider(t *testing.T) {
11 s := StaticCredentialsProvider{
12 Value: aws.Credentials{
13 AccessKeyID: "AKID",
14 SecretAccessKey: "SECRET",
15 SessionToken: "",
16 },
17 }
18
19 creds, err := s.Retrieve(context.Background())
20 if err != nil {
21 t.Errorf("expect no error, got %v", err)
22 }
23 if e, a := "AKID", creds.AccessKeyID; e != a {
24 t.Errorf("expect %v, got %v", e, a)
25 }
26 if e, a := "SECRET", creds.SecretAccessKey; e != a {
27 t.Errorf("expect %v, got %v", e, a)
28 }
29 if l := creds.SessionToken; len(l) != 0 {
30 t.Errorf("expect no token, got %v", l)
31 }
32 }
33
34 func TestStaticCredentialsProviderIsExpired(t *testing.T) {
35 s := StaticCredentialsProvider{
36 Value: aws.Credentials{
37 AccessKeyID: "AKID",
38 SecretAccessKey: "SECRET",
39 SessionToken: "",
40 },
41 }
42
43 creds, err := s.Retrieve(context.Background())
44 if err != nil {
45 t.Fatalf("expect no error, got %v", err)
46 }
47
48 if creds.Expired() {
49 t.Errorf("expect static credentials to never expire")
50 }
51 }
52
View as plain text