elastic / cloud-sdk-go

Apache License 2.0
21 stars 46 forks source link

Add new mock client to match responses by endpoint #485

Closed claudia-correia closed 1 month ago

claudia-correia commented 1 month ago

Description

Adds a new mock client to match a set of responses per endpoint. The match is done using a regex.

Related Issues

https://elasticco.atlassian.net/browse/CP-7863

Motivation and Context

In PR https://github.com/elastic/cloud-cli/pull/1525, I added some unit tests that are currently failing because they're using the default Round Tripper client. This client provides the responses in the order they're defined. However, in those tests we're not sure in which order the requests are executed, because they're performed by different go routines running concurrently. This new client allows to provide a set of responses per endpoint, by specifying an endpoint regex as the key to a map and a set of responses as the value.

How Has This Been Tested?

Types of Changes

Readiness Checklist