Skip to content

Commit

Permalink
fix content-length header
Browse files Browse the repository at this point in the history
  • Loading branch information
jfeodor committed Jun 10, 2024
1 parent 8af23de commit e964459
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions cli/internal/app/upload_app_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"github.com/stretchr/testify/mock"
)

func dummyReader() io.Reader {
return bytes.NewBuffer([]byte("some data"))
}

func TestUploadAppSource(t *testing.T) {
testError := errors.New("some test error")

Expand All @@ -22,7 +26,7 @@ func TestUploadAppSource(t *testing.T) {
doer.On("Do", mock.Anything).Return(nilResp, testError)
s := Service{uploadDoer: &doer}

err := s.UploadAppSource("http://some-upload-url", io.NopCloser(bytes.NewReader([]byte(""))))
err := s.UploadAppSource("http://some-upload-url", dummyReader())

assert.ErrorIs(t, err, testError)
})
Expand All @@ -33,15 +37,15 @@ func TestUploadAppSource(t *testing.T) {
doer.On("Do", mock.Anything).Return(&resp, nil)
s := Service{uploadDoer: &doer}

err := s.UploadAppSource("http://some-upload-url", io.NopCloser(bytes.NewReader([]byte(""))))
err := s.UploadAppSource("http://some-upload-url", dummyReader())

assert.ErrorIs(t, err, ErrAppSourceUpload)
})

t.Run("given invalid upload URL then it returns error", func(t *testing.T) {
s := Service{uploadDoer: &test.MockDoer{}}

err := s.UploadAppSource("://invalid-url", io.NopCloser(bytes.NewReader([]byte(""))))
err := s.UploadAppSource("://invalid-url", dummyReader())

assert.Error(t, err)
})
Expand All @@ -52,7 +56,7 @@ func TestUploadAppSource(t *testing.T) {
doer.On("Do", mock.Anything).Return(&resp, nil)
s := Service{uploadDoer: &doer}

err := s.UploadAppSource("http://some-upload-url", io.NopCloser(bytes.NewReader([]byte(""))))
err := s.UploadAppSource("http://some-upload-url", bytes.NewReader([]byte("")))

assert.NoError(t, err)
})
Expand All @@ -62,7 +66,7 @@ func TestUploadAppSource(t *testing.T) {
resp := http.Response{Status: "OK", StatusCode: http.StatusOK}
doer.On("Do", mock.Anything).Return(&resp, nil)
s := Service{uploadDoer: &doer}
err := s.UploadAppSource("http://some-upload-url", io.NopCloser(bytes.NewReader([]byte("some data"))))
err := s.UploadAppSource("http://some-upload-url", bytes.NewReader([]byte("some data")))

assert.NoError(t, err)
doer.AssertCalled(t, "Do", mock.MatchedBy(func(r *http.Request) bool {
Expand Down

0 comments on commit e964459

Please sign in to comment.