Skip to content

Commit

Permalink
Merge pull request #12 from DataDog/james.pond/fix-lint-errors
Browse files Browse the repository at this point in the history
Convert dynamic errors to constants
  • Loading branch information
jamesponddotco authored May 6, 2024
2 parents 40628e6 + 8f78cea commit bff3d19
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions internal/xhttp/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ package xhttp_test

import (
"bytes"
"errors"
"fmt"
"io"
"net/http"
"testing"

"github.com/DataDog/cloudcraft-go/internal/xerrors"
"github.com/DataDog/cloudcraft-go/internal/xhttp"
)

const ErrMockClose xerrors.Error = "mock close error"

type errReader struct{}

func (*errReader) Read(_ []byte) (n int, err error) {
Expand All @@ -30,7 +32,7 @@ func (c *customReadCloser) Read(p []byte) (n int, err error) {
}

func (*customReadCloser) Close() error {
return errors.New("mock close error")
return fmt.Errorf("%w", ErrMockClose)
}

func TestDrainResponseBody(t *testing.T) {
Expand Down Expand Up @@ -96,7 +98,7 @@ func TestDrainResponseBody_ErrorClose(t *testing.T) {
t.Error("expected error, got nil")
}

want := fmt.Errorf("%w: %w", xhttp.ErrCannotCloseResponse, errors.New("mock close error"))
want := fmt.Errorf("%w: %w", xhttp.ErrCannotCloseResponse, ErrMockClose)
if err.Error() != want.Error() {
t.Errorf("got: %v, want: %v", err, want)
}
Expand Down
5 changes: 4 additions & 1 deletion internal/xhttp/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import (
"testing"
"time"

"github.com/DataDog/cloudcraft-go/internal/xerrors"
"github.com/DataDog/cloudcraft-go/internal/xhttp"
)

const ErrGenericError xerrors.Error = "generic error"

func TestRetryPolicy_Wait(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -111,7 +114,7 @@ func TestDefaultIsRetryable(t *testing.T) {
{
name: "Error occurs",
giveResp: nil,
giveError: errors.New("error"),
giveError: ErrGenericError,
want: true,
},
{
Expand Down

0 comments on commit bff3d19

Please sign in to comment.