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

Replace Deprecations and Fix some Comments #392

Merged
merged 3 commits into from
Oct 6, 2023
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

# Common IDE paths
.vscode/
.idea/

vendor/**/
.env
coverage.txt

4 changes: 2 additions & 2 deletions account_invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Invoice struct {
Date *time.Time `json:"-"`
}

// InvoiceItem structs reflect an single billable activity associate with an Invoice
// InvoiceItem structs reflect a single billable activity associate with an Invoice
type InvoiceItem struct {
Label string `json:"label"`
Type string `json:"type"`
Expand Down Expand Up @@ -105,7 +105,7 @@ func (i *InvoiceItem) UnmarshalJSON(b []byte) error {
return nil
}

// GetInvoice gets the a single Invoice matching the provided ID
// GetInvoice gets a single Invoice matching the provided ID
func (c *Client) GetInvoice(ctx context.Context, invoiceID int) (*Invoice, error) {
req := c.R(ctx).SetResult(&Invoice{})
e := fmt.Sprintf("account/invoices/%d", invoiceID)
Expand Down
7 changes: 3 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package linodego
import (
"context"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -166,7 +165,7 @@ func (c *Client) updateHostURL() {
apiProto = c.apiProto
}

c.resty.SetHostURL(
c.resty.SetBaseURL(
fmt.Sprintf(
"%s://%s/%s",
apiProto,
Expand All @@ -183,7 +182,7 @@ func (c *Client) SetRootCertificate(path string) *Client {
}

// SetToken sets the API token for all requests from this client
// Only necessary if you haven't already provided an http client to NewClient() configured with the token.
// Only necessary if you haven't already provided the http client to NewClient() configured with the token.
func (c *Client) SetToken(token string) *Client {
c.resty.SetHeader("Authorization", fmt.Sprintf("Bearer %s", token))
return c
Expand Down Expand Up @@ -398,7 +397,7 @@ func NewClient(hc *http.Client) (client Client) {
certPath, certPathExists := os.LookupEnv(APIHostCert)

if certPathExists {
cert, err := ioutil.ReadFile(filepath.Clean(certPath))
cert, err := os.ReadFile(filepath.Clean(certPath))
if err != nil {
log.Fatalf("[ERROR] Error when reading cert at %s: %s\n", certPath, err.Error())
}
Expand Down
20 changes: 10 additions & 10 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,39 @@ func TestClient_SetAPIVersion(t *testing.T) {

client := NewClient(nil)

if client.resty.HostURL != defaultURL {
t.Fatal(cmp.Diff(client.resty.HostURL, defaultURL))
if client.resty.BaseURL != defaultURL {
t.Fatal(cmp.Diff(client.resty.BaseURL, defaultURL))
}

client.SetBaseURL(baseURL)
client.SetAPIVersion(apiVersion)

if client.resty.HostURL != expectedHost {
t.Fatal(cmp.Diff(client.resty.HostURL, expectedHost))
if client.resty.BaseURL != expectedHost {
t.Fatal(cmp.Diff(client.resty.BaseURL, expectedHost))
}

// Ensure setting twice does not cause conflicts
client.SetBaseURL(updatedBaseURL)
client.SetAPIVersion(updatedAPIVersion)

if client.resty.HostURL != updatedExpectedHost {
t.Fatal(cmp.Diff(client.resty.HostURL, updatedExpectedHost))
if client.resty.BaseURL != updatedExpectedHost {
t.Fatal(cmp.Diff(client.resty.BaseURL, updatedExpectedHost))
}

// Revert
client.SetBaseURL(baseURL)
client.SetAPIVersion(apiVersion)

if client.resty.HostURL != expectedHost {
t.Fatal(cmp.Diff(client.resty.HostURL, expectedHost))
if client.resty.BaseURL != expectedHost {
t.Fatal(cmp.Diff(client.resty.BaseURL, expectedHost))
}

// Custom protocol
client.SetBaseURL(protocolBaseURL)
client.SetAPIVersion(protocolAPIVersion)

if client.resty.HostURL != protocolExpectedHost {
t.Fatal(cmp.Diff(client.resty.HostURL, expectedHost))
if client.resty.BaseURL != protocolExpectedHost {
t.Fatal(cmp.Diff(client.resty.BaseURL, expectedHost))
}
}

Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type LoadConfigOptions struct {
SkipLoadProfile bool
}

// LoadConfig loads a Linode config according to the options argument.
// LoadConfig loads a Linode config according to the option's argument.
// If no options are specified, the following defaults will be used:
// Path: ~/.config/linode
// Profile: default
Expand Down
11 changes: 5 additions & 6 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package linodego

import (
"fmt"
"io/ioutil"
"os"
"testing"
)
Expand Down Expand Up @@ -43,8 +42,8 @@ func TestConfig_LoadWithDefaults(t *testing.T) {

expectedURL := "https://api.cool.linode.com/v4beta"

if client.resty.HostURL != expectedURL {
t.Fatalf("mismatched host url: %s != %s", client.resty.HostURL, expectedURL)
if client.resty.BaseURL != expectedURL {
t.Fatalf("mismatched host url: %s != %s", client.resty.BaseURL, expectedURL)
}

if client.resty.Header.Get("Authorization") != "Bearer "+p.APIToken {
Expand Down Expand Up @@ -89,8 +88,8 @@ func TestConfig_OverrideDefaults(t *testing.T) {

expectedURL := "https://api.cool.linode.com/v4"

if client.resty.HostURL != expectedURL {
t.Fatalf("mismatched host url: %s != %s", client.resty.HostURL, expectedURL)
if client.resty.BaseURL != expectedURL {
t.Fatalf("mismatched host url: %s != %s", client.resty.BaseURL, expectedURL)
}

if client.resty.Header.Get("Authorization") != "Bearer "+p.APIToken {
Expand Down Expand Up @@ -131,7 +130,7 @@ func TestConfig_NoDefaults(t *testing.T) {
}

func createTestConfig(t *testing.T, conf string) *os.File {
file, err := ioutil.TempFile("", "linode")
file, err := os.CreateTemp("", "linode")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"errors"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -114,7 +114,7 @@ func TestCoupleAPIErrors_badGatewayError(t *testing.T) {
<hr><center>nginx</center>
</body>
</html>`)
buf := ioutil.NopCloser(bytes.NewBuffer(rawResponse))
buf := io.NopCloser(bytes.NewBuffer(rawResponse))

resp := &resty.Response{
Request: &resty.Request{
Expand Down
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ require (
github.com/go-resty/resty/v2 v2.7.0
github.com/google/go-cmp v0.5.7
golang.org/x/net v0.15.0
golang.org/x/text v0.13.0
gopkg.in/ini.v1 v1.66.6
)

require (
github.com/stretchr/testify v1.8.4 // indirect
golang.org/x/text v0.13.0 // indirect
)
require github.com/stretchr/testify v1.8.4 // indirect

go 1.20

Expand Down
2 changes: 1 addition & 1 deletion images.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (c *Client) GetImage(ctx context.Context, imageID string) (*Image, error) {
return r.Result().(*Image), nil
}

// CreateImage creates a Image
// CreateImage creates an Image
func (c *Client) CreateImage(ctx context.Context, opts ImageCreateOptions) (*Image, error) {
body, err := json.Marshal(opts)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
MySQLDatabaseTargetSecondary MySQLDatabaseTarget = "secondary"
)

// A MySQLDatabase is a instance of Linode MySQL Managed Databases
// A MySQLDatabase is an instance of Linode MySQL Managed Databases
type MySQLDatabase struct {
ID int `json:"id"`
Status DatabaseStatus `json:"status"`
Expand Down
2 changes: 1 addition & 1 deletion postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const (
PostgresReplicationSemiSynch PostgresReplicationType = "semi_synch"
)

// A PostgresDatabase is a instance of Linode Postgres Managed Databases
// A PostgresDatabase is an instance of Linode Postgres Managed Databases
type PostgresDatabase struct {
ID int `json:"id"`
Status DatabaseStatus `json:"status"`
Expand Down
2 changes: 1 addition & 1 deletion test/integration/longview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestLongviewClient_Delete(t *testing.T) {
t.Errorf("Error getting longview client:%s", getErr)
}

// If there is no error, the longview client was delete properly
// If there is no error, the longview client was deleted properly
if err := client.DeleteLongviewClient(context.Background(), testingLongviewClient.ID); err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions test/integration/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package integration
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"reflect"
"regexp"
Expand All @@ -29,7 +29,7 @@ func mockRequestBodyValidate(t *testing.T, expected interface{}, response interf

i := result.Interface()

data, err := ioutil.ReadAll(request.Body)
data, err := io.ReadAll(request.Body)
if err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 6 additions & 2 deletions waitfor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import (
"log"
"net/http"
"strconv"
"strings"
"time"

"golang.org/x/text/cases"
"golang.org/x/text/language"
)

var englishTitle = cases.Title(language.English)

type EventPoller struct {
EntityID any
EntityType EntityType
Expand Down Expand Up @@ -284,7 +288,7 @@ func (client Client) WaitForEventFinished(
minStart time.Time,
timeoutSeconds int,
) (*Event, error) {
titledEntityType := strings.Title(string(entityType))
titledEntityType := englishTitle.String(string(entityType))
filter := Filter{
Order: Descending,
OrderBy: "created",
Expand Down