fix: adjust some code structure to satisfy linter
This commit is contained in:
parent
7b30a04933
commit
4060ec09c4
7 changed files with 38 additions and 31 deletions
|
@ -40,7 +40,10 @@ func (c *Context) Download() error {
|
|||
}
|
||||
return err
|
||||
}
|
||||
defer resp.Close()
|
||||
if err = resp.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
return ErrInvalidURL
|
||||
}
|
||||
|
@ -50,19 +53,19 @@ func (c *Context) Download() error {
|
|||
if resp.StatusCode != http.StatusOK {
|
||||
return errors.New(resp.RawResponse.Status)
|
||||
}
|
||||
resp.Close()
|
||||
|
||||
resp, err = req.Get(c.Link, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Close()
|
||||
|
||||
var filesize int64
|
||||
if resp.RawResponse.ContentLength > -1 {
|
||||
filesize = resp.RawResponse.ContentLength
|
||||
}
|
||||
|
||||
destFile, err := os.OpenFile(c.Filename, os.O_CREATE|os.O_WRONLY, 0644)
|
||||
destFile, err := os.OpenFile(c.Filename, os.O_CREATE|os.O_WRONLY, 0600)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -58,7 +58,10 @@ func TestDownload(t *testing.T) {
|
|||
|
||||
t.Run("CertificateError", func(t *testing.T) {
|
||||
// This test assumes a self-signed certificate or similar issue. This is hard to simulate in a unit test.
|
||||
ctx := downloader.NewContext("test_cert_error.txt", "https://self-signed.badssl.com/") // Example URL that can be used
|
||||
ctx := downloader.NewContext(
|
||||
"test_cert_error.txt",
|
||||
"https://self-signed.badssl.com/", // Example URL that can be used
|
||||
)
|
||||
|
||||
if err := ctx.Download(); err == nil || err.Error() != "certificate from unknown authority" {
|
||||
t.Errorf("expected certificate from unknown authority error, got %v", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue