|
| 1 | +package aws |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +type anonymousNamedType AnonymousCredentials |
| 9 | + |
| 10 | +func (f anonymousNamedType) Retrieve(ctx context.Context) (Credentials, error) { |
| 11 | + return AnonymousCredentials(f).Retrieve(ctx) |
| 12 | +} |
| 13 | + |
| 14 | +func TestIsCredentialsProvider(t *testing.T) { |
| 15 | + tests := map[string]struct { |
| 16 | + provider CredentialsProvider |
| 17 | + target CredentialsProvider |
| 18 | + want bool |
| 19 | + }{ |
| 20 | + "same implementations": { |
| 21 | + provider: AnonymousCredentials{}, |
| 22 | + target: AnonymousCredentials{}, |
| 23 | + want: true, |
| 24 | + }, |
| 25 | + "same implementations, pointer target": { |
| 26 | + provider: AnonymousCredentials{}, |
| 27 | + target: &AnonymousCredentials{}, |
| 28 | + want: true, |
| 29 | + }, |
| 30 | + "same implementations, pointer provider": { |
| 31 | + provider: &AnonymousCredentials{}, |
| 32 | + target: AnonymousCredentials{}, |
| 33 | + want: true, |
| 34 | + }, |
| 35 | + "same implementations, both pointers": { |
| 36 | + provider: &AnonymousCredentials{}, |
| 37 | + target: &AnonymousCredentials{}, |
| 38 | + want: true, |
| 39 | + }, |
| 40 | + "different implementations, nil target": { |
| 41 | + provider: AnonymousCredentials{}, |
| 42 | + target: nil, |
| 43 | + want: false, |
| 44 | + }, |
| 45 | + "different implementations, nil provider": { |
| 46 | + provider: nil, |
| 47 | + target: AnonymousCredentials{}, |
| 48 | + want: false, |
| 49 | + }, |
| 50 | + "different implementations": { |
| 51 | + provider: AnonymousCredentials{}, |
| 52 | + target: &stubCredentialsProvider{}, |
| 53 | + want: false, |
| 54 | + }, |
| 55 | + "nil provider and target": { |
| 56 | + provider: nil, |
| 57 | + target: nil, |
| 58 | + want: true, |
| 59 | + }, |
| 60 | + "implements IsCredentialsProvider, match": { |
| 61 | + provider: NewCredentialsCache(AnonymousCredentials{}), |
| 62 | + target: AnonymousCredentials{}, |
| 63 | + want: true, |
| 64 | + }, |
| 65 | + "implements IsCredentialsProvider, no match": { |
| 66 | + provider: NewCredentialsCache(AnonymousCredentials{}), |
| 67 | + target: &stubCredentialsProvider{}, |
| 68 | + want: false, |
| 69 | + }, |
| 70 | + "named types aliasing underlying types": { |
| 71 | + provider: AnonymousCredentials{}, |
| 72 | + target: anonymousNamedType{}, |
| 73 | + want: false, |
| 74 | + }, |
| 75 | + } |
| 76 | + for name, tt := range tests { |
| 77 | + t.Run(name, func(t *testing.T) { |
| 78 | + if got := IsCredentialsProvider(tt.provider, tt.target); got != tt.want { |
| 79 | + t.Errorf("IsCredentialsProvider() = %v, want %v", got, tt.want) |
| 80 | + } |
| 81 | + }) |
| 82 | + } |
| 83 | +} |
0 commit comments