diff --git a/instance.go b/instance.go index bef8e1e..fa0c6a3 100644 --- a/instance.go +++ b/instance.go @@ -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) @@ -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 diff --git a/instance_test.go b/instance_test.go index abc3b0b..5bb9f54 100644 --- a/instance_test.go +++ b/instance_test.go @@ -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.Update returned %+v, expected %+v", server, expected) + } } func TestServerServiceHandler_CreateMarketplace(t *testing.T) {