Skip to content

Commit

Permalink
🐛 Edited the api_client_impl.go
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreminiom committed Jul 24, 2023
1 parent 929d8c0 commit 415ac90
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions jira/v2/api_client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,12 @@ func (c *Client) NewRequest(ctx context.Context, method, urlStr, type_ string, b
}
}

// If the body interface is a *bytes.Buffer type
// it means the NewRequest() requires to handle the RFC 1867 ISO
if attachBuffer, ok := body.(*bytes.Buffer); ok {
buf = attachBuffer
}

req, err := http.NewRequestWithContext(ctx, method, u.String(), buf)
if err != nil {
return nil, err
Expand Down
18 changes: 18 additions & 0 deletions jira/v2/api_client_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,24 @@ func TestClient_NewRequest(t *testing.T) {
wantErr: false,
},

{
name: "when the content type is provided",
fields: fields{
HTTP: http.DefaultClient,
Auth: authMocked,
Site: siteAsURL,
},
args: args{
ctx: context.TODO(),
method: http.MethodGet,
urlStr: "rest/2/issue/attachment",
type_: "type_sample",
body: bytes.NewReader([]byte("Hello World")),
},
want: requestMocked,
wantErr: false,
},

{
name: "when the url cannot be parsed",
fields: fields{
Expand Down
6 changes: 6 additions & 0 deletions jira/v3/api_client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,12 @@ func (c *Client) NewRequest(ctx context.Context, method, urlStr, type_ string, b
}
}

// If the body interface is a *bytes.Buffer type
// it means the NewRequest() requires to handle the RFC 1867 ISO
if attachBuffer, ok := body.(*bytes.Buffer); ok {
buf = attachBuffer
}

req, err := http.NewRequestWithContext(ctx, method, u.String(), buf)
if err != nil {
return nil, err
Expand Down
18 changes: 18 additions & 0 deletions jira/v3/api_client_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,24 @@ func TestClient_NewRequest(t *testing.T) {
wantErr: true,
},

{
name: "when the content type is provided",
fields: fields{
HTTP: http.DefaultClient,
Auth: authMocked,
Site: siteAsURL,
},
args: args{
ctx: context.TODO(),
method: http.MethodGet,
urlStr: "rest/2/issue/attachment",
type_: "type_sample",
body: bytes.NewReader([]byte("Hello World")),
},
want: requestMocked,
wantErr: false,
},

{
name: "when the request cannot be created",
fields: fields{
Expand Down

0 comments on commit 415ac90

Please sign in to comment.