Skip to content

Commit

Permalink
test: http do
Browse files Browse the repository at this point in the history
  • Loading branch information
brokeyourbike committed Aug 30, 2023
1 parent 037cb2f commit 26cdec2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/brokeyourbike/clearbank-api-client-go"
"github.com/brokeyourbike/clearbank-api-client-go/signature"
"github.com/brokeyourbike/clearbank-api-client-go/signature/local"
"github.com/sirupsen/logrus"
logrustest "github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -49,6 +50,26 @@ func TestTest(t *testing.T) {
assert.Equal(t, "123", hook.Entries[0].Data["http.request.headers.request_id"])
}

func TestFailedHttpRequest(t *testing.T) {
mockHttpClient := clearbank.NewMockHttpClient(t)
client := clearbank.NewClient("token", local.NewNilSigner(), clearbank.WithHTTPClient(mockHttpClient))

mockHttpClient.On("Do", mock.AnythingOfType("*http.Request")).Return(&http.Response{}, errors.New("cannot do")).Once()

assert.Error(t, client.Test(context.TODO(), "hello!"))
}

func TestFailedHttpRequestBodyDecode(t *testing.T) {
mockHttpClient := clearbank.NewMockHttpClient(t)
client := clearbank.NewClient("token", local.NewNilSigner(), clearbank.WithHTTPClient(mockHttpClient))

body := io.NopCloser(bytes.NewReader(nil))
require.NoError(t, body.Close())
mockHttpClient.On("Do", mock.AnythingOfType("*http.Request")).Return(&http.Response{Body: body}, nil).Once()

assert.Error(t, client.Test(context.TODO(), "hello!"))
}

func TestFailedSign(t *testing.T) {
mockSigner := signature.NewMockSigner(t)
mockHttpClient := clearbank.NewMockHttpClient(t)
Expand Down

0 comments on commit 26cdec2

Please sign in to comment.