Skip to content

Direct mocking of clients in v0.25.0? #1536

Answered by skmcgrail
zubinmadon asked this question in Q&A
Discussion options

You must be logged in to vote

Thank you for reaching out to us @zubinmadon.

What is the recommended method of writing mock objects for the new Client types? Do you have any examples?

The best way to mock the Client types is to define an interface in your package that defines the API(s) that you require. You can then provide any type that satisfies this interface to mock output responses or errors from the client. Here is one example method that can be used to mock responses and validate inputs to the client.

type s3GetObjectAPI interface {
	PutObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)
}

func GetObjectFromS3(api s3GetObjectAPI, bucket, key string)…

Replies: 10 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by vudh1
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@simar7
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
guidance Question that needs advice or information.
9 participants
Converted from issue

This discussion was converted from issue #786 on December 17, 2021 22:55.