diff --git a/mongodbatlas/mongodb.go b/mongodbatlas/mongodb.go index 245a41e..30b049d 100644 --- a/mongodbatlas/mongodb.go +++ b/mongodbatlas/mongodb.go @@ -6,7 +6,7 @@ import ( "github.com/dghubble/sling" ) -const apiURL = "https://cloud.mongodb.com/api/atlas/v1.0/" +const atlasURL = "https://cloud.mongodb.com/api/atlas/v1.0/" // Client is a MongoDB Atlas client for making MongoDB API requests. type Client struct { @@ -25,8 +25,13 @@ type Client struct { PrivateIPMode *PrivateIPModeService } -// NewClient returns a new Client. +// NewClient returns a new Client using MongoDB Atlas API Base URL func NewClient(httpClient *http.Client) *Client { + return NewCustomURLClient(httpClient, atlasURL) +} + +// NewCustomURLClient returns a new Client using provided API Base URL +func NewCustomURLClient(httpClient *http.Client, apiURL string) *Client { base := sling.New().Client(httpClient).Base(apiURL) return &Client{ diff --git a/mongodbatlas/root_test.go b/mongodbatlas/root_test.go index 0951c67..d46d958 100644 --- a/mongodbatlas/root_test.go +++ b/mongodbatlas/root_test.go @@ -26,3 +26,22 @@ func TestRootService_Get(t *testing.T) { assert.Nil(t, err) assert.Equal(t, expected, root) } + +func TestCloudManagerRootService_Get(t *testing.T) { + httpClient, mux, server := testServer() + defer server.Close() + + mux.HandleFunc("/api/public/v1.0/", func(w http.ResponseWriter, r *http.Request) { + assertMethod(t, "GET", r) + fmt.Fprintf(w, `{"appName":"MongoDB Cloud Manager","build":"2cf9112fd6b8f59c03a9d1d4cbf32004424e728e","links":[{"href":"https://cloud.mongodb.com/api/public/v1.0","rel":"self"},{"href":"https://cloud.mongodb.com/api/public/v1.0/orgs/000000000000000000000000/apiKeys/000000000000000000000000","rel":"http://mms.mongodb.com/apiKeys"},{"href":"https://cloud.mongodb.com/api/public/v1.0/groups","rel":"http://mms.mongodb.com/groups"},{"href":"https://cloud.mongodb.com/api/public/v1.0/admin/backup","rel":"http://mms.mongodb.com/backupAdmin"}],"throttling":false}`) + }) + + client := NewCustomURLClient(httpClient, "https://cloud.mongodb.com/api/public/v1.0/") + root, _, err := client.Root.Get() + expected := &Root{ + AppName: "MongoDB Cloud Manager", + Build: "2cf9112fd6b8f59c03a9d1d4cbf32004424e728e", + } + assert.Nil(t, err) + assert.Equal(t, expected, root) +}