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

fix: Exclude request body in POST and PUT helpers when options are unspecified #458

Merged
merged 2 commits into from
Feb 28, 2024

Conversation

lgarber-akamai
Copy link
Contributor

@lgarber-akamai lgarber-akamai commented Feb 28, 2024

📝 Description

This change fixes a small issue that made the POST and PUT request helpers encode empty bodies as null, which is rejected by the API. This works by making the options argument variadic and only calling r.SetBody(...) if the argument is specified.

✔️ How to Test

The following test steps assume you have pulled down this PR locally.

Unit Testing

make testunit

Integration Testing

NOTE: This test calls out to the client.ShutdownInstance(...) function, which consumes this helper and does not accept a request body.

make ARGS="-run TestEventPoller_InstancePower" fixtures

Manual Testing

  1. In a linodego sandbox environment (e.g. dx-devenv), run the following:
package main

import (
	"context"
	"log"
	"os"

	"github.com/linode/linodego"
)

func main() {
	ctx := context.Background()

	client := linodego.NewClient(nil)
	client.SetToken(os.Getenv("LINODE_TOKEN"))

	inst, err := client.CreateInstance(ctx, linodego.InstanceCreateOptions{
		Region:   "us-mia",
		Type:     "g6-nanode-1",
		Label:    "test-instance",
		Image:    "linode/ubuntu22.04",
		RootPass: "v3rys3cur3t3stp4ssw0rd!!!!",
	})
	if err != nil {
		log.Fatal(err)
	}

	inst, err = client.WaitForInstanceStatus(ctx, inst.ID, linodego.InstanceRunning, 180)
	if err != nil {
		log.Fatal(err)
	}

	// Attempt to shutdown the instance
	// This calls the request helper with no options internally
	if err := client.ShutdownInstance(ctx, inst.ID); err != nil {
		log.Fatal(err)
	}
}
  1. Ensure no errors are raised.

@lgarber-akamai lgarber-akamai marked this pull request as ready for review February 28, 2024 17:32
@lgarber-akamai lgarber-akamai requested a review from a team as a code owner February 28, 2024 17:32
@lgarber-akamai lgarber-akamai requested review from jriddle-linode and ykim-1 and removed request for a team February 28, 2024 17:32
Copy link
Contributor

@jriddle-linode jriddle-linode left a comment

Choose a reason for hiding this comment

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

LGTM. passes tests locally

Copy link
Contributor

@ykim-1 ykim-1 left a comment

Choose a reason for hiding this comment

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

LGTM

@lgarber-akamai lgarber-akamai merged commit 377f746 into linode:main Feb 28, 2024
3 checks passed
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

3 participants