From 46df9e2a5f2877d6ddfde932e62b81f3801f1016 Mon Sep 17 00:00:00 2001 From: vshanthe Date: Fri, 26 Jul 2024 16:59:37 +0530 Subject: [PATCH 1/2] integration test --- test/integration/account_invoice_test.go | 44 ++++++++++ test/integration/account_settings_test.go | 79 ++++++++++++++++++ test/integration/account_transfer_test.go | 29 +++++++ test/integration/fixtures/.DS_Store | Bin 0 -> 6148 bytes .../fixtures/TestAccountSettings.yaml | 51 +++++++++++ .../fixtures/TestAccountTransfer_Get.yaml | 79 ++++++++++++++++++ .../fixtures/TestIPv6Pool_Get.yaml | 20 +++++ .../fixtures/TestIPv6Pool_List.yaml | 20 +++++ .../fixtures/TestInvoiceItems_List.yaml | 20 +++++ .../integration/fixtures/TestInvoice_Get.yaml | 20 +++++ .../fixtures/TestInvoice_List.yaml | 20 +++++ .../fixtures/TestSecurityQuestions_List.yaml | 62 ++++++++++++++ test/integration/fixtures/TestTicket_Get.yaml | 20 +++++ .../integration/fixtures/TestTicket_List.yaml | 20 +++++ test/integration/integration_suite_test.go | 16 ++++ test/integration/network_pools_test.go | 31 +++++++ .../profile_security_question_test.go | 22 +++++ test/integration/support_ticket_test.go | 33 ++++++++ 18 files changed, 586 insertions(+) create mode 100644 test/integration/account_invoice_test.go create mode 100644 test/integration/account_settings_test.go create mode 100644 test/integration/account_transfer_test.go create mode 100644 test/integration/fixtures/.DS_Store create mode 100644 test/integration/fixtures/TestAccountSettings.yaml create mode 100644 test/integration/fixtures/TestAccountTransfer_Get.yaml create mode 100644 test/integration/fixtures/TestIPv6Pool_Get.yaml create mode 100644 test/integration/fixtures/TestIPv6Pool_List.yaml create mode 100644 test/integration/fixtures/TestInvoiceItems_List.yaml create mode 100644 test/integration/fixtures/TestInvoice_Get.yaml create mode 100644 test/integration/fixtures/TestInvoice_List.yaml create mode 100644 test/integration/fixtures/TestSecurityQuestions_List.yaml create mode 100644 test/integration/fixtures/TestTicket_Get.yaml create mode 100644 test/integration/fixtures/TestTicket_List.yaml create mode 100644 test/integration/network_pools_test.go create mode 100644 test/integration/profile_security_question_test.go create mode 100644 test/integration/support_ticket_test.go diff --git a/test/integration/account_invoice_test.go b/test/integration/account_invoice_test.go new file mode 100644 index 000000000..16c1f8751 --- /dev/null +++ b/test/integration/account_invoice_test.go @@ -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") +} \ No newline at end of file diff --git a/test/integration/account_settings_test.go b/test/integration/account_settings_test.go new file mode 100644 index 000000000..a14d86cd6 --- /dev/null +++ b/test/integration/account_settings_test.go @@ -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 } \ No newline at end of file diff --git a/test/integration/account_transfer_test.go b/test/integration/account_transfer_test.go new file mode 100644 index 000000000..7490e39c7 --- /dev/null +++ b/test/integration/account_transfer_test.go @@ -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) + } +} \ No newline at end of file diff --git a/test/integration/fixtures/.DS_Store b/test/integration/fixtures/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Fri, 26 Jul 2024 17:15:47 +0530 Subject: [PATCH 2/2] fix --- test/integration/fixtures/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test/integration/fixtures/.DS_Store diff --git a/test/integration/fixtures/.DS_Store b/test/integration/fixtures/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0