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

Docs update and custom image options update #538

Merged

Conversation

frezbo
Copy link
Contributor

@frezbo frezbo commented Dec 19, 2020

Signed-off-by: Noel Georgi [email protected]

  • Fixes the doc update that was missed in the initial implementation.
  • Pulls in the changes to update description and distribution from digitalocean/godo#413

@frezbo frezbo changed the title Docs update and custom image options update support Docs update and custom image options update Dec 19, 2020
Copy link
Member

@andrewsomething andrewsomething left a comment

Thanks for picking this up! I had meant to add these here after doing so in godo, but it seems to have slipped my mind.

It would be great to add an additional step to this test exercising the update method:

func TestAccDigitalOceanCustomImageFull(t *testing.T) {

_, _, err := client.Images.Update(ctx, id, &godo.ImageUpdateRequest{
Name: name,
})
if d.HasChanges("name", "description", "distribution") {
Copy link
Member

@andrewsomething andrewsomething Dec 21, 2020

Choose a reason for hiding this comment

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

👀 Hadn't noticed they've introduced HasChanges. Much nicer than the old if d.HasChange("foo") || d.HasChange("bar") syntaxt.

imageUpdateRequest := &godo.ImageUpdateRequest{}

if d.HasChange("name") {
imageUpdateRequest.Name = imageName
}
if d.HasChange("distribution") {
imageDistribution := d.Get("distribution").(string)
imageUpdateRequest.Distribution = imageDistribution
}

if d.HasChange("description") {
imageDescription := d.Get("description").(string)
imageUpdateRequest.Description = imageDescription
}
Copy link
Member

@andrewsomething andrewsomething Dec 21, 2020

Choose a reason for hiding this comment

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

Suggested change
imageUpdateRequest := &godo.ImageUpdateRequest{}
if d.HasChange("name") {
imageUpdateRequest.Name = imageName
}
if d.HasChange("distribution") {
imageDistribution := d.Get("distribution").(string)
imageUpdateRequest.Distribution = imageDistribution
}
if d.HasChange("description") {
imageDescription := d.Get("description").(string)
imageUpdateRequest.Description = imageDescription
}
imageUpdateRequest := &godo.ImageUpdateRequest{
Name: imageName,
Distribution: d.Get("distribution").(string),
Description: d.Get("description").(string),
}

We can simplify this a bit. PUT is idempotent, so no reason not to build the full request.

Copy link
Contributor Author

@frezbo frezbo Dec 21, 2020

Choose a reason for hiding this comment

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

I didn't noticed it was idempotent, was trying to change only fields that changed. I'll make this change

@frezbo
Copy link
Contributor Author

@frezbo frezbo commented Dec 21, 2020

@andrewsomething I'll add a test for update in a bit. Finishing off something.

@andrewsomething andrewsomething self-requested a review Jan 13, 2021
@andrewsomething
Copy link
Member

@andrewsomething andrewsomething commented Jan 13, 2021

I've gone ahead and written a test for the update method to unblock this: 21c3341

Thanks again for your contributions @frezbo!

@andrewsomething andrewsomething merged commit 30d814d into digitalocean:master Jan 13, 2021
2 checks passed
@frezbo frezbo deleted the feature/custom_image_updates branch Jan 14, 2021
@frezbo
Copy link
Contributor Author

@frezbo frezbo commented Jan 14, 2021

@andrewsomething I'm so sorry. I forgot about this. Thanks for taking it up 👍 ❤️

andrewsomething added a commit that referenced this issue Apr 26, 2021
* Docs update and custom image options update support

Signed-off-by: Noel Georgi <[email protected]>

* Apply review suggestion.

* Add an acceptance test for updates.

Co-authored-by: Andrew Starr-Bochicchio <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants