@@ -106,7 +106,7 @@ func TestServerlessInstances_List(t *testing.T) {
106
106
StateName : "IDLE" ,
107
107
ConnectionStrings : & ConnectionStrings {StandardSrv : "mongodb+srv://instance1.example.com" },
108
108
CreateDate : "2021-06-25T21:32:06Z" ,
109
- Tags : []* Tag {
109
+ Tags : & []* Tag {
110
110
{
111
111
Key : "key1" ,
112
112
Value : "value1" ,
@@ -128,7 +128,7 @@ func TestServerlessInstances_List(t *testing.T) {
128
128
StateName : "IDLE" ,
129
129
ConnectionStrings : & ConnectionStrings {StandardSrv : "mongodb+srv://instance1.example.com" },
130
130
CreateDate : "2021-06-25T21:32:06Z" ,
131
- Tags : []* Tag {
131
+ Tags : & []* Tag {
132
132
{
133
133
Key : "key1" ,
134
134
Value : "value1" ,
@@ -261,7 +261,7 @@ func TestServerlessInstances_Create(t *testing.T) {
261
261
Href : "http://cloud.mongodb.com/api/atlas/v1.0/groups/{groupId}/serverless/{instanceName1}" ,
262
262
},
263
263
},
264
- Tags : []* Tag {
264
+ Tags : & []* Tag {
265
265
{
266
266
Key : "key1" ,
267
267
Value : "value1" ,
@@ -275,90 +275,122 @@ func TestServerlessInstances_Create(t *testing.T) {
275
275
}
276
276
277
277
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 ()
280
281
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
+ },
306
352
},
307
- "serverlessBackupOptions" : {
308
- "serverlessContinuousBackupEnabled" : true
353
+ Tags : & []* Tag {
354
+ {
355
+ Key : "key1" ,
356
+ Value : "value1" ,
357
+ },
309
358
},
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
+ }
314
364
})
315
365
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 ()
320
369
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
+ })
325
376
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
+ }
358
380
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
+ })
362
394
}
363
395
364
396
func TestServerlessInstances_Delete (t * testing.T ) {
0 commit comments