Skip to content

Commit

Permalink
integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vshanthe committed Jun 25, 2024
1 parent 0b5959c commit 6a382db
Show file tree
Hide file tree
Showing 8 changed files with 357 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/integration/account_invoice_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package integration

import (
"context"
"testing"
)

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

invoices, err := client.ListInvoices(context.Background(), nil)
if err != nil {
t.Fatalf("Error getting Invoices, expected struct, got error %v", err)
}

if len(invoices) == 0 {
t.Fatalf("Expected to see invoices returned.")
}
}

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

invoice, err := client.GetInvoice(context.Background(), 123)
if err != nil {
t.Fatalf("Error getting Invoice, expected struct, got error %v", err)
}

if invoice.ID != 123 {
t.Fatalf("Expected Invoice ID to be 123, got %v", invoice.ID)
}

if invoice.Label != "Invoice" {
t.Fatalf("Expected Invoice Label to be 'Invoice', got %v", invoice.Label)
}

if invoice.Total != 132.5 {
t.Fatalf("Expected Invoice Total to be 132.5, got %v", invoice.Total)
}
}

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

items, err := client.ListInvoiceItems(context.Background(), 123, nil)
if err != nil {
t.Fatalf("Error getting Invoice Items, expected struct, got error %v", err)
}

if len(items) == 0 {
t.Fatalf("Expected to see invoice items returned.")
}

item := items[0]
if item.Label != "Linode 2GB" {
t.Fatalf("Expected item label to be 'Linode 2GB', got %v", item.Label)
}

if item.Amount != 10 {
t.Fatalf("Expected item amount to be 10, got %v", item.Amount)
}
}
69 changes: 69 additions & 0 deletions test/integration/account_settings_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package integration

import (
"context"
"testing"

"github.com/linode/linodego"
)

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

settings, err := client.GetAccountSettings(context.Background())
if err != nil {
t.Fatalf("Error getting Account Settings, expected struct, got error %v", err)
}

if settings.BackupsEnabled != true {
t.Fatalf("Expected BackupsEnabled to be true, got %v", settings.BackupsEnabled)
}

if settings.Managed != true {
t.Fatalf("Expected Managed to be true, got %v", settings.Managed)
}

if settings.NetworkHelper != true {
t.Fatalf("Expected NetworkHelper to be true, got %v", settings.NetworkHelper)
}

if settings.LongviewSubscription == nil || *settings.LongviewSubscription != "longview-3" {
t.Fatalf("Expected LongviewSubscription to be 'longview-3', got %v", settings.LongviewSubscription)
}

if settings.ObjectStorage == nil || *settings.ObjectStorage != "active" {
t.Fatalf("Expected ObjectStorage to be 'active', got %v", settings.ObjectStorage)
}
}

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

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

settings, err := client.UpdateAccountSettings(context.Background(), opts)
if err != nil {
t.Fatalf("Error updating Account Settings, expected struct, got error %v", err)
}

if settings.BackupsEnabled != false {
t.Fatalf("Expected BackupsEnabled to be false, got %v", settings.BackupsEnabled)
}

if settings.NetworkHelper != false {
t.Fatalf("Expected NetworkHelper to be false, got %v", settings.NetworkHelper)
}

if settings.LongviewSubscription == nil || *settings.LongviewSubscription != "longview-10" {
t.Fatalf("Expected LongviewSubscription to be 'longview-10', got %v", settings.LongviewSubscription)
}
}

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

import (
"context"
"testing"
)

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

transfer, err := client.GetAccountTransfer(context.Background())
if err != nil {
t.Fatalf("Error getting Account Transfer, expected struct, got error %v", err)
}

if transfer.Billable == 0 && transfer.Quota == 0 && transfer.Used == 0 {
t.Fatalf("Expected non-zero values for Billable, Quota, and Used.")
}

if len(transfer.RegionTransfers) == 0 {
t.Fatalf("Expected to see region transfers.")
}

for _, regionTransfer := range transfer.RegionTransfers {
if regionTransfer.ID == "" {
t.Errorf("Expected region ID to be non-empty.")
}
if regionTransfer.Billable == 0 && regionTransfer.Quota == 0 && regionTransfer.Used == 0 {
t.Errorf("Expected non-zero values for Billable, Quota, and 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/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
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
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: ""

0 comments on commit 6a382db

Please sign in to comment.