Skip to content

Commit

Permalink
Made requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ezilber-akamai committed Feb 8, 2023
1 parent deb3e46 commit e106d41
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 42 deletions.
36 changes: 30 additions & 6 deletions longview.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ import (
"context"
"encoding/json"
"fmt"
"time"

"github.com/go-resty/resty/v2"
"github.com/linode/linodego/internal/parseabletime"
)

// LongviewClient represents a LongviewClient object
type LongviewClient struct {
ID int `json:"id"`
APIKey string `json:"api_key"`
Created string `json:"created"`
InstallCode string `json:"install_code"`
Label string `json:"label"`
Updated string `json:"updated"`
ID int `json:"id"`
APIKey string `json:"api_key"`
Created *time.Time `json:"-"`
InstallCode string `json:"install_code"`
Label string `json:"label"`
Updated *time.Time `json:"-"`
Apps struct {
Apache any `json:"apache"`
MySQL any `json:"mysql"`
Expand Down Expand Up @@ -154,3 +156,25 @@ func (c *Client) UpdateLongviewPlan(ctx context.Context, opts LongviewPlanUpdate
}
return r.Result().(*LongviewPlan), nil
}

// UnmarshalJSON implements the json.Unmarshaler interface
func (i *LongviewClient) UnmarshalJSON(b []byte) error {
type Mask LongviewClient

p := struct {
*Mask
Created *parseabletime.ParseableTime `json:"created"`
Updated *parseabletime.ParseableTime `json:"updated"`
}{
Mask: (*Mask)(i),
}

if err := json.Unmarshal(b, &p); err != nil {
return err
}

i.Created = (*time.Time)(p.Created)
i.Updated = (*time.Time)(p.Updated)

return nil
}
12 changes: 6 additions & 6 deletions test/integration/fixtures/TestLongviewClient_Create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ interactions:
url: https://api.linode.com/v4beta/longview/clients
method: POST
response:
body: '{"id": 297869, "label": "testing", "api_key": "330D197F-1EFC-4D49-A6B0AA508B141B92",
"install_code": "A091884B-6F64-493F-B81F14570275BDDF", "apps": {"apache": 0,
body: '{"id": 297873, "label": "testing", "api_key": "274D7DEB-393F-4AE8-AC231D11B441BE5F",
"install_code": "659AE7C6-D98F-420A-B293031726EF75D1", "apps": {"apache": 0,
"nginx": 0, "mysql": 0}, "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05"}'
headers:
Access-Control-Allow-Credentials:
Expand Down Expand Up @@ -68,11 +68,11 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/longview/clients/297869
url: https://api.linode.com/v4beta/longview/clients/297873
method: GET
response:
body: '{"id": 297869, "label": "testing", "api_key": "330D197F-1EFC-4D49-A6B0AA508B141B92",
"install_code": "A091884B-6F64-493F-B81F14570275BDDF", "apps": {"apache": false,
body: '{"id": 297873, "label": "testing", "api_key": "274D7DEB-393F-4AE8-AC231D11B441BE5F",
"install_code": "659AE7C6-D98F-420A-B293031726EF75D1", "apps": {"apache": false,
"nginx": false, "mysql": false}, "created": "2018-01-02T03:04:05", "updated":
"2018-01-02T03:04:05"}'
headers:
Expand Down Expand Up @@ -128,7 +128,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/longview/clients/297869
url: https://api.linode.com/v4beta/longview/clients/297873
method: DELETE
response:
body: '{}'
Expand Down
12 changes: 6 additions & 6 deletions test/integration/fixtures/TestLongviewClient_Delete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ interactions:
url: https://api.linode.com/v4beta/longview/clients
method: POST
response:
body: '{"id": 297870, "label": "testing", "api_key": "A499EE5E-CDAF-41FB-9EF0DBEE7B7ADED5",
"install_code": "56B9DBBB-EF00-4715-9E1BB3C129613918", "apps": {"apache": 0,
body: '{"id": 297875, "label": "testing", "api_key": "2B2EB2AD-C41B-4722-853D15EBA92B191B",
"install_code": "82B4250B-86D5-4825-AAEFC9AB6A825052", "apps": {"apache": 0,
"nginx": 0, "mysql": 0}, "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05"}'
headers:
Access-Control-Allow-Credentials:
Expand Down Expand Up @@ -68,11 +68,11 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/longview/clients/297870
url: https://api.linode.com/v4beta/longview/clients/297875
method: GET
response:
body: '{"id": 297870, "label": "testing", "api_key": "A499EE5E-CDAF-41FB-9EF0DBEE7B7ADED5",
"install_code": "56B9DBBB-EF00-4715-9E1BB3C129613918", "apps": {"apache": false,
body: '{"id": 297875, "label": "testing", "api_key": "2B2EB2AD-C41B-4722-853D15EBA92B191B",
"install_code": "82B4250B-86D5-4825-AAEFC9AB6A825052", "apps": {"apache": false,
"nginx": false, "mysql": false}, "created": "2018-01-02T03:04:05", "updated":
"2018-01-02T03:04:05"}'
headers:
Expand Down Expand Up @@ -128,7 +128,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/longview/clients/297870
url: https://api.linode.com/v4beta/longview/clients/297875
method: DELETE
response:
body: '{}'
Expand Down
16 changes: 8 additions & 8 deletions test/integration/fixtures/TestLongviewClient_Get.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ interactions:
url: https://api.linode.com/v4beta/longview/clients
method: POST
response:
body: '{"id": 297868, "label": "testing", "api_key": "0C1CE320-E5B9-4FCE-89E45583B5D2F146",
"install_code": "B57EDD9D-2616-418B-BC3DC1B2AF836593", "apps": {"apache": 0,
body: '{"id": 297872, "label": "testing", "api_key": "D8AD6A15-AD2C-4DC0-BC981E738E988264",
"install_code": "EE8FF29F-758D-49B5-ABD783AE322950D2", "apps": {"apache": 0,
"nginx": 0, "mysql": 0}, "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05"}'
headers:
Access-Control-Allow-Credentials:
Expand Down Expand Up @@ -68,11 +68,11 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/longview/clients/297868
url: https://api.linode.com/v4beta/longview/clients/297872
method: GET
response:
body: '{"id": 297868, "label": "testing", "api_key": "0C1CE320-E5B9-4FCE-89E45583B5D2F146",
"install_code": "B57EDD9D-2616-418B-BC3DC1B2AF836593", "apps": {"apache": false,
body: '{"id": 297872, "label": "testing", "api_key": "D8AD6A15-AD2C-4DC0-BC981E738E988264",
"install_code": "EE8FF29F-758D-49B5-ABD783AE322950D2", "apps": {"apache": false,
"nginx": false, "mysql": false}, "created": "2018-01-02T03:04:05", "updated":
"2018-01-02T03:04:05"}'
headers:
Expand Down Expand Up @@ -131,8 +131,8 @@ interactions:
url: https://api.linode.com/v4beta/longview/clients
method: GET
response:
body: '{"data": [{"id": 297868, "label": "testing", "api_key": "0C1CE320-E5B9-4FCE-89E45583B5D2F146",
"install_code": "B57EDD9D-2616-418B-BC3DC1B2AF836593", "apps": {"apache": false,
body: '{"data": [{"id": 297872, "label": "testing", "api_key": "D8AD6A15-AD2C-4DC0-BC981E738E988264",
"install_code": "EE8FF29F-758D-49B5-ABD783AE322950D2", "apps": {"apache": false,
"nginx": false, "mysql": false}, "created": "2018-01-02T03:04:05", "updated":
"2018-01-02T03:04:05"}], "page": 1, "pages": 1, "results": 1}'
headers:
Expand Down Expand Up @@ -188,7 +188,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/longview/clients/297868
url: https://api.linode.com/v4beta/longview/clients/297872
method: DELETE
response:
body: '{}'
Expand Down
12 changes: 6 additions & 6 deletions test/integration/fixtures/TestLongviewClient_Update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ interactions:
url: https://api.linode.com/v4beta/longview/clients
method: POST
response:
body: '{"id": 297871, "label": "testing", "api_key": "64F57EAB-2537-4E1F-BCC9CF54C3F81509",
"install_code": "1ADE47BD-63B1-4088-859EE040850716AA", "apps": {"apache": 0,
body: '{"id": 297876, "label": "testing", "api_key": "9B4E29A0-E339-4E16-A86540CD6F847A31",
"install_code": "8BCA03D4-307D-4899-B22F58C6C28700BE", "apps": {"apache": 0,
"nginx": 0, "mysql": 0}, "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05"}'
headers:
Access-Control-Allow-Credentials:
Expand Down Expand Up @@ -68,11 +68,11 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/longview/clients/297871
url: https://api.linode.com/v4beta/longview/clients/297876
method: PUT
response:
body: '{"id": 297871, "label": "testing_updated", "api_key": "64F57EAB-2537-4E1F-BCC9CF54C3F81509",
"install_code": "1ADE47BD-63B1-4088-859EE040850716AA", "apps": {"apache": false,
body: '{"id": 297876, "label": "testing_updated", "api_key": "9B4E29A0-E339-4E16-A86540CD6F847A31",
"install_code": "8BCA03D4-307D-4899-B22F58C6C28700BE", "apps": {"apache": false,
"nginx": false, "mysql": false}, "created": "2018-01-02T03:04:05", "updated":
"2018-01-02T03:04:05"}'
headers:
Expand Down Expand Up @@ -126,7 +126,7 @@ interactions:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/longview/clients/297871
url: https://api.linode.com/v4beta/longview/clients/297876
method: DELETE
response:
body: '{}'
Expand Down
10 changes: 0 additions & 10 deletions test/integration/longview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ import (
"github.com/linode/linodego"
)

func TestLongviewClient_List(t *testing.T) {
client, teardown := createTestClient(t, "fixtures/TestLongviewClient_List")
defer teardown()

_, err := client.ListLongviewClients(context.Background(), nil)
if err != nil {
t.Errorf("Error listing longview clients, expected struct - error %v", err)
}
}

func TestLongviewClient_Get(t *testing.T) {
client, teardown := createTestClient(t, "fixtures/TestLongviewClient_Get")
defer teardown()
Expand Down

0 comments on commit e106d41

Please sign in to comment.