Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ func (c *Client) Do(r *Request) (resp *Response, err error) {
resp.Response, resp.err = c.httpClient.Do(req)
if resp.err == nil && resp.StatusCode >= 200 {
// set resp.body
resp.ToBytes() //nolint:errcheck
_, err = resp.ToBytes()
if err != nil {
return nil, err
}
// restore body for re-reading
resp.Body = io.NopCloser(bytes.NewReader(resp.body))
}
Expand Down
4 changes: 2 additions & 2 deletions api/hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func (it *HostnameIterator) getMoreResults() (results []*json.RawMessage, err er
return nil, err
}

r := &HostnameResults{} // nolint: exhaustruct
err = resp.Unmarshal(r)
var r HostnameResults
err = resp.Unmarshal(&r)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions api/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ func (it *Iterator) getMoreResults() (results []*SearchResult, err error) {
return nil, err
}

r := &SearchResults{} // nolint: exhaustruct
err = resp.Unmarshal(r)
var r SearchResults
err = resp.Unmarshal(&r)
if err != nil {
return nil, err
}
Expand Down
10 changes: 7 additions & 3 deletions api/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ func (r *Response) ToBytes() (body []byte, err error) {
}

defer func() {
r.Body.Close() //nolint:errcheck
closeErr := r.Body.Close()
if closeErr != nil && err == nil {
err = closeErr
}

if err != nil {
r.err = err
}
Expand Down Expand Up @@ -59,8 +63,8 @@ func (r *Response) Error() error {
return nil
}

jsonErr := &JSONError{} // nolint: exhaustruct
err := json.Unmarshal(r.body, jsonErr)
var jsonErr JSONError
err := json.Unmarshal(r.body, &jsonErr)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions api/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ func (c *Client) Scan(url string, options ...ScanOption) (*ScanResult, error) {
return nil, err
}

r := &ScanResult{} // nolint: exhaustruct
err = resp.Unmarshal(r)
var r ScanResult
err = resp.Unmarshal(&r)
if err != nil {
return nil, err
}

return r, nil
return &r, nil
}

func (c *Client) NewBatchScanTask(url string, opts ...ScanOption) BatchTask[*Response] {
Expand All @@ -162,8 +162,8 @@ func (c *Client) NewBatchScanWithWaitTask(url string, maxWait int, opts ...ScanO
return mo.Err[*Response](err)
}

scanResult := &ScanResult{} // nolint: exhaustruct
err = scanResp.Unmarshal(scanResult)
var scanResult ScanResult
err = scanResp.Unmarshal(&scanResult)
if err != nil {
return mo.Err[*Response](err)
}
Expand Down
14 changes: 14 additions & 0 deletions test/pro/hostname.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bats

load test_helper

@test "search with limit" {
run bash -c "./dist/urlscan pro hostname example.com --limit 1 | jq -r '.results | length'"
assert_output 1
}

@test "search with limit & size" {
run bash -c "./dist/urlscan pro hostname example.com --limit 10 --size 5 | jq -r '.results | length'"
assert_output 10
}

Comment on lines +1 to +14
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this for testing the change in api/hostname.go