Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mongodbatlas/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ type Cluster struct {
VersionReleaseSystem string `json:"versionReleaseSystem,omitempty"`
RootCertType string `json:"rootCertType,omitempty"`
TerminationProtectionEnabled *bool `json:"terminationProtectionEnabled,omitempty"`
Tags []*Tag `json:"tags,omitempty"`
Tags *[]*Tag `json:"tags,omitempty"`
}

// ProcessArgs represents the advanced configuration options for the cluster.
Expand Down
6 changes: 3 additions & 3 deletions mongodbatlas/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func TestClusters_ListClusters(t *testing.T) {
SrvAddress: "mongodb+srv://mongo-shard-00-00.mongodb.net:27017,mongo-shard-00-01.mongodb.net:27017,mongo-shard-00-02.mongodb.net:27017",
StateName: "IDLE",
VersionReleaseSystem: "LTS",
Tags: []*Tag{
Tags: &[]*Tag{
{
Key: "key1",
Value: "value1",
Expand Down Expand Up @@ -399,7 +399,7 @@ func TestClusters_Create(t *testing.T) {
StateName: "IDLE",
VersionReleaseSystem: "LTS",
RootCertType: "ISRGROOTX1",
Tags: []*Tag{
Tags: &[]*Tag{
{
Key: "key1",
Value: "value1",
Expand Down Expand Up @@ -554,7 +554,7 @@ func TestClusters_Create(t *testing.T) {
t.Errorf("expected pitEnabled 'false', received '%t'", *pitEnabled)
}

if cluster.Tags == nil || len(cluster.Tags) == 0 {
if cluster.Tags == nil || len((*cluster.Tags)) == 0 {
t.Errorf("expected tags, received none")
}
}
Expand Down
4 changes: 2 additions & 2 deletions mongodbatlas/serverless_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ type ServerlessCreateRequestParams struct {
ProviderSettings *ServerlessProviderSettings `json:"providerSettings,omitempty"`
ServerlessBackupOptions *ServerlessBackupOptions `json:"serverlessBackupOptions,omitempty"`
TerminationProtectionEnabled *bool `json:"terminationProtectionEnabled,omitempty"`
Tag []*Tag `json:"tags,omitempty"`
Tag *[]*Tag `json:"tags,omitempty"`
}

type ServerlessUpdateRequestParams struct {
ServerlessBackupOptions *ServerlessBackupOptions `json:"serverlessBackupOptions"`
TerminationProtectionEnabled *bool `json:"terminationProtectionEnabled,omitempty"`
Tag []*Tag `json:"tags,omitempty"`
Tag *[]*Tag `json:"tags"`
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you write a unit test for the condition you're looking to cover?


// ServerlessProviderSettings represents the Provider Settings of serverless instances.
Expand Down
190 changes: 111 additions & 79 deletions mongodbatlas/serverless_instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestServerlessInstances_List(t *testing.T) {
StateName: "IDLE",
ConnectionStrings: &ConnectionStrings{StandardSrv: "mongodb+srv://instance1.example.com"},
CreateDate: "2021-06-25T21:32:06Z",
Tags: []*Tag{
Tags: &[]*Tag{
{
Key: "key1",
Value: "value1",
Expand All @@ -128,7 +128,7 @@ func TestServerlessInstances_List(t *testing.T) {
StateName: "IDLE",
ConnectionStrings: &ConnectionStrings{StandardSrv: "mongodb+srv://instance1.example.com"},
CreateDate: "2021-06-25T21:32:06Z",
Tags: []*Tag{
Tags: &[]*Tag{
{
Key: "key1",
Value: "value1",
Expand Down Expand Up @@ -261,7 +261,7 @@ func TestServerlessInstances_Create(t *testing.T) {
Href: "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}",
},
},
Tags: []*Tag{
Tags: &[]*Tag{
{
Key: "key1",
Value: "value1",
Expand All @@ -275,90 +275,122 @@ func TestServerlessInstances_Create(t *testing.T) {
}

func TestServerlessInstances_Update(t *testing.T) {
client, mux, teardown := setup()
defer teardown()
t.Run("default", func(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

mux.HandleFunc(fmt.Sprintf("/"+serverlessInstancesPath+"/%s", groupID, "sample"), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPatch)
fmt.Fprint(w, `{
"connectionStrings" : {
"standardSrv" : "mongodb+srv://instanceName1.example.com"
},
"createDate" : "2021-06-25T21:31:10Z",
"groupId" : "1",
"id" : "1",
"links" : [ {
"href" : "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}",
"rel" : "self"
}, {
"href" : "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}/backup/restoreJobs",
"rel" : "http://cloud.mongodb.com/restoreJobs"
}, {
"href" : "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}/backup/snapshots",
"rel" : "http://cloud.mongodb.com/snapshots"
}],
"mongoDBVersion" : "5.0.0",
"name" : "sample",
"providerSettings" : {
"providerName" : "SERVERLESS",
"backingProviderName" : "AWS",
"regionName" : "US_EAST_1"
mux.HandleFunc(fmt.Sprintf("/"+serverlessInstancesPath+"/%s", groupID, "sample"), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPatch)
fmt.Fprint(w, `{
"connectionStrings" : {
"standardSrv" : "mongodb+srv://instanceName1.example.com"
},
"createDate" : "2021-06-25T21:31:10Z",
"groupId" : "1",
"id" : "1",
"links" : [ {
"href" : "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}",
"rel" : "self"
}, {
"href" : "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}/backup/restoreJobs",
"rel" : "http://cloud.mongodb.com/restoreJobs"
}, {
"href" : "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}/backup/snapshots",
"rel" : "http://cloud.mongodb.com/snapshots"
}],
"mongoDBVersion" : "5.0.0",
"name" : "sample",
"providerSettings" : {
"providerName" : "SERVERLESS",
"backingProviderName" : "AWS",
"regionName" : "US_EAST_1"
},
"serverlessBackupOptions" : {
"serverlessContinuousBackupEnabled" : true
},
"stateName" : "IDLE",
"terminationProtectionEnabled": true,
"tags": [ { "key": "key1", "value": "value1" } ]
}`)
})

bodyParam := &ServerlessUpdateRequestParams{
ServerlessBackupOptions: &ServerlessBackupOptions{ServerlessContinuousBackupEnabled: pointer(true)},
TerminationProtectionEnabled: pointer(true),
Tag: &[]*Tag{{Key: "key1", Value: "value1"}},
}

serverlessInstance, _, err := client.ServerlessInstances.Update(ctx, groupID, "sample", bodyParam)
if err != nil {
t.Fatalf("ServerlessInstances.Get returned error: %v", err)
}

expected := &Cluster{
ID: id,
GroupID: groupID,
MongoDBVersion: "5.0.0",
Name: "sample",
ProviderSettings: &ProviderSettings{RegionName: "US_EAST_1", BackingProviderName: "AWS", ProviderName: "SERVERLESS"},
StateName: "IDLE",
ConnectionStrings: &ConnectionStrings{StandardSrv: "mongodb+srv://instanceName1.example.com"},
CreateDate: "2021-06-25T21:31:10Z",
ServerlessBackupOptions: &ServerlessBackupOptions{ServerlessContinuousBackupEnabled: pointer(true)},
TerminationProtectionEnabled: pointer(true),
Links: []*Link{
{
Rel: "self",
Href: "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}",
},
{
Rel: "http://cloud.mongodb.com/restoreJobs",
Href: "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}/backup/restoreJobs",
},
{
Rel: "http://cloud.mongodb.com/snapshots",
Href: "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}/backup/snapshots",
},
},
"serverlessBackupOptions" : {
"serverlessContinuousBackupEnabled" : true
Tags: &[]*Tag{
{
Key: "key1",
Value: "value1",
},
},
"stateName" : "IDLE",
"terminationProtectionEnabled": true,
"tags": [ { "key": "key1", "value": "value1" } ]
}`)
}

if diff := deep.Equal(serverlessInstance, expected); diff != nil {
t.Error(diff)
}
})

bodyParam := &ServerlessUpdateRequestParams{
ServerlessBackupOptions: &ServerlessBackupOptions{ServerlessContinuousBackupEnabled: pointer(true)},
TerminationProtectionEnabled: pointer(true),
}
t.Run("with empty array of tags", func(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

serverlessInstance, _, err := client.ServerlessInstances.Update(ctx, groupID, "sample", bodyParam)
if err != nil {
t.Fatalf("ServerlessInstances.Get returned error: %v", err)
}
mux.HandleFunc(fmt.Sprintf("/"+serverlessInstancesPath+"/%s", groupID, "sample"), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPatch)
fmt.Fprint(w, `{
"tags": []
}`)
})

expected := &Cluster{
ID: id,
GroupID: groupID,
MongoDBVersion: "5.0.0",
Name: "sample",
ProviderSettings: &ProviderSettings{RegionName: "US_EAST_1", BackingProviderName: "AWS", ProviderName: "SERVERLESS"},
StateName: "IDLE",
ConnectionStrings: &ConnectionStrings{StandardSrv: "mongodb+srv://instanceName1.example.com"},
CreateDate: "2021-06-25T21:31:10Z",
ServerlessBackupOptions: &ServerlessBackupOptions{ServerlessContinuousBackupEnabled: pointer(true)},
TerminationProtectionEnabled: pointer(true),
Links: []*Link{
{
Rel: "self",
Href: "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}",
},
{
Rel: "http://cloud.mongodb.com/restoreJobs",
Href: "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}/backup/restoreJobs",
},
{
Rel: "http://cloud.mongodb.com/snapshots",
Href: "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}/backup/snapshots",
},
},
Tags: []*Tag{
{
Key: "key1",
Value: "value1",
},
},
}
bodyParam := &ServerlessUpdateRequestParams{
Tag: &[]*Tag{},
}

if diff := deep.Equal(serverlessInstance, expected); diff != nil {
t.Error(diff)
}
serverlessInstance, _, err := client.ServerlessInstances.Update(ctx, groupID, "sample", bodyParam)
if err != nil {
t.Fatalf("ServerlessInstances.Get returned error: %v", err)
}

expected := &Cluster{
Tags: &[]*Tag{},
}

if diff := deep.Equal(serverlessInstance, expected); diff != nil {
t.Error(diff)
}
})
}

func TestServerlessInstances_Delete(t *testing.T) {
Expand Down