Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: Add support LKE, Volume, NodeBalancer, and network transfer pricing endpoints #573

Merged
merged 8 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add volume types
  • Loading branch information
lgarber-akamai committed Sep 4, 2024
commit f8cab32f07b49e11e65562641da1de2c9beb31d8
4 changes: 1 addition & 3 deletions nodebalancer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import (
"context"
)

// NodeBalancerType represents a single valid LKE type.
// NOTE: This typically corresponds to the availability of a cluster's
// control plane.
// NodeBalancerType represents a single valid NodeBalancer type.
type NodeBalancerType struct {
baseType
}
Expand Down
68 changes: 68 additions & 0 deletions test/integration/fixtures/TestVolumeType_List.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
version: 1
interactions:
- request:
body: ""
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
User-Agent:
- linodego/dev https://github.com/linode/linodego
url: https://api.linode.com/v4beta/volumes/types?page=1
method: GET
response:
body: '{"data": [{"id": "volume", "label": "Storage Volume", "price": {"hourly":
0.00015, "monthly": 0.1}, "region_prices": [{"id": "id-cgk", "hourly": 0.00018,
"monthly": 0.12}, {"id": "br-gru", "hourly": 0.00021, "monthly": 0.14}], "transfer":
0}], "page": 1, "pages": 1, "results": 1}'
headers:
Access-Control-Allow-Credentials:
- "true"
Access-Control-Allow-Headers:
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter
Access-Control-Allow-Methods:
- HEAD, GET, OPTIONS, POST, PUT, DELETE
Access-Control-Allow-Origin:
- '*'
Access-Control-Expose-Headers:
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status
Akamai-Internal-Account:
- '*'
Cache-Control:
- max-age=0, no-cache, no-store
Connection:
- keep-alive
Content-Length:
- "280"
Content-Security-Policy:
- default-src 'none'
Content-Type:
- application/json
Expires:
- Wed, 04 Sep 2024 17:59:26 GMT
Pragma:
- no-cache
Strict-Transport-Security:
- max-age=31536000
Vary:
- Authorization, X-Filter
- Authorization, X-Filter
X-Accepted-Oauth-Scopes:
- '*'
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
- DENY
X-Oauth-Scopes:
- '*'
X-Ratelimit-Limit:
- "400"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
code: 200
duration: ""
40 changes: 40 additions & 0 deletions test/integration/volume_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package integration

import (
"context"
"testing"

"github.com/linode/linodego"
"github.com/stretchr/testify/require"
)

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

volumeTypes, err := client.ListVolumeTypes(context.Background(), nil)
require.NoError(t, err)
require.Greater(t, len(volumeTypes), 0)

for _, volumeType := range volumeTypes {
validateVolumeType(t, volumeType)
}
}

func validateVolumeType(
t *testing.T,
volumeType linodego.VolumeType,
) {
require.NotEmpty(t, volumeType.ID)
require.NotEmpty(t, volumeType.Label)

require.Greater(t, volumeType.Price.Hourly, 0.0)
require.Greater(t, volumeType.Price.Monthly, 0.0)
require.GreaterOrEqual(t, volumeType.Transfer, 0)

for _, regionPrice := range volumeType.RegionPrices {
require.NotEmpty(t, regionPrice.ID)
require.Greater(t, regionPrice.Hourly, 0.0)
require.Greater(t, regionPrice.Monthly, 0.0)
}
}
33 changes: 33 additions & 0 deletions volumes_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package linodego

import (
"context"
)

// VolumeType represents a single valid Volume type.
type VolumeType struct {
baseType
}

// ListVolumeTypes lists Volume types. This endpoint is cached by default.
func (c *Client) ListVolumeTypes(ctx context.Context, opts *ListOptions) ([]VolumeType, error) {
e := "volumes/types"

endpoint, err := generateListCacheURL(e, opts)
if err != nil {
return nil, err
}

if result := c.getCachedResponse(endpoint); result != nil {
return result.([]VolumeType), nil
}

response, err := getPaginatedResults[VolumeType](ctx, c, e, opts)
if err != nil {
return nil, err
}

c.addCachedResponse(endpoint, response, &cacheExpiryTime)

return response, nil
}