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

Integration test #561

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
44 changes: 44 additions & 0 deletions test/integration/account_invoice_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package integration

import (
"context"
"testing"

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

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

invoices, err := client.ListInvoices(context.Background(), nil)
require.NoError(t, err, "Error getting Invoices, expected struct")
require.NotEmpty(t, invoices, "Expected to see invoices returned")
}

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

invoice, err := client.GetInvoice(context.Background(), 123)
require.NoError(t, err, "Error getting Invoice, expected struct")
require.Equal(t, 123, invoice.ID, "Expected Invoice ID to be 123")
require.Equal(t, "Invoice", invoice.Label, "Expected Invoice Label to be 'Invoice'")
require.Equal(t, 132.5, float64(invoice.Total), "Expected Invoice Total to be 132.5")
}

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

items, err := client.ListInvoiceItems(context.Background(), 123, nil)
require.NoError(t, err, "Error getting Invoice Items, expected struct")
require.NotEmpty(t, items, "Expected to see invoice items returned")

item := items[0]
require.Equal(t, "Linode 2GB", item.Label, "Expected item label to be 'Linode 2GB'")
require.Equal(t, 10.0, float64(item.Amount), "Expected item amount to be 10")
}
79 changes: 79 additions & 0 deletions test/integration/account_settings_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package integration

import (
"context"
"encoding/json"
"testing"

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

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

// Mocking the API response
httpmock.Activate()
defer httpmock.DeactivateAndReset()

mockSettings := linodego.AccountSettings{
BackupsEnabled: true,
Managed: true,
NetworkHelper: true,
LongviewSubscription: String("longview-3"),
ObjectStorage: String("active"),
}
mockResponse, _ := json.Marshal(mockSettings)

httpmock.RegisterResponder("GET", "https://api.linode.com/v4/account/settings",
httpmock.NewStringResponder(200, string(mockResponse)))

settings, err := client.GetAccountSettings(context.Background())
require.NoError(t, err, "Error getting Account Settings")

require.True(t, settings.BackupsEnabled, "Expected BackupsEnabled to be true")
require.True(t, settings.Managed, "Expected Managed to be true")
require.True(t, settings.NetworkHelper, "Expected NetworkHelper to be true")
require.NotNil(t, settings.LongviewSubscription, "Expected LongviewSubscription to be non-nil")
require.Equal(t, "longview-3", *settings.LongviewSubscription, "Expected LongviewSubscription to be 'longview-3'")
require.NotNil(t, settings.ObjectStorage, "Expected ObjectStorage to be non-nil")
require.Equal(t, "active", *settings.ObjectStorage, "Expected ObjectStorage to be 'active'")
}

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

// Mocking the API response
httpmock.Activate()
defer httpmock.DeactivateAndReset()

opts := linodego.AccountSettingsUpdateOptions{
BackupsEnabled: Bool(false),
LongviewSubscription: String("longview-10"),
NetworkHelper: Bool(false),
}

mockSettings := linodego.AccountSettings{
BackupsEnabled: false,
NetworkHelper: false,
LongviewSubscription: String("longview-10"),
}
mockResponse, _ := json.Marshal(mockSettings)

httpmock.RegisterResponder("PUT", "https://api.linode.com/v4/account/settings",
httpmock.NewStringResponder(200, string(mockResponse)))

settings, err := client.UpdateAccountSettings(context.Background(), opts)
require.NoError(t, err, "Error updating Account Settings")

require.False(t, settings.BackupsEnabled, "Expected BackupsEnabled to be false")
require.False(t, settings.NetworkHelper, "Expected NetworkHelper to be false")
require.NotNil(t, settings.LongviewSubscription, "Expected LongviewSubscription to be non-nil")
require.Equal(t, "longview-10", *settings.LongviewSubscription, "Expected LongviewSubscription to be 'longview-10'")
}

func Bool(v bool) *bool { return &v }
func String(v string) *string { return &v }
29 changes: 29 additions & 0 deletions test/integration/account_transfer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package integration

import (
"context"
"testing"

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

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

transfer, err := client.GetAccountTransfer(context.Background())
require.NoError(t, err, "Error getting Account Transfer, expected struct")

require.NotEqual(t, 0, transfer.Billable, "Expected non-zero value for Billable")
require.NotEqual(t, 0, transfer.Quota, "Expected non-zero value for Quota")
require.NotEqual(t, 0, transfer.Used, "Expected non-zero value for Used")

require.NotEmpty(t, transfer.RegionTransfers, "Expected to see region transfers")

for _, regionTransfer := range transfer.RegionTransfers {
require.NotEmpty(t, regionTransfer.ID, "Expected region ID to be non-empty")
require.NotEqual(t, 0, regionTransfer.Billable, "Expected non-zero value for Billable in region %s", regionTransfer.ID)
require.NotEqual(t, 0, regionTransfer.Quota, "Expected non-zero value for Quota in region %s", regionTransfer.ID)
require.NotEqual(t, 0, regionTransfer.Used, "Expected non-zero value for Used in region %s", regionTransfer.ID)
}
}
51 changes: 51 additions & 0 deletions test/integration/fixtures/TestAccountSettings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: 1
interactions:
- request:
body: ""
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
url: https://api.linode.com/v4beta/account/settings
method: GET
response:
body: '{
"backups_enabled": true,
"managed": true,
"network_helper": true,
"longview_subscription": "longview-3",
"object_storage": "active"
}'
headers:
Content-Type:
- application/json
status: 200
code: 200
duration: ""

