Mock acmpca interfaces of aws-sdk-go-v2

Viewed 21

I'm using latest v1.17.15 aws-sdk-go-v2 for acmpca but this doesn't have acmpcaiface interfaces. Now how to mock these acmpca api for my unit testing? Please help me to mock the interfaces. Currently I'm using IssueCertificate() and GetCertificate() in my code which needs to be mocked for unit testing.

1 Answers

You don't need acmpcaiface for unit testing. Amazon has already provided a excelent document on how to mock the client operations.

I usually create the interfaces on my own. For example -

// You can use AWSCertificateOperations interface instead on concrete acmpca
// client in your code.
type AWSCertificateOperations interface {
  IssueCertificate(params...) returns..
  GetCertificate(params...) return...
}

type mockAWSCertificateOperations struct {}

func (m *mockAWSCertificateOperations) IssueCertificate(params...) returns... {
    // whatever mock logic you want to have
}

func (m *mockAWSCertificateOperations) GetCertificate(params...) returns... {
    // whatever mock logic you want to have
}
Related