go1.24: fix lint, unit and system tests

- development env: base on debian trixie with go1.24
- lint: run with default config
- fix lint errors
- fix unit tests
- fix system test
This commit is contained in:
André Roth
2025-04-12 17:53:48 +02:00
parent ae5379d84a
commit f7057a9517
117 changed files with 803 additions and 727 deletions

View File

@@ -12,20 +12,18 @@ import (
"github.com/aptly-dev/aptly/utils"
"github.com/aws/aws-sdk-go-v2/aws"
v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
signer "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/aws/smithy-go"
smithy "github.com/aws/smithy-go"
"github.com/aws/smithy-go/logging"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
const errCodeNotFound = "NotFound"
type logger struct{}
func (l *logger) Logf(classification logging.Classification, format string, v ...interface{}) {
@@ -90,7 +88,7 @@ func NewPublishedStorageRaw(
result := &PublishedStorage{
s3: s3.NewFromConfig(*config, func(o *s3.Options) {
o.UsePathStyle = !forceVirtualHostedStyle
o.HTTPSignerV4 = v4.NewSigner()
o.HTTPSignerV4 = signer.NewSigner()
o.BaseEndpoint = baseEndpoint
}),
bucket: bucket,
@@ -149,7 +147,7 @@ func NewPublishedStorage(
return result, err
}
// String
// String returns the storage as string
func (storage *PublishedStorage) String() string {
return fmt.Sprintf("S3: %s:%s/%s", storage.config.Region, storage.bucket, storage.prefix)
}
@@ -170,7 +168,7 @@ func (storage *PublishedStorage) PutFile(path string, sourceFilename string) err
if err != nil {
return err
}
defer source.Close()
defer func() { _ = source.Close() }()
log.Debug().Msgf("S3: PutFile '%s'", path)
err = storage.putFile(path, source, "")
@@ -385,7 +383,7 @@ func (storage *PublishedStorage) LinkFromPool(publishedPrefix, publishedRelPath,
if err != nil {
return err
}
defer source.Close()
defer func() { _ = source.Close() }()
log.Debug().Msgf("S3: LinkFromPool '%s'", relPath)
err = storage.putFile(relPath, source, sourceMD5)

View File

@@ -3,7 +3,7 @@ package s3
import (
"bytes"
"context"
"io/ioutil"
"io"
"os"
"path/filepath"
"sort"
@@ -70,8 +70,8 @@ func (s *PublishedStorageSuite) GetFile(c *C, path string) []byte {
})
c.Assert(err, IsNil)
body, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
body, err := io.ReadAll(resp.Body)
_ = resp.Body.Close()
c.Assert(err, IsNil)
return body
@@ -98,7 +98,7 @@ func (s *PublishedStorageSuite) PutFile(c *C, path string, data []byte) {
func (s *PublishedStorageSuite) TestPutFile(c *C) {
dir := c.MkDir()
err := ioutil.WriteFile(filepath.Join(dir, "a"), []byte("welcome to s3!"), 0644)
err := os.WriteFile(filepath.Join(dir, "a"), []byte("welcome to s3!"), 0644)
c.Assert(err, IsNil)
err = s.storage.PutFile("a/b.txt", filepath.Join(dir, "a"))
@@ -116,7 +116,7 @@ func (s *PublishedStorageSuite) TestPutFilePlusWorkaround(c *C) {
s.storage.plusWorkaround = true
dir := c.MkDir()
err := ioutil.WriteFile(filepath.Join(dir, "a"), []byte("welcome to s3!"), 0644)
err := os.WriteFile(filepath.Join(dir, "a"), []byte("welcome to s3!"), 0644)
c.Assert(err, IsNil)
err = s.storage.PutFile("a/b+c.txt", filepath.Join(dir, "a"))
@@ -260,18 +260,18 @@ func (s *PublishedStorageSuite) TestLinkFromPool(c *C) {
cs := files.NewMockChecksumStorage()
tmpFile1 := filepath.Join(c.MkDir(), "mars-invaders_1.03.deb")
err := ioutil.WriteFile(tmpFile1, []byte("Contents"), 0644)
err := os.WriteFile(tmpFile1, []byte("Contents"), 0644)
c.Assert(err, IsNil)
cksum1 := utils.ChecksumInfo{MD5: "c1df1da7a1ce305a3b60af9d5733ac1d"}
tmpFile2 := filepath.Join(c.MkDir(), "mars-invaders_1.03.deb")
err = ioutil.WriteFile(tmpFile2, []byte("Spam"), 0644)
err = os.WriteFile(tmpFile2, []byte("Spam"), 0644)
c.Assert(err, IsNil)
cksum2 := utils.ChecksumInfo{MD5: "e9dfd31cc505d51fc26975250750deab"}
tmpFile3 := filepath.Join(c.MkDir(), "netboot/boot.img.gz")
os.MkdirAll(filepath.Dir(tmpFile3), 0777)
err = ioutil.WriteFile(tmpFile3, []byte("Contents"), 0644)
_ = os.MkdirAll(filepath.Dir(tmpFile3), 0777)
err = os.WriteFile(tmpFile3, []byte("Contents"), 0644)
c.Assert(err, IsNil)
cksum3 := utils.ChecksumInfo{MD5: "c1df1da7a1ce305a3b60af9d5733ac1d"}
@@ -332,7 +332,7 @@ func (s *PublishedStorageSuite) TestLinkFromPoolCache(c *C) {
cs := files.NewMockChecksumStorage()
tmpFile1 := filepath.Join(c.MkDir(), "mars-invaders_1.03.deb")
err := ioutil.WriteFile(tmpFile1, []byte("Contents"), 0644)
err := os.WriteFile(tmpFile1, []byte("Contents"), 0644)
c.Assert(err, IsNil)
cksum1 := utils.ChecksumInfo{MD5: "c1df1da7a1ce305a3b60af9d5733ac1d"}

View File

@@ -8,7 +8,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
@@ -113,15 +112,15 @@ func NewServer(config *Config) (*Server, error) {
buckets: make(map[string]*bucket),
config: config,
}
go http.Serve(l, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
go func() { _ = http.Serve(l, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
srv.serveHTTP(w, req)
}))
})) }()
return srv, nil
}
// Quit closes down the server.
func (srv *Server) Quit() {
srv.listener.Close()
_ = srv.listener.Close()
}
// URL returns a URL for the server.
@@ -140,7 +139,7 @@ func fatalError(code int, codeStr string, errf string, a ...interface{}) {
// serveHTTP serves the S3 protocol.
func (srv *Server) serveHTTP(w http.ResponseWriter, req *http.Request) {
// ignore error from ParseForm as it's usually spurious.
req.ParseForm()
_ = req.ParseForm()
srv.mu.Lock()
defer srv.mu.Unlock()
@@ -384,7 +383,7 @@ func (r bucketResource) get(a *action) interface{} {
if s := a.req.Form.Get("max-keys"); s != "" {
i, err := strconv.Atoi(s)
if err != nil || i < 0 {
fatalError(400, "invalid value for max-keys: %q", s)
fatalError(400, "invalid value for max-keys", "%q", s)
}
maxKeys = i
}
@@ -541,7 +540,7 @@ func validBucketName(name string) bool {
return false
}
r := name[0]
if !(r >= '0' && r <= '9' || r >= 'a' && r <= 'z') {
if r < '0' || (r > '9' && r < 'a') || r > 'z' {
return false
}
for _, r := range name {
@@ -654,7 +653,7 @@ func (objr objectResource) put(a *action) interface{} {
}
sum := md5.New()
// TODO avoid holding lock while reading data.
data, err := ioutil.ReadAll(io.TeeReader(a.req.Body, sum))
data, err := io.ReadAll(io.TeeReader(a.req.Body, sum))
if err != nil {
fatalError(400, "TODO", "read error")
}
@@ -699,14 +698,14 @@ type CreateBucketConfiguration struct {
func locationConstraint(a *action) string {
var body bytes.Buffer
if _, err := io.Copy(&body, a.req.Body); err != nil {
fatalError(400, "InvalidRequest", err.Error())
fatalError(400, "InvalidRequest", "%v", err.Error())
}
if body.Len() == 0 {
return ""
}
var loc CreateBucketConfiguration
if err := xml.NewDecoder(&body).Decode(&loc); err != nil {
fatalError(400, "InvalidRequest", err.Error())
fatalError(400, "InvalidRequest", "%v", err.Error())
}
return loc.LocationConstraint
}