Skip to content

Commit

Permalink
Use assert instead of require
Browse files Browse the repository at this point in the history
  • Loading branch information
renaudhartert-db committed Jul 16, 2024
1 parent 4d68012 commit 3d76a5b
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions httpclient/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"testing"

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

func make200Response(body string) *http.Response {
Expand Down Expand Up @@ -39,10 +39,10 @@ func TestWithResponseUnmarshal_structWithContent(t *testing.T) {
var got structWithContents
gotErr := c.Do(context.Background(), "GET", "/a", WithResponseUnmarshal(&got))

require.NoError(t, gotErr)
assert.NoError(t, gotErr)
wantBytes, _ := io.ReadAll(want.Contents)
gotBytes, _ := io.ReadAll(got.Contents)
require.Equal(t, wantBytes, gotBytes)
assert.Equal(t, wantBytes, gotBytes)
}

func TestWithResponseUnmarshal_readCloser(t *testing.T) {
Expand All @@ -52,10 +52,10 @@ func TestWithResponseUnmarshal_readCloser(t *testing.T) {
var got io.ReadCloser
gotErr := c.Do(context.Background(), "GET", "/a", WithResponseUnmarshal(&got))

require.NoError(t, gotErr)
assert.NoError(t, gotErr)
wantBytes, _ := io.ReadAll(want)
gotBytes, _ := io.ReadAll(got)
require.Equal(t, wantBytes, gotBytes)
assert.Equal(t, wantBytes, gotBytes)
}

func TestWithResponseUnmarshal_byteBuffer(t *testing.T) {
Expand All @@ -65,8 +65,8 @@ func TestWithResponseUnmarshal_byteBuffer(t *testing.T) {
var got bytes.Buffer
gotErr := c.Do(context.Background(), "GET", "/a", WithResponseUnmarshal(&got))

require.NoError(t, gotErr)
require.Equal(t, want.Bytes(), got.Bytes())
assert.NoError(t, gotErr)
assert.Equal(t, want.Bytes(), got.Bytes())
}

func TestWithResponseUnmarshal_bytes(t *testing.T) {
Expand All @@ -76,8 +76,8 @@ func TestWithResponseUnmarshal_bytes(t *testing.T) {
var got []byte
gotErr := c.Do(context.Background(), "GET", "/a", WithResponseUnmarshal(&got))

require.NoError(t, gotErr)
require.Equal(t, want, got)
assert.NoError(t, gotErr)
assert.Equal(t, want, got)
}

func TestWithResponseUnmarshal_json(t *testing.T) {
Expand All @@ -90,8 +90,8 @@ func TestWithResponseUnmarshal_json(t *testing.T) {
var got jsonStruct
gotErr := c.Do(context.Background(), "GET", "/a", WithResponseUnmarshal(&got))

require.NoError(t, gotErr)
require.Equal(t, want, got)
assert.NoError(t, gotErr)
assert.Equal(t, want, got)
}

func TestWithResponseHeader(t *testing.T) {
Expand All @@ -108,10 +108,9 @@ func TestWithResponseHeader(t *testing.T) {
}),
})

var out string
ctx := context.Background()
err := client.Do(ctx, "GET", "abc",
WithResponseHeader("Foo", &out))
require.NoError(t, err)
require.Equal(t, "some", out)
var got string
gotErr := client.Do(context.Background(), "GET", "abc", WithResponseHeader("Foo", &got))

assert.NoError(t, gotErr)
assert.Equal(t, "some", got)
}

0 comments on commit 3d76a5b

Please sign in to comment.