From 160432c514151264c83b47435319164254e12509 Mon Sep 17 00:00:00 2001 From: David Dymko Date: Mon, 15 Nov 2021 11:19:50 -0500 Subject: [PATCH 1/2] instance upgrade will return instance data --- instance.go | 13 +++++++++---- instance_test.go | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 5 deletions(-) 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..02e3ab2 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.Create returned %+v, expected %+v", server, expected) + } } func TestServerServiceHandler_CreateMarketplace(t *testing.T) { From a3b5b0ca95edc158e16007b27f0f5ffd3619f897 Mon Sep 17 00:00:00 2001 From: David Dymko Date: Mon, 15 Nov 2021 13:31:48 -0500 Subject: [PATCH 2/2] instance test fixed typo for update test --- instance_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instance_test.go b/instance_test.go index 02e3ab2..5bb9f54 100644 --- a/instance_test.go +++ b/instance_test.go @@ -1101,7 +1101,7 @@ func TestServerServiceHandler_Update(t *testing.T) { } if !reflect.DeepEqual(server, expected) { - t.Errorf("Instance.Create returned %+v, expected %+v", server, expected) + t.Errorf("Instance.Update returned %+v, expected %+v", server, expected) } }