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

Bump Golang to v1.22 #569

Merged
merged 3 commits into from
Aug 21, 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
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (c *httpClient) doRequest(ctx context.Context, method, url string, params R
err error
)

for attempt := 0; attempt < httpDefaultRetryCount; attempt++ {
for range httpDefaultRetryCount {
req, bodyBuffer, err = c.createRequest(ctx, method, url, params)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

go 1.21
go 1.22

retract v1.0.0 // Accidental branch push
2 changes: 1 addition & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.21
go 1.22

use (
.
Expand Down
2 changes: 1 addition & 1 deletion internal/duration/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func durationToSeconds(s string) (int, error) {

l := len(segs)

for i := 0; i < l; i++ {
for i := range l {
m, err := strconv.Atoi(segs[i])
if err != nil {
return 0, err
Expand Down
2 changes: 1 addition & 1 deletion k8s/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ require (

replace github.com/linode/linodego => ../

go 1.21
go 1.22
2 changes: 1 addition & 1 deletion pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func flattenQueryStruct(val any) (map[string]string, error) {

valType := reflectVal.Type()

for i := 0; i < valType.NumField(); i++ {
for i := range valType.NumField() {
currentField := valType.Field(i)

queryTag, ok := currentField.Tag.Lookup("query")
Expand Down
2 changes: 1 addition & 1 deletion test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ require (
sigs.k8s.io/yaml v1.3.0 // indirect
)

go 1.21
go 1.22

replace github.com/linode/linodego => ../

Expand Down
60 changes: 30 additions & 30 deletions test/integration/account_invoice_test.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
package integration

import (
"context"
"testing"
"context"
"testing"

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

func TestInvoice_List(t *testing.T) {
warnSensitiveTest(t)
client, teardown := createTestClient(t, "fixtures/TestInvoice_List")
defer teardown()
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")
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")
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")
}
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")
}
134 changes: 67 additions & 67 deletions test/integration/account_settings_test.go
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
package integration

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

"github.com/jarcoal/httpmock"
"github.com/linode/linodego"
"github.com/stretchr/testify/require"
"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'")
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'")
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 }
func Bool(v bool) *bool { return &v }
func String(v string) *string { return &v }
36 changes: 18 additions & 18 deletions test/integration/account_transfer_test.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package integration

import (
"context"
"testing"
"context"
"testing"

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

func TestAccountTransfer_Get(t *testing.T) {
client, teardown := createTestClient(t, "fixtures/TestAccountTransfer_Get")
defer teardown()
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")
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.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")
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)
}
}
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)
}
}
24 changes: 12 additions & 12 deletions test/integration/integration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"log/slog"
"net/http"
"os"
"regexp"
Expand All @@ -18,7 +19,6 @@ import (
"github.com/dnaeon/go-vcr/recorder"
"github.com/linode/linodego"
"golang.org/x/oauth2"
"log/slog"
"k8s.io/client-go/transport"
)

Expand Down Expand Up @@ -63,17 +63,17 @@ func init() {
}

func warnSensitiveTest(t *testing.T) {
if testingMode == recorder.ModeReplaying {
return
}

slog.Warn(
fmt.Sprintf(
"Test %s is a sensitive test. Ensure you validate and sanitize "+
"its generated test fixtures before pushing.",
t.Name(),
),
)
if testingMode == recorder.ModeReplaying {
return
}

slog.Warn(
fmt.Sprintf(
"Test %s is a sensitive test. Ensure you validate and sanitize "+
"its generated test fixtures before pushing.",
t.Name(),
),
)
}

// testRecorder returns a go-vcr recorder and an associated function that the caller must defer
Expand Down
Loading