diff --git a/longview.go b/longview.go index ba2cb7450..8eeb9f3a8 100644 --- a/longview.go +++ b/longview.go @@ -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"` @@ -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 +} diff --git a/test/integration/fixtures/TestLongviewClient_Create.yaml b/test/integration/fixtures/TestLongviewClient_Create.yaml index 9dad0038b..067291c56 100644 --- a/test/integration/fixtures/TestLongviewClient_Create.yaml +++ b/test/integration/fixtures/TestLongviewClient_Create.yaml @@ -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: @@ -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: @@ -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: '{}' diff --git a/test/integration/fixtures/TestLongviewClient_Delete.yaml b/test/integration/fixtures/TestLongviewClient_Delete.yaml index 1470781c2..da91ee48c 100644 --- a/test/integration/fixtures/TestLongviewClient_Delete.yaml +++ b/test/integration/fixtures/TestLongviewClient_Delete.yaml @@ -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: @@ -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: @@ -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: '{}' diff --git a/test/integration/fixtures/TestLongviewClient_Get.yaml b/test/integration/fixtures/TestLongviewClient_Get.yaml index 4d1d729fb..8619b9f40 100644 --- a/test/integration/fixtures/TestLongviewClient_Get.yaml +++ b/test/integration/fixtures/TestLongviewClient_Get.yaml @@ -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: @@ -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: @@ -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: @@ -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: '{}' diff --git a/test/integration/fixtures/TestLongviewClient_Update.yaml b/test/integration/fixtures/TestLongviewClient_Update.yaml index 405357ed9..e9a618485 100644 --- a/test/integration/fixtures/TestLongviewClient_Update.yaml +++ b/test/integration/fixtures/TestLongviewClient_Update.yaml @@ -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: @@ -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: @@ -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: '{}' diff --git a/test/integration/longview_test.go b/test/integration/longview_test.go index 943b3d7fd..f1a176161 100644 --- a/test/integration/longview_test.go +++ b/test/integration/longview_test.go @@ -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()