Skip to content

Conversation

cveticm
Copy link
Contributor

@cveticm cveticm commented Jul 27, 2023

This will allow for operators to remove all tags from Serverless Instances as tags will not be omitted when sending an empty array of tags.

Description

Please include a summary of the fix/feature/change, including any relevant motivation and context.

Link to any related issue(s):

Type of change:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Required Checklist:

  • I have signed the MongoDB CLA
  • I have added tests that prove my fix is effective or that my feature works
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code

Further comments

This is a minor change to allow AKO to remove all tags from a Serverless Instance

This will allow for operators to remove all tags from Serverless Instances as tags will not be omitted when sending an empty array of tags.
@cveticm cveticm requested a review from a team as a code owner July 27, 2023 10:44
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?

@matt-condon
Copy link
Contributor

I think omitempty is very confusing in golang in relation to arrays (pointer values in general) Since we have array of pointers omitEmpty acts only on array itself - not on pointers: https://go.dev/play/p/N64Ggd7Gdth

@wtrocki This approach is a convention across this client, so I think we're fine to go with this for consistency (also any other approach would likely introduce a breaking change)

@gssbzn gssbzn changed the title Removed omitempty from tags in ServerlessUpdateRequestParams fix: Removed omitempty from tags in ServerlessUpdateRequestParams Jul 27, 2023
@wtrocki
Copy link
Member

wtrocki commented Jul 27, 2023

@wtrocki This approach is a convention across this client

I understand that. Trick is that removing ommitempty has no impact unless (breaking) suggestion by @gssbzn is applied.

https://go.dev/play/p/RKmHl4b0X6p

@cveticm cveticm requested a review from gssbzn July 27, 2023 13:11
wtrocki
wtrocki previously approved these changes Jul 27, 2023
Copy link
Member

@wtrocki wtrocki left a comment

Choose a reason for hiding this comment

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

LGTM after unit test covering this case and passing

@cveticm cveticm requested a review from wtrocki July 27, 2023 14:16
wtrocki
wtrocki previously approved these changes Jul 27, 2023
}

// Testing for removing tags
client, mux, teardown = setup()
Copy link
Contributor

Choose a reason for hiding this comment

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

can you please group the tests using t.Run for example

t.Run("default", func(t *testing.T) {
client, mux, teardown := setup()
defer teardown()
mux.HandleFunc("/api/atlas/v1.0/orgs", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
_, _ = fmt.Fprint(w, `{
"links": [{
"href": "https://cloud.mongodb.com/api/public/v1.0/orgs",
"rel": "self"
}],
"results": [{
"id": "56a10a80e4b0fd3b9a9bb0c2",
"links": [{
"href": "https://cloud.mongodb.com/api/public/v1.0/orgs/56a10a80e4b0fd3b9a9bb0c2",
"rel": "self"
}],
"name": "012i3091203jioawjioej"
}, {
"id": "56aa691ce4b0a0e8c4be51f7",
"links": [{
"href": "https://cloud.mongodb.com/api/public/v1.0/orgs/56aa691ce4b0a0e8c4be51f7",
"rel": "self"
}],
"name": "1454008603036"
}],
"totalCount": 2
}`)
})
orgs, _, err := client.Organizations.List(ctx, nil)
if err != nil {
t.Fatalf("Organizations.List returned error: %v", err)
}
expected := &Organizations{
Links: []*Link{
{
Href: "https://cloud.mongodb.com/api/public/v1.0/orgs",
Rel: "self",
},
},
Results: []*Organization{
{
ID: "56a10a80e4b0fd3b9a9bb0c2",
Links: []*Link{
{
Href: "https://cloud.mongodb.com/api/public/v1.0/orgs/56a10a80e4b0fd3b9a9bb0c2",
Rel: "self",
},
},
Name: "012i3091203jioawjioej",
},
{
ID: "56aa691ce4b0a0e8c4be51f7",
Links: []*Link{
{
Href: "https://cloud.mongodb.com/api/public/v1.0/orgs/56aa691ce4b0a0e8c4be51f7",
Rel: "self",
},
},
Name: "1454008603036",
},
},
TotalCount: 2,
}
if diff := deep.Equal(orgs, expected); diff != nil {
t.Error(diff)
}
})
t.Run("by page number", func(t *testing.T) {
client, mux, teardown := setup()
defer teardown()
mux.HandleFunc("/api/atlas/v1.0/orgs", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
_, _ = fmt.Fprint(w, `{
"links": [
{
"href": "https://cloud.mongodb.com/api/public/v1.0/orgs?pageNum=1&itemsPerPage=1",
"rel": "previous"
},
{
"href": "https://cloud.mongodb.com/api/public/v1.0/orgs?pageNum=2&itemsPerPage=1",
"rel": "self"
},
{
"href": "https://cloud.mongodb.com/api/public/v1.0/orgs?itemsPerPage=3&pageNum=2",
"rel": "next"
}
],
"results": [{
"id": "56a10a80e4b0fd3b9a9bb0c2",
"links": [{
"href": "https://cloud.mongodb.com/api/public/v1.0/orgs/56a10a80e4b0fd3b9a9bb0c2",
"rel": "self"
}],
"name": "FooBar"
}],
"totalCount": 3
}`)
})
opt := &OrganizationsListOptions{ListOptions: ListOptions{PageNum: 2}, Name: "FooBar"}
orgs, _, err := client.Organizations.List(ctx, opt)
if err != nil {
t.Fatalf("Organizations.List returned error: %v", err)
}
expected := &Organizations{
Links: []*Link{
{
Href: "https://cloud.mongodb.com/api/public/v1.0/orgs?pageNum=1&itemsPerPage=1",
Rel: "previous",
},
{
Href: "https://cloud.mongodb.com/api/public/v1.0/orgs?pageNum=2&itemsPerPage=1",
Rel: "self",
},
{
Href: "https://cloud.mongodb.com/api/public/v1.0/orgs?itemsPerPage=3&pageNum=2",
Rel: "next",
},
},
Results: []*Organization{
{
ID: "56a10a80e4b0fd3b9a9bb0c2",
Links: []*Link{
{
Href: "https://cloud.mongodb.com/api/public/v1.0/orgs/56a10a80e4b0fd3b9a9bb0c2",
Rel: "self",
},
},
Name: "FooBar",
},
},
TotalCount: 3,
}
if diff := deep.Equal(orgs, expected); diff != nil {
t.Error(diff)
}
})
}

@cveticm cveticm requested a review from gssbzn July 27, 2023 14:46
@gssbzn gssbzn added the breaking Pull requests that breaks backwards compatibility label Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Pull requests that breaks backwards compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants