-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add tests for
mongodb_advanced_cluster
covering transitions t…
…o auto-scaling mode (#2851) * implement GetIndependentShardScalingMode * add tests * add comment on fixed version * use base url from env variable to make tests work in QA
- Loading branch information
Showing
3 changed files
with
212 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package acc | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/mongodb-forks/digest" | ||
) | ||
|
||
func GetIndependentShardScalingMode(ctx context.Context, projectID, clusterName string) (*string, *http.Response, error) { | ||
baseURL := os.Getenv("MONGODB_ATLAS_BASE_URL") | ||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, baseURL+"test/utils/auth/groups/"+projectID+"/clusters/"+clusterName+"/independentShardScalingMode", http.NoBody) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
req.Header.Add("Accept", "*/*") | ||
|
||
transport := digest.NewTransport(os.Getenv("MONGODB_ATLAS_PUBLIC_KEY"), os.Getenv("MONGODB_ATLAS_PRIVATE_KEY")) | ||
httpClient, err := transport.Client() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
resp, err := httpClient.Do(req) | ||
if err != nil || resp == nil { | ||
return nil, resp, err | ||
} | ||
|
||
var result *string | ||
result, err = decode(resp.Body) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return result, resp, nil | ||
} | ||
|
||
func decode(body io.ReadCloser) (*string, error) { | ||
buf, err := io.ReadAll(body) | ||
_ = body.Close() | ||
if err != nil { | ||
return nil, err | ||
} | ||
result := string(buf) | ||
return &result, nil | ||
} |