diff --git a/mongodbatlas/clusters.go b/mongodbatlas/clusters.go index 2781e967..acfacd51 100644 --- a/mongodbatlas/clusters.go +++ b/mongodbatlas/clusters.go @@ -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. diff --git a/mongodbatlas/clusters_test.go b/mongodbatlas/clusters_test.go index aa550c8e..9425e90e 100644 --- a/mongodbatlas/clusters_test.go +++ b/mongodbatlas/clusters_test.go @@ -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", @@ -399,7 +399,7 @@ func TestClusters_Create(t *testing.T) { StateName: "IDLE", VersionReleaseSystem: "LTS", RootCertType: "ISRGROOTX1", - Tags: []*Tag{ + Tags: &[]*Tag{ { Key: "key1", Value: "value1", @@ -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") } } diff --git a/mongodbatlas/serverless_instances.go b/mongodbatlas/serverless_instances.go index 78ae0593..8468daed 100644 --- a/mongodbatlas/serverless_instances.go +++ b/mongodbatlas/serverless_instances.go @@ -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"` } // ServerlessProviderSettings represents the Provider Settings of serverless instances. diff --git a/mongodbatlas/serverless_instances_test.go b/mongodbatlas/serverless_instances_test.go index fcc05c87..411eed45 100644 --- a/mongodbatlas/serverless_instances_test.go +++ b/mongodbatlas/serverless_instances_test.go @@ -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", @@ -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", @@ -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", @@ -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) {