- request:
body: '{"backups_enabled":false,"longview_subscription":"longview-10","network_helper":false}'
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
url: https://api.linode.com/v4beta/account/settings
method: PUT
response:
body: '{
"backups_enabled": false,
"managed": true,
"network_helper": false,
"longview_subscription": "longview-10",
"object_storage": "active"
}'
headers:
Content-Type:
- application/json
status: 200
code: 200
duration: ""
79 changes: 79 additions & 0 deletions test/integration/fixtures/TestAccountTransfer_Get.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
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/account/transfer
method: GET
response:
body: '{
"billable": 100,
"quota": 1000,
"used": 200,
"region_transfers": [
{
"id": "us-east",
"billable": 50,
"quota": 500,
"used": 100
},
{
"id": "us-west",
"billable": 50,
"quota": 500,
"used": 100
}
]
}'
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
Cache-Control:
- max-age=0, no-cache, no-store
Connection:
- keep-alive
Content-Length:
- "287"
Content-Security-Policy:
- default-src 'none'
Content-Type:
- application/json
Expires:
- Tue, 16 Apr 2024 20:58:13 GMT
Pragma:
- no-cache
Strict-Transport-Security:
- max-age=31536000
Vary:
- Authorization, X-Filter
X-Accepted-Oauth-Scopes:
- account:read_only
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-Oauth-Scopes:
- account:read_write
X-Ratelimit-Limit:
- "400"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
code: 200
duration: ""
20 changes: 20 additions & 0 deletions test/integration/fixtures/TestIPv6Pool_Get.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 1
interactions:
- request:
body: ""
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
url: https://api.linode.com/v4beta/networking/ipv6/pools/2600:3c00::%2F32
method: GET
response:
body: '{"range": "2600:3c00::/32", "region": "us-east", "route_target": "2600:3c00::/32"}'
headers:
Content-Type:
- application/json
status: 200
code: 200
duration: ""
20 changes: 20 additions & 0 deletions test/integration/fixtures/TestIPv6Pool_List.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 1
interactions:
- request:
body: ""
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
url: https://api.linode.com/v4beta/networking/ipv6/pools?page=1
method: GET
response:
body: '{"data": [{"range": "2600:3c00::/32", "region": "us-east", "route_target": "2600:3c00::/32"}], "page": 1, "pages": 1, "results": 1}'
headers:
Content-Type:
- application/json
status: 200
code: 200
duration: ""
20 changes: 20 additions & 0 deletions test/integration/fixtures/TestInvoiceItems_List.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 1
interactions:
- request:
body: ""
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
url: https://api.linode.com/v4beta/account/invoices/123/items?page=1
method: GET
response:
body: '{"data": [{"label": "Linode 2GB", "type": "linode", "unitprice": 10, "quantity": 1, "amount": 10, "tax": 0.6, "region": "us-east", "from": "2018-01-01T00:00:00", "to": "2018-01-31T23:59:59"}], "page": 1, "pages": 1, "results": 1}'
headers:
Content-Type:
- application/json
status: 200
code: 200
duration: ""
20 changes: 20 additions & 0 deletions test/integration/fixtures/TestInvoice_Get.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 1
interactions:
- request:
body: ""
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
url: https://api.linode.com/v4beta/account/invoices/123
method: GET
response:
body: '{"id": 123, "label": "Invoice", "date": "2018-01-01T00:01:01", "subtotal": 120.25, "tax": 12.25, "tax_summary": [{"name": "PA STATE TAX", "tax": 12.25}], "total": 132.5, "billing_source": "linode"}'
headers:
Content-Type:
- application/json
status: 200
code: 200
duration: ""
20 changes: 20 additions & 0 deletions test/integration/fixtures/TestInvoice_List.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 1
interactions:
- request:
body: ""
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
url: https://api.linode.com/v4beta/account/invoices?page=1
method: GET
response:
body: '{"data": [{"billing_source": "linode", "date": "2018-01-01T00:01:01", "id": 123, "label": "Invoice", "subtotal": 120.25, "tax": 12.25, "tax_summary": [{"name": "PA STATE TAX", "tax": 12.25}], "total": 132.5}], "page": 1, "pages": 1, "results": 1}'
headers:
Content-Type:
- application/json
status: 200
code: 200
duration: ""
Loading