Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLOUDP-179698 Add tags to clusters #488

Merged
merged 2 commits into from
May 29, 2023
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
6 changes: 6 additions & 0 deletions mongodbatlas/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +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"`
}

// ProcessArgs represents the advanced configuration options for the cluster.
Expand All @@ -188,6 +189,11 @@ type ProcessArgs struct {
OplogMinRetentionHours *float64 `json:"oplogMinRetentionHours,omitempty"`
}

type Tag struct {
Key string `json:"key,omitempty"`
Value string `json:"value,omitempty"`
}

// ClusterStatus is the status of the operations on the cluster.
type ClusterStatus struct {
ChangeStatus ChangeStatus `json:"changeStatus"`
Expand Down
33 changes: 30 additions & 3 deletions mongodbatlas/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ 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"
"versionReleaseSystem": "LTS",
"tags": [ { "key": "key1", "value": "value1" } ]
},
{
"autoScaling": {
Expand Down Expand Up @@ -181,7 +182,8 @@ 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"
"versionReleaseSystem": "LTS",
"tags": [ { "key": "key1", "value": "value1" } ]
}
],
"totalCount": 2
Expand Down Expand Up @@ -263,6 +265,12 @@ 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{
{
Key: "key1",
Value: "value1",
},
},
}

expected := []Cluster{cluster1, cluster1}
Expand Down Expand Up @@ -391,6 +399,12 @@ func TestClusters_Create(t *testing.T) {
StateName: "IDLE",
VersionReleaseSystem: "LTS",
RootCertType: "ISRGROOTX1",
Tags: []*Tag{
{
Key: "key1",
Value: "value1",
},
},
}

mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/clusters", groupID), func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -444,6 +458,12 @@ func TestClusters_Create(t *testing.T) {
"stateName": "IDLE",
"versionReleaseSystem": "LTS",
"rootCertType": "ISRGROOTX1",
"tags": []interface{}{
map[string]interface{}{
"key": "key1",
"value": "value1",
},
},
}

jsonBlob := `
Expand Down Expand Up @@ -496,7 +516,10 @@ func TestClusters_Create(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"
"versionReleaseSystem": "LTS",
"tags": [
{ "key": "key1", "value": "value2" }
]
}
`

Expand Down Expand Up @@ -530,6 +553,10 @@ func TestClusters_Create(t *testing.T) {
if pitEnabled := cluster.PitEnabled; *pitEnabled {
t.Errorf("expected pitEnabled 'false', received '%t'", *pitEnabled)
}

if cluster.Tags == nil || len(cluster.Tags) == 0 {
t.Errorf("expected tags, received none")
}
}

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