Skip to content

Commit

Permalink
Merge branch 'main' into zhiwei/enforce-format-for-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zliang-akamai authored Feb 7, 2025
2 parents 01e22d6 + 635a017 commit a400d98
Show file tree
Hide file tree
Showing 132 changed files with 6,905 additions and 2,798 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
python-version: '3.x'

- name: Install Python deps
run: pip3 install requests wheel boto3
run: pip3 install requests wheel boto3==1.35.99

- name: Install go-junit-report
run: go install github.com/jstemmer/go-junit-report/v2@latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: actions/checkout@v4
-
name: Run Labeler
uses: crazy-max/ghaction-github-labeler@b54af0c25861143e7c8813d7cbbf46d2c341680c
uses: crazy-max/ghaction-github-labeler@31674a3852a9074f2086abcf1c53839d466a47e7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
yaml-file: .github/labels.yml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly_smoke_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Run smoke tests
id: smoke_tests
run: |
make smoketest
make test-smoke
env:
LINODE_TOKEN: ${{ secrets.DX_LINODE_TOKEN }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-cross-repo-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ jobs:
- name: run tests
run: |
make int-test
make test-int
env:
LINODE_TOKEN: ${{ secrets.DX_LINODE_TOKEN }}
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ PACKAGES := $(shell go list ./... | grep -v integration)

SKIP_LINT ?= 0

.PHONY: build vet test refresh-fixtures clean clean-cov clean-fixtures lint run_fixtures sanitize fixtures godoc testint testunit testcov tidy
.PHONY: build vet test refresh-fixtures clean clean-cov clean-fixtures lint run_fixtures sanitize fixtures godoc test-int test-unit test-smoke testcov tidy

test: build lint testunit testint
test: build lint test-unit test-int

citest: lint test

testunit:
go test -v $(PACKAGES) $(ARGS)
cd test && make testunit
test-unit:
go test -v $(PACKAGES) $(TEST_ARGS)
cd test && make test-unit

testint:
cd test && make testint
test-int:
cd test && make test-int

testcov-func:
@go test -v -coverprofile="coverage.txt" . > /dev/null 2>&1
Expand All @@ -39,8 +39,8 @@ testcov-html:
@go test -v -coverprofile="coverage.txt" . > /dev/null 2>&1
@go tool cover -html coverage.txt

smoketest:
cd test && make smoketest
test-smoke:
cd test && make test-smoke

build: vet lint
go build ./...
Expand Down Expand Up @@ -77,7 +77,7 @@ run_fixtures:
LINODE_API_VERSION="v4beta" \
LINODE_URL="$(LINODE_URL)" \
GO111MODULE="on" \
go test --tags $(TEST_TAGS) -timeout=$(TEST_TIMEOUT) -v $(ARGS)
go test --tags $(TEST_TAGS) -timeout=$(TEST_TIMEOUT) -v $(TEST_ARGS)

sanitize:
@echo "* Sanitizing fixtures"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ When performing a `POST` or `PUT` request, multiple field related errors will be

## Tests

Run `make testunit` to run the unit tests.
Run `make test-unit` to run the unit tests.

Run `make testint` to run the integration tests. The integration tests use fixtures.
Run `make test-int` to run the integration tests. The integration tests use fixtures.

To update the test fixtures, run `make fixtures`. This will record the API responses into the `fixtures/` directory.
Be careful about committing any sensitive account details. An attempt has been made to sanitize IP addresses and
dates, but no automated sanitization will be performed against `fixtures/*Account*.yaml`, for example.

To prevent disrupting unaffected fixtures, target fixture generation like so: `make ARGS="-run TestListVolumes" fixtures`.
To prevent disrupting unaffected fixtures, target fixture generation like so: `make TEST_ARGS="-run TestListVolumes" fixtures`.

## Discussion / Help

Expand Down
3 changes: 1 addition & 2 deletions account_agreements.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ func (c *Client) GetAccountAgreements(ctx context.Context) (*AccountAgreements,

// AcknowledgeAccountAgreements acknowledges account agreements for the Account
func (c *Client) AcknowledgeAccountAgreements(ctx context.Context, opts AccountAgreementsUpdateOptions) error {
_, err := doPOSTRequest[AccountAgreements](ctx, c, "account/agreements", opts)
return err
return doPOSTRequestNoResponseBody(ctx, c, "account/agreements", opts)
}
14 changes: 2 additions & 12 deletions account_availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,11 @@ type AccountAvailability struct {

// ListAccountAvailabilities lists all regions and the resource availabilities to the account.
func (c *Client) ListAccountAvailabilities(ctx context.Context, opts *ListOptions) ([]AccountAvailability, error) {
response, err := getPaginatedResults[AccountAvailability](ctx, c, "account/availability", opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[AccountAvailability](ctx, c, "account/availability", opts)
}

// GetAccountAvailability gets the resources availability in a region to the customer.
func (c *Client) GetAccountAvailability(ctx context.Context, regionID string) (*AccountAvailability, error) {
b := formatAPIPath("account/availability/%s", regionID)
response, err := doGETRequest[AccountAvailability](ctx, c, b)
if err != nil {
return nil, err
}

return response, nil
return doGETRequest[AccountAvailability](ctx, c, b)
}
25 changes: 4 additions & 21 deletions account_betas.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,16 @@ func (cBeta *AccountBetaProgram) UnmarshalJSON(b []byte) error {

// ListAccountBetaPrograms lists all beta programs an account is enrolled in.
func (c *Client) ListAccountBetaPrograms(ctx context.Context, opts *ListOptions) ([]AccountBetaProgram, error) {
response, err := getPaginatedResults[AccountBetaProgram](ctx, c, "/account/betas", opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[AccountBetaProgram](ctx, c, "/account/betas", opts)
}

// GetAccountBetaProgram gets the details of a beta program an account is enrolled in.
func (c *Client) GetAccountBetaProgram(ctx context.Context, betaID string) (*AccountBetaProgram, error) {
b := formatAPIPath("/account/betas/%s", betaID)

response, err := doGETRequest[AccountBetaProgram](ctx, c, b)
if err != nil {
return nil, err
}

return response, nil
e := formatAPIPath("/account/betas/%s", betaID)
return doGETRequest[AccountBetaProgram](ctx, c, e)
}

// JoinBetaProgram enrolls an account into a beta program.
func (c *Client) JoinBetaProgram(ctx context.Context, opts AccountBetaProgramCreateOpts) (*AccountBetaProgram, error) {
e := "account/betas"
response, err := doPOSTRequest[AccountBetaProgram](ctx, c, e, opts)
if err != nil {
return nil, err
}

return response, nil
return doPOSTRequest[AccountBetaProgram](ctx, c, "account/betas", opts)
}
20 changes: 4 additions & 16 deletions account_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,35 +300,23 @@ func (i *Event) UnmarshalJSON(b []byte) error {
// on the Account. The Events returned depend on the token grants and the grants
// of the associated user.
func (c *Client) ListEvents(ctx context.Context, opts *ListOptions) ([]Event, error) {
response, err := getPaginatedResults[Event](ctx, c, "account/events", opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[Event](ctx, c, "account/events", opts)
}

// GetEvent gets the Event with the Event ID
func (c *Client) GetEvent(ctx context.Context, eventID int) (*Event, error) {
e := formatAPIPath("account/events/%d", eventID)
response, err := doGETRequest[Event](ctx, c, e)
if err != nil {
return nil, err
}

return response, nil
return doGETRequest[Event](ctx, c, e)
}

// MarkEventRead marks a single Event as read.
func (c *Client) MarkEventRead(ctx context.Context, event *Event) error {
e := formatAPIPath("account/events/%d/read", event.ID)
_, err := doPOSTRequest[Event](ctx, c, e, []any{})
return err
return doPOSTRequestNoRequestResponseBody(ctx, c, e)
}

// MarkEventsSeen marks all Events up to and including this Event by ID as seen.
func (c *Client) MarkEventsSeen(ctx context.Context, event *Event) error {
e := formatAPIPath("account/events/%d/seen", event.ID)
_, err := doPOSTRequest[Event](ctx, c, e, []any{})
return err
return doPOSTRequestNoRequestResponseBody(ctx, c, e)
}
21 changes: 3 additions & 18 deletions account_invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ type InvoiceItem struct {

// ListInvoices gets a paginated list of Invoices against the Account
func (c *Client) ListInvoices(ctx context.Context, opts *ListOptions) ([]Invoice, error) {
response, err := getPaginatedResults[Invoice](ctx, c, "account/invoices", opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[Invoice](ctx, c, "account/invoices", opts)
}

// UnmarshalJSON implements the json.Unmarshaler interface
Expand Down Expand Up @@ -94,20 +89,10 @@ func (i *InvoiceItem) UnmarshalJSON(b []byte) error {
// GetInvoice gets a single Invoice matching the provided ID
func (c *Client) GetInvoice(ctx context.Context, invoiceID int) (*Invoice, error) {
e := formatAPIPath("account/invoices/%d", invoiceID)
response, err := doGETRequest[Invoice](ctx, c, e)
if err != nil {
return nil, err
}

return response, nil
return doGETRequest[Invoice](ctx, c, e)
}

// ListInvoiceItems gets the invoice items associated with a specific Invoice
func (c *Client) ListInvoiceItems(ctx context.Context, invoiceID int, opts *ListOptions) ([]InvoiceItem, error) {
response, err := getPaginatedResults[InvoiceItem](ctx, c, formatAPIPath("account/invoices/%d/items", invoiceID), opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[InvoiceItem](ctx, c, formatAPIPath("account/invoices/%d/items", invoiceID), opts)
}
15 changes: 2 additions & 13 deletions account_logins.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ type Login struct {
}

func (c *Client) ListLogins(ctx context.Context, opts *ListOptions) ([]Login, error) {
response, err := getPaginatedResults[Login](ctx, c, "account/logins", opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[Login](ctx, c, "account/logins", opts)
}

// UnmarshalJSON implements the json.Unmarshaler interface
Expand All @@ -48,11 +43,5 @@ func (i *Login) UnmarshalJSON(b []byte) error {

func (c *Client) GetLogin(ctx context.Context, loginID int) (*Login, error) {
e := formatAPIPath("account/logins/%d", loginID)

response, err := doGETRequest[Login](ctx, c, e)
if err != nil {
return nil, err
}

return response, nil
return doGETRequest[Login](ctx, c, e)
}
7 changes: 1 addition & 6 deletions account_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,7 @@ const (
// have been resolved. For example, if the account has an important Ticket open, a response
// to the Ticket will dismiss the Notification.
func (c *Client) ListNotifications(ctx context.Context, opts *ListOptions) ([]Notification, error) {
response, err := getPaginatedResults[Notification](ctx, c, "account/notifications", opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[Notification](ctx, c, "account/notifications", opts)
}

// UnmarshalJSON implements the json.Unmarshaler interface
Expand Down
39 changes: 6 additions & 33 deletions account_oauth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,61 +82,34 @@ func (i OAuthClient) GetUpdateOptions() (o OAuthClientUpdateOptions) {

// ListOAuthClients lists OAuthClients
func (c *Client) ListOAuthClients(ctx context.Context, opts *ListOptions) ([]OAuthClient, error) {
response, err := getPaginatedResults[OAuthClient](ctx, c, "account/oauth-clients", opts)
if err != nil {
return nil, err
}

return response, nil
return getPaginatedResults[OAuthClient](ctx, c, "account/oauth-clients", opts)
}

// GetOAuthClient gets the OAuthClient with the provided ID
func (c *Client) GetOAuthClient(ctx context.Context, clientID string) (*OAuthClient, error) {
e := formatAPIPath("account/oauth-clients/%s", clientID)
response, err := doGETRequest[OAuthClient](ctx, c, e)
if err != nil {
return nil, err
}

return response, nil
return doGETRequest[OAuthClient](ctx, c, e)
}

// CreateOAuthClient creates an OAuthClient
func (c *Client) CreateOAuthClient(ctx context.Context, opts OAuthClientCreateOptions) (*OAuthClient, error) {
e := "account/oauth-clients"
response, err := doPOSTRequest[OAuthClient](ctx, c, e, opts)
if err != nil {
return nil, err
}

return response, nil
return doPOSTRequest[OAuthClient](ctx, c, "account/oauth-clients", opts)
}

// UpdateOAuthClient updates the OAuthClient with the specified id
func (c *Client) UpdateOAuthClient(ctx context.Context, clientID string, opts OAuthClientUpdateOptions) (*OAuthClient, error) {
e := formatAPIPath("account/oauth-clients/%s", clientID)
response, err := doPUTRequest[OAuthClient](ctx, c, e, opts)
if err != nil {
return nil, err
}

return response, nil
return doPUTRequest[OAuthClient](ctx, c, e, opts)
}

// DeleteOAuthClient deletes the OAuthClient with the specified id
func (c *Client) DeleteOAuthClient(ctx context.Context, clientID string) error {
e := formatAPIPath("account/oauth-clients/%s", clientID)
err := doDELETERequest(ctx, c, e)
return err
return doDELETERequest(ctx, c, e)
}

// ResetOAuthClientSecret resets the OAuth Client secret for a client with a specified id
func (c *Client) ResetOAuthClientSecret(ctx context.Context, clientID string) (*OAuthClient, error) {
e := formatAPIPath("account/oauth-clients/%s/reset-secret", clientID)
response, err := doPOSTRequest[OAuthClient, any](ctx, c, e)
if err != nil {
return nil, err
}

return response, nil
return doPOSTRequest[OAuthClient, any](ctx, c, e)
}
6 changes: 2 additions & 4 deletions account_payment_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,11 @@ func (c *Client) DeletePaymentMethod(ctx context.Context, paymentMethodID int) e

// AddPaymentMethod adds the provided payment method to the account
func (c *Client) AddPaymentMethod(ctx context.Context, opts PaymentMethodCreateOptions) error {
_, err := doPOSTRequest[PaymentMethod, any](ctx, c, "account/payment-methods", opts)
return err
return doPOSTRequestNoResponseBody(ctx, c, "account/payment-methods", opts)
}

// SetDefaultPaymentMethod sets the payment method with the provided ID as the default
func (c *Client) SetDefaultPaymentMethod(ctx context.Context, paymentMethodID int) error {
e := formatAPIPath("account/payment-methods/%d", paymentMethodID)
_, err := doPOSTRequest[PaymentMethod, any](ctx, c, e)
return err
return doPOSTRequestNoRequestResponseBody(ctx, c, e)
}
Loading

0 comments on commit a400d98

Please sign in to comment.