fix: adjust some code structure to satisfy linter
All checks were successful
ci/woodpecker/push/lint Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/deploy Pipeline was successful

This commit is contained in:
Tom Neuber 2025-04-18 15:31:05 +02:00
parent 7b30a04933
commit 4060ec09c4
Signed by: tom
GPG key ID: F17EFE4272D89FF6
7 changed files with 38 additions and 31 deletions

View file

@ -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
}

View file

@ -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)