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

Instance update will return instance data #185

Merged
merged 2 commits into from Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions instance.go
Expand Up @@ -15,7 +15,7 @@ const instancePath = "/v2/instances"
type InstanceService interface {
Create(ctx context.Context, instanceReq *InstanceCreateReq) (*Instance, error)
Get(ctx context.Context, instanceID string) (*Instance, error)
Update(ctx context.Context, instanceID string, instanceReq *InstanceUpdateReq) error
Update(ctx context.Context, instanceID string, instanceReq *InstanceUpdateReq) (*Instance, error)
Delete(ctx context.Context, instanceID string) error
List(ctx context.Context, options *ListOptions) ([]Instance, *Meta, error)

Expand Down Expand Up @@ -290,15 +290,20 @@ func (i *InstanceServiceHandler) Get(ctx context.Context, instanceID string) (*I
}

// Update will update the server with the given parameters
func (i *InstanceServiceHandler) Update(ctx context.Context, instanceID string, instanceReq *InstanceUpdateReq) error {
func (i *InstanceServiceHandler) Update(ctx context.Context, instanceID string, instanceReq *InstanceUpdateReq) (*Instance, error) {
uri := fmt.Sprintf("%s/%s", instancePath, instanceID)

req, err := i.client.NewRequest(ctx, http.MethodPatch, uri, instanceReq)
if err != nil {
return err
return nil, err
}

return i.client.DoWithContext(ctx, req, nil)
instance := new(instanceBase)
if err := i.client.DoWithContext(ctx, req, instance); err != nil {
return nil, err
}

return instance.Instance, nil
}

// Delete an instance. All data will be permanently lost, and the IP address will be released
Expand Down
37 changes: 36 additions & 1 deletion instance_test.go
Expand Up @@ -1065,9 +1065,44 @@ func TestServerServiceHandler_Update(t *testing.T) {
AppID: 1,
}

if err := client.Instance.Update(ctx, "14b3e7d6-ffb5-4994-8502-57fcd9db3b33", options); err != nil {
server, err := client.Instance.Update(ctx, "14b3e7d6-ffb5-4994-8502-57fcd9db3b33", options)
if err != nil {
t.Errorf("Instance.Update returned %+v", err)
}

expected := &Instance{
ID: "14b3e7d6-ffb5-4994-8502-57fcd9db3b33",
Os: "CentOS SELinux 8 x64",
OsID: 362,
RAM: 2048,
Disk: 60,
MainIP: "123.123.123.123",
VCPUCount: 2,
Region: "ewr",
DefaultPassword: "nreqnusibni",
DateCreated: "2013-12-19 14:45:41",
Status: "active",
AllowedBandwidth: 2000,
NetmaskV4: "255.255.255.248",
GatewayV4: "123.123.123.1",
PowerStatus: "running",
ServerStatus: "ok",
Plan: "vc2-1c-2gb",
V6Network: "2001:DB8:1000::",
V6MainIP: "fd11:1111:1112:1c02:0200:00ff:fe00:0000",
V6NetworkSize: 64,
Label: "my new server",
InternalIP: "10.99.0.10",
KVM: "https://my.vultr.com/subs/novnc/api.php?data=eawxFVZw2mXnhGUV",
Tag: "tagger",
AppID: 0,
FirewallGroupID: "1234",
Features: []string{"auto_backups", "ipv6"},
}

if !reflect.DeepEqual(server, expected) {
t.Errorf("Instance.Create returned %+v, expected %+v", server, expected)
ddymko marked this conversation as resolved.
Show resolved Hide resolved
}
}

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