Skip to content

Commit 52d17d5

Browse files
author
speruri
committed
add the list certificates error test back
ref #725 Signed-off-by: speruri <[email protected]>
1 parent 8071751 commit 52d17d5

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

aws/acm_test.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package aws
22

33
import (
4+
"fmt"
45
"testing"
56

67
"github.com/aws/aws-sdk-go-v2/aws"
@@ -37,7 +38,7 @@ func TestACM(t *testing.T) {
3738
CertificateChain: aws.String(chain),
3839
},
3940
},
40-
nil,
41+
nil, nil,
4142
),
4243
expect: acmExpect{
4344
ARN: "foobar",
@@ -52,7 +53,7 @@ func TestACM(t *testing.T) {
5253
Certificate: aws.String(cert),
5354
},
5455
},
55-
nil,
56+
nil, nil,
5657
),
5758
expect: acmExpect{
5859
ARN: "foobar",
@@ -78,6 +79,7 @@ func TestACM(t *testing.T) {
7879
Tags: []types.Tag{{Key: aws.String("production"), Value: aws.String("false")}},
7980
},
8081
},
82+
nil,
8183
),
8284
filterTag: "production=true",
8385
expect: acmExpect{
@@ -98,6 +100,7 @@ func TestACM(t *testing.T) {
98100
Tags: []types.Tag{{Key: aws.String("production"), Value: aws.String("false")}},
99101
},
100102
},
103+
nil,
101104
),
102105
filterTag: "production=true",
103106
expect: acmExpect{
@@ -106,6 +109,19 @@ func TestACM(t *testing.T) {
106109
DomainNames: []string{"foobar.de"},
107110
},
108111
},
112+
{
113+
msg: "Fail on ListCertificates error",
114+
api: fake.NewACMClient(
115+
nil, nil,
116+
map[string]error{
117+
"ListCertificates": fmt.Errorf("ListCertificates error"),
118+
},
119+
),
120+
filterTag: "production=true",
121+
expect: acmExpect{
122+
Error: "failed to list certificates page: ListCertificates error",
123+
},
124+
},
109125
} {
110126
t.Run(ti.msg, func(t *testing.T) {
111127
provider := newACMCertProvider(ti.api, ti.filterTag)

aws/fake/acm.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ import (
1111
type ACMClient struct {
1212
cert map[string]*acm.GetCertificateOutput
1313
tags map[string]*acm.ListTagsForCertificateOutput
14+
err map[string]error
1415
}
1516

1617
func (m *ACMClient) ListCertificates(ctx context.Context, input *acm.ListCertificatesInput, fn ...func(*acm.Options)) (*acm.ListCertificatesOutput, error) {
18+
if m.err != nil {
19+
if err, ok := m.err["ListCertificates"]; ok {
20+
return nil, err
21+
}
22+
}
1723
output := &acm.ListCertificatesOutput{
1824
CertificateSummaryList: make([]types.CertificateSummary, 0),
1925
}
@@ -26,6 +32,11 @@ func (m *ACMClient) ListCertificates(ctx context.Context, input *acm.ListCertifi
2632
}
2733

2834
func (m *ACMClient) GetCertificate(ctx context.Context, input *acm.GetCertificateInput, fn ...func(*acm.Options)) (*acm.GetCertificateOutput, error) {
35+
if m.err != nil {
36+
if err, ok := m.err["GetCertificate"]; ok {
37+
return nil, err
38+
}
39+
}
2940
if input.CertificateArn == nil {
3041
return nil, fmt.Errorf("expected a valid CertificateArn, got: nil")
3142
}
@@ -38,6 +49,11 @@ func (m *ACMClient) GetCertificate(ctx context.Context, input *acm.GetCertificat
3849
}
3950

4051
func (m *ACMClient) ListTagsForCertificate(ctx context.Context, in *acm.ListTagsForCertificateInput, fn ...func(*acm.Options)) (*acm.ListTagsForCertificateOutput, error) {
52+
if m.err != nil {
53+
if err, ok := m.err["ListTagsForCertificate"]; ok {
54+
return nil, err
55+
}
56+
}
4157
if in.CertificateArn == nil {
4258
return nil, fmt.Errorf("expected a valid CertificateArn, got: nil")
4359
}
@@ -48,10 +64,12 @@ func (m *ACMClient) ListTagsForCertificate(ctx context.Context, in *acm.ListTags
4864
func NewACMClient(
4965
cert map[string]*acm.GetCertificateOutput,
5066
tags map[string]*acm.ListTagsForCertificateOutput,
67+
err map[string]error,
5168
) *ACMClient {
5269
c := &ACMClient{
5370
cert: cert,
5471
tags: tags,
72+
err: err,
5573
}
5674
return c
5775
}

0 commit comments

Comments
 (0)