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

@@ -89,7 +89,9 @@ func NewPublishedStorage(username string, password string, authURL string, tenan
var bulkDelete bool
resp, err := http.Get(filepath.Join(ct.StorageUrl, "..", "..") + "/info")
if err == nil {
defer resp.Body.Close()
defer func() {
_ = resp.Body.Close()
}()
decoder := json.NewDecoder(resp.Body)
var infos swiftInfo
if decoder.Decode(&infos) == nil {
@@ -107,7 +109,7 @@ func NewPublishedStorage(username string, password string, authURL string, tenan
return result, nil
}
// String
// String represents the Storage as string
func (storage *PublishedStorage) String() string {
return fmt.Sprintf("Swift: %s/%s/%s", storage.conn.StorageUrl, storage.container, storage.prefix)
}
@@ -128,7 +130,9 @@ func (storage *PublishedStorage) PutFile(path string, sourceFilename string) err
if err != nil {
return err
}
defer source.Close()
defer func() {
_ = source.Close()
}()
err = storage.putFile(path, source)
if err != nil {
@@ -225,7 +229,9 @@ func (storage *PublishedStorage) LinkFromPool(publishedPrefix, publishedRelPath,
if err != nil {
return err
}
defer source.Close()
defer func() {
_ = source.Close()
}()
err = storage.putFile(relPath, source)
if err != nil {

View File

@@ -2,7 +2,6 @@ package swift
import (
"fmt"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
@@ -39,7 +38,7 @@ func (s *PublishedStorageSuite) SetUpTest(c *C) {
s.prefixedStorage, err = NewPublishedStorage("swifttest", "swifttest", s.AuthURL, "", "", "", "", "", "", "test", "lala")
c.Assert(err, IsNil)
s.storage.conn.ContainerCreate("test", nil)
_ = s.storage.conn.ContainerCreate("test", nil)
}
func (s *PublishedStorageSuite) TearDownTest(c *C) {
@@ -54,7 +53,7 @@ func (s *PublishedStorageSuite) TestNewPublishedStorage(c *C) {
func (s *PublishedStorageSuite) TestPutFile(c *C) {
dir := c.MkDir()
err := ioutil.WriteFile(filepath.Join(dir, "a"), []byte("welcome to swift!"), 0644)
err := os.WriteFile(filepath.Join(dir, "a"), []byte("welcome to swift!"), 0644)
c.Assert(err, IsNil)
err = s.storage.PutFile("a/b.txt", filepath.Join(dir, "a"))
@@ -74,7 +73,7 @@ func (s *PublishedStorageSuite) TestPutFile(c *C) {
func (s *PublishedStorageSuite) TestFilelist(c *C) {
dir := c.MkDir()
err := ioutil.WriteFile(filepath.Join(dir, "a"), []byte("welcome to swift!"), 0644)
err := os.WriteFile(filepath.Join(dir, "a"), []byte("welcome to swift!"), 0644)
c.Assert(err, IsNil)
paths := []string{"a", "b", "c", "testa", "test/a", "test/b", "lala/a", "lala/b", "lala/c"}
@@ -102,7 +101,7 @@ func (s *PublishedStorageSuite) TestFilelist(c *C) {
func (s *PublishedStorageSuite) TestRemove(c *C) {
dir := c.MkDir()
err := ioutil.WriteFile(filepath.Join(dir, "a"), []byte("welcome to swift!"), 0644)
err := os.WriteFile(filepath.Join(dir, "a"), []byte("welcome to swift!"), 0644)
c.Assert(err, IsNil)
err = s.storage.PutFile("a/b.txt", filepath.Join(dir, "a"))
@@ -119,7 +118,7 @@ func (s *PublishedStorageSuite) TestRemoveDirs(c *C) {
c.Skip("bulk-delete not available in s3test")
dir := c.MkDir()
err := ioutil.WriteFile(filepath.Join(dir, "a"), []byte("welcome to swift!"), 0644)
err := os.WriteFile(filepath.Join(dir, "a"), []byte("welcome to swift!"), 0644)
c.Assert(err, IsNil)
paths := []string{"a", "b", "c", "testa", "test/a", "test/b", "lala/a", "lala/b", "lala/c"}
@@ -146,18 +145,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"}
@@ -211,7 +210,7 @@ func (s *PublishedStorageSuite) TestLinkFromPool(c *C) {
func (s *PublishedStorageSuite) TestSymLink(c *C) {
dir := c.MkDir()
err := ioutil.WriteFile(filepath.Join(dir, "a"), []byte("welcome to swift!"), 0644)
err := os.WriteFile(filepath.Join(dir, "a"), []byte("welcome to swift!"), 0644)
c.Assert(err, IsNil)
err = s.storage.PutFile("a/b.txt", filepath.Join(dir, "a"))
@@ -230,7 +229,7 @@ func (s *PublishedStorageSuite) TestSymLink(c *C) {
func (s *PublishedStorageSuite) TestFileExists(c *C) {
dir := c.MkDir()
err := ioutil.WriteFile(filepath.Join(dir, "a"), []byte("welcome to swift!"), 0644)
err := os.WriteFile(filepath.Join(dir, "a"), []byte("welcome to swift!"), 0644)
c.Assert(err, IsNil)
err = s.storage.PutFile("a/b.txt", filepath.Join(dir, "a"))