Skip to content

Commit

Permalink
Instance update will return instance data (#185)
Browse files Browse the repository at this point in the history
* instance upgrade will return instance data

* instance test fixed typo for update test
  • Loading branch information
ddymko authored Nov 15, 2021
1 parent 987ccda commit fbc0568
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
13 changes: 9 additions & 4 deletions instance.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.Update returned %+v, expected %+v", server, expected)
}
}

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

0 comments on commit fbc0568

Please # to comment.