Skip to content

Commit 380bffa

Browse files
authored
fix: Removed omitempty from tags in ServerlessUpdateRequestParams (#509)
1 parent 97c98b2 commit 380bffa

File tree

4 files changed

+117
-85
lines changed

4 files changed

+117
-85
lines changed

mongodbatlas/clusters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ type Cluster struct {
172172
VersionReleaseSystem string `json:"versionReleaseSystem,omitempty"`
173173
RootCertType string `json:"rootCertType,omitempty"`
174174
TerminationProtectionEnabled *bool `json:"terminationProtectionEnabled,omitempty"`
175-
Tags []*Tag `json:"tags,omitempty"`
175+
Tags *[]*Tag `json:"tags,omitempty"`
176176
}
177177

178178
// ProcessArgs represents the advanced configuration options for the cluster.

mongodbatlas/clusters_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func TestClusters_ListClusters(t *testing.T) {
265265
SrvAddress: "mongodb+srv://mongo-shard-00-00.mongodb.net:27017,mongo-shard-00-01.mongodb.net:27017,mongo-shard-00-02.mongodb.net:27017",
266266
StateName: "IDLE",
267267
VersionReleaseSystem: "LTS",
268-
Tags: []*Tag{
268+
Tags: &[]*Tag{
269269
{
270270
Key: "key1",
271271
Value: "value1",
@@ -399,7 +399,7 @@ func TestClusters_Create(t *testing.T) {
399399
StateName: "IDLE",
400400
VersionReleaseSystem: "LTS",
401401
RootCertType: "ISRGROOTX1",
402-
Tags: []*Tag{
402+
Tags: &[]*Tag{
403403
{
404404
Key: "key1",
405405
Value: "value1",
@@ -554,7 +554,7 @@ func TestClusters_Create(t *testing.T) {
554554
t.Errorf("expected pitEnabled 'false', received '%t'", *pitEnabled)
555555
}
556556

557-
if cluster.Tags == nil || len(cluster.Tags) == 0 {
557+
if cluster.Tags == nil || len((*cluster.Tags)) == 0 {
558558
t.Errorf("expected tags, received none")
559559
}
560560
}

mongodbatlas/serverless_instances.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ type ServerlessCreateRequestParams struct {
5151
ProviderSettings *ServerlessProviderSettings `json:"providerSettings,omitempty"`
5252
ServerlessBackupOptions *ServerlessBackupOptions `json:"serverlessBackupOptions,omitempty"`
5353
TerminationProtectionEnabled *bool `json:"terminationProtectionEnabled,omitempty"`
54-
Tag []*Tag `json:"tags,omitempty"`
54+
Tag *[]*Tag `json:"tags,omitempty"`
5555
}
5656

5757
type ServerlessUpdateRequestParams struct {
5858
ServerlessBackupOptions *ServerlessBackupOptions `json:"serverlessBackupOptions"`
5959
TerminationProtectionEnabled *bool `json:"terminationProtectionEnabled,omitempty"`
60-
Tag []*Tag `json:"tags,omitempty"`
60+
Tag *[]*Tag `json:"tags"`
6161
}
6262

6363
// ServerlessProviderSettings represents the Provider Settings of serverless instances.

mongodbatlas/serverless_instances_test.go

Lines changed: 111 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func TestServerlessInstances_List(t *testing.T) {
106106
StateName: "IDLE",
107107
ConnectionStrings: &ConnectionStrings{StandardSrv: "mongodb+srv://instance1.example.com"},
108108
CreateDate: "2021-06-25T21:32:06Z",
109-
Tags: []*Tag{
109+
Tags: &[]*Tag{
110110
{
111111
Key: "key1",
112112
Value: "value1",
@@ -128,7 +128,7 @@ func TestServerlessInstances_List(t *testing.T) {
128128
StateName: "IDLE",
129129
ConnectionStrings: &ConnectionStrings{StandardSrv: "mongodb+srv://instance1.example.com"},
130130
CreateDate: "2021-06-25T21:32:06Z",
131-
Tags: []*Tag{
131+
Tags: &[]*Tag{
132132
{
133133
Key: "key1",
134134
Value: "value1",
@@ -261,7 +261,7 @@ func TestServerlessInstances_Create(t *testing.T) {
261261
Href: "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}",
262262
},
263263
},
264-
Tags: []*Tag{
264+
Tags: &[]*Tag{
265265
{
266266
Key: "key1",
267267
Value: "value1",
@@ -275,90 +275,122 @@ func TestServerlessInstances_Create(t *testing.T) {
275275
}
276276

277277
func TestServerlessInstances_Update(t *testing.T) {
278-
client, mux, teardown := setup()
279-
defer teardown()
278+
t.Run("default", func(t *testing.T) {
279+
client, mux, teardown := setup()
280+
defer teardown()
280281

281-
mux.HandleFunc(fmt.Sprintf("/"+serverlessInstancesPath+"/%s", groupID, "sample"), func(w http.ResponseWriter, r *http.Request) {
282-
testMethod(t, r, http.MethodPatch)
283-
fmt.Fprint(w, `{
284-
"connectionStrings" : {
285-
"standardSrv" : "mongodb+srv://instanceName1.example.com"
286-
},
287-
"createDate" : "2021-06-25T21:31:10Z",
288-
"groupId" : "1",
289-
"id" : "1",
290-
"links" : [ {
291-
"href" : "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}",
292-
"rel" : "self"
293-
}, {
294-
"href" : "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}/backup/restoreJobs",
295-
"rel" : "http://cloud.mongodb.com/restoreJobs"
296-
}, {
297-
"href" : "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}/backup/snapshots",
298-
"rel" : "http://cloud.mongodb.com/snapshots"
299-
}],
300-
"mongoDBVersion" : "5.0.0",
301-
"name" : "sample",
302-
"providerSettings" : {
303-
"providerName" : "SERVERLESS",
304-
"backingProviderName" : "AWS",
305-
"regionName" : "US_EAST_1"
282+
mux.HandleFunc(fmt.Sprintf("/"+serverlessInstancesPath+"/%s", groupID, "sample"), func(w http.ResponseWriter, r *http.Request) {
283+
testMethod(t, r, http.MethodPatch)
284+
fmt.Fprint(w, `{
285+
"connectionStrings" : {
286+
"standardSrv" : "mongodb+srv://instanceName1.example.com"
287+
},
288+
"createDate" : "2021-06-25T21:31:10Z",
289+
"groupId" : "1",
290+
"id" : "1",
291+
"links" : [ {
292+
"href" : "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}",
293+
"rel" : "self"
294+
}, {
295+
"href" : "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}/backup/restoreJobs",
296+
"rel" : "http://cloud.mongodb.com/restoreJobs"
297+
}, {
298+
"href" : "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}/backup/snapshots",
299+
"rel" : "http://cloud.mongodb.com/snapshots"
300+
}],
301+
"mongoDBVersion" : "5.0.0",
302+
"name" : "sample",
303+
"providerSettings" : {
304+
"providerName" : "SERVERLESS",
305+
"backingProviderName" : "AWS",
306+
"regionName" : "US_EAST_1"
307+
},
308+
"serverlessBackupOptions" : {
309+
"serverlessContinuousBackupEnabled" : true
310+
},
311+
"stateName" : "IDLE",
312+
"terminationProtectionEnabled": true,
313+
"tags": [ { "key": "key1", "value": "value1" } ]
314+
}`)
315+
})
316+
317+
bodyParam := &ServerlessUpdateRequestParams{
318+
ServerlessBackupOptions: &ServerlessBackupOptions{ServerlessContinuousBackupEnabled: pointer(true)},
319+
TerminationProtectionEnabled: pointer(true),
320+
Tag: &[]*Tag{{Key: "key1", Value: "value1"}},
321+
}
322+
323+
serverlessInstance, _, err := client.ServerlessInstances.Update(ctx, groupID, "sample", bodyParam)
324+
if err != nil {
325+
t.Fatalf("ServerlessInstances.Get returned error: %v", err)
326+
}
327+
328+
expected := &Cluster{
329+
ID: id,
330+
GroupID: groupID,
331+
MongoDBVersion: "5.0.0",
332+
Name: "sample",
333+
ProviderSettings: &ProviderSettings{RegionName: "US_EAST_1", BackingProviderName: "AWS", ProviderName: "SERVERLESS"},
334+
StateName: "IDLE",
335+
ConnectionStrings: &ConnectionStrings{StandardSrv: "mongodb+srv://instanceName1.example.com"},
336+
CreateDate: "2021-06-25T21:31:10Z",
337+
ServerlessBackupOptions: &ServerlessBackupOptions{ServerlessContinuousBackupEnabled: pointer(true)},
338+
TerminationProtectionEnabled: pointer(true),
339+
Links: []*Link{
340+
{
341+
Rel: "self",
342+
Href: "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}",
343+
},
344+
{
345+
Rel: "http://cloud.mongodb.com/restoreJobs",
346+
Href: "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}/backup/restoreJobs",
347+
},
348+
{
349+
Rel: "http://cloud.mongodb.com/snapshots",
350+
Href: "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}/backup/snapshots",
351+
},
306352
},
307-
"serverlessBackupOptions" : {
308-
"serverlessContinuousBackupEnabled" : true
353+
Tags: &[]*Tag{
354+
{
355+
Key: "key1",
356+
Value: "value1",
357+
},
309358
},
310-
"stateName" : "IDLE",
311-
"terminationProtectionEnabled": true,
312-
"tags": [ { "key": "key1", "value": "value1" } ]
313-
}`)
359+
}
360+
361+
if diff := deep.Equal(serverlessInstance, expected); diff != nil {
362+
t.Error(diff)
363+
}
314364
})
315365

316-
bodyParam := &ServerlessUpdateRequestParams{
317-
ServerlessBackupOptions: &ServerlessBackupOptions{ServerlessContinuousBackupEnabled: pointer(true)},
318-
TerminationProtectionEnabled: pointer(true),
319-
}
366+
t.Run("with empty array of tags", func(t *testing.T) {
367+
client, mux, teardown := setup()
368+
defer teardown()
320369

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

326-
expected := &Cluster{
327-
ID: id,
328-
GroupID: groupID,
329-
MongoDBVersion: "5.0.0",
330-
Name: "sample",
331-
ProviderSettings: &ProviderSettings{RegionName: "US_EAST_1", BackingProviderName: "AWS", ProviderName: "SERVERLESS"},
332-
StateName: "IDLE",
333-
ConnectionStrings: &ConnectionStrings{StandardSrv: "mongodb+srv://instanceName1.example.com"},
334-
CreateDate: "2021-06-25T21:31:10Z",
335-
ServerlessBackupOptions: &ServerlessBackupOptions{ServerlessContinuousBackupEnabled: pointer(true)},
336-
TerminationProtectionEnabled: pointer(true),
337-
Links: []*Link{
338-
{
339-
Rel: "self",
340-
Href: "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}",
341-
},
342-
{
343-
Rel: "http://cloud.mongodb.com/restoreJobs",
344-
Href: "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}/backup/restoreJobs",
345-
},
346-
{
347-
Rel: "http://cloud.mongodb.com/snapshots",
348-
Href: "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}/backup/snapshots",
349-
},
350-
},
351-
Tags: []*Tag{
352-
{
353-
Key: "key1",
354-
Value: "value1",
355-
},
356-
},
357-
}
377+
bodyParam := &ServerlessUpdateRequestParams{
378+
Tag: &[]*Tag{},
379+
}
358380

359-
if diff := deep.Equal(serverlessInstance, expected); diff != nil {
360-
t.Error(diff)
361-
}
381+
serverlessInstance, _, err := client.ServerlessInstances.Update(ctx, groupID, "sample", bodyParam)
382+
if err != nil {
383+
t.Fatalf("ServerlessInstances.Get returned error: %v", err)
384+
}
385+
386+
expected := &Cluster{
387+
Tags: &[]*Tag{},
388+
}
389+
390+
if diff := deep.Equal(serverlessInstance, expected); diff != nil {
391+
t.Error(diff)
392+
}
393+
})
362394
}
363395

364396
func TestServerlessInstances_Delete(t *testing.T) {

0 commit comments

Comments
 (0)