mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-06 05:30:57 +00:00
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:
+6
-2
@@ -17,7 +17,9 @@ func MD5ChecksumForFile(path string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
hash := md5.New()
|
||||
_, err = io.Copy(hash, file)
|
||||
@@ -62,7 +64,9 @@ func ChecksumsForFile(path string) (ChecksumInfo, error) {
|
||||
if err != nil {
|
||||
return ChecksumInfo{}, err
|
||||
}
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
return ChecksumsForReader(file)
|
||||
}
|
||||
|
||||
@@ -14,11 +14,11 @@ var _ = Suite(&ChecksumSuite{})
|
||||
|
||||
func (s *ChecksumSuite) SetUpTest(c *C) {
|
||||
s.tempfile, _ = os.CreateTemp(c.MkDir(), "aptly-test")
|
||||
s.tempfile.WriteString(testString)
|
||||
_, _ = s.tempfile.WriteString(testString)
|
||||
}
|
||||
|
||||
func (s *ChecksumSuite) TearDownTest(c *C) {
|
||||
s.tempfile.Close()
|
||||
_ = s.tempfile.Close()
|
||||
}
|
||||
|
||||
func (s *ChecksumSuite) TestChecksumsForFile(c *C) {
|
||||
|
||||
+7
-3
@@ -18,12 +18,16 @@ func CompressFile(source *os.File, onlyGzip bool) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer gzFile.Close()
|
||||
defer func() {
|
||||
_ = gzFile.Close()
|
||||
}()
|
||||
|
||||
gzWriter := pgzip.NewWriter(gzFile)
|
||||
defer gzWriter.Close()
|
||||
defer func() {
|
||||
_ = gzWriter.Close()
|
||||
}()
|
||||
|
||||
source.Seek(0, 0)
|
||||
_, _ = source.Seek(0, 0)
|
||||
_, err = io.Copy(gzWriter, source)
|
||||
if err != nil || onlyGzip {
|
||||
return err
|
||||
|
||||
@@ -3,7 +3,7 @@ package utils
|
||||
import (
|
||||
"compress/bzip2"
|
||||
"compress/gzip"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
. "gopkg.in/check.v1"
|
||||
@@ -19,11 +19,11 @@ const testString = "Quick brown fox jumps over black dog and runs away... Really
|
||||
|
||||
func (s *CompressSuite) SetUpTest(c *C) {
|
||||
s.tempfile, _ = os.CreateTemp(c.MkDir(), "aptly-test")
|
||||
s.tempfile.WriteString(testString)
|
||||
_, _ = s.tempfile.WriteString(testString)
|
||||
}
|
||||
|
||||
func (s *CompressSuite) TearDownTest(c *C) {
|
||||
s.tempfile.Close()
|
||||
_ = s.tempfile.Close()
|
||||
}
|
||||
|
||||
func (s *CompressSuite) TestCompress(c *C) {
|
||||
@@ -36,11 +36,11 @@ func (s *CompressSuite) TestCompress(c *C) {
|
||||
gzReader, err := gzip.NewReader(file)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
buf, err := ioutil.ReadAll(gzReader)
|
||||
buf, err := io.ReadAll(gzReader)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
gzReader.Close()
|
||||
file.Close()
|
||||
_ = gzReader.Close()
|
||||
_ = file.Close()
|
||||
|
||||
c.Check(string(buf), Equals, testString)
|
||||
|
||||
@@ -52,7 +52,7 @@ func (s *CompressSuite) TestCompress(c *C) {
|
||||
_, err = bzReader.Read(buf)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
file.Close()
|
||||
_ = file.Close()
|
||||
|
||||
c.Check(string(buf), Equals, testString)
|
||||
}
|
||||
|
||||
+16
-8
@@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/DisposaBoy/JsonConfigReader"
|
||||
"gopkg.in/yaml.v3"
|
||||
yaml "gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// ConfigStructure is structure of main configuration
|
||||
@@ -65,10 +65,10 @@ type ConfigStructure struct { // nolint: maligned
|
||||
PackagePoolStorage PackagePoolStorage `json:"packagePoolStorage" yaml:"packagepool_storage"`
|
||||
}
|
||||
|
||||
// DBConfig
|
||||
// DBConfig structure
|
||||
type DBConfig struct {
|
||||
Type string `json:"type" yaml:"type"`
|
||||
DbPath string `json:"dbPath" yaml:"db_path"`
|
||||
DBPath string `json:"dbPath" yaml:"db_path"`
|
||||
URL string `json:"url" yaml:"url"`
|
||||
}
|
||||
|
||||
@@ -251,11 +251,13 @@ func LoadConfig(filename string, config *ConfigStructure) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
defer func() {
|
||||
_ = f.Close()
|
||||
}()
|
||||
|
||||
decJSON := json.NewDecoder(JsonConfigReader.New(f))
|
||||
if err = decJSON.Decode(&config); err != nil {
|
||||
f.Seek(0, 0)
|
||||
_, _ = f.Seek(0, 0)
|
||||
decYAML := yaml.NewDecoder(f)
|
||||
if err2 := decYAML.Decode(&config); err2 != nil {
|
||||
err = fmt.Errorf("invalid yaml (%s) or json (%s)", err2, err)
|
||||
@@ -272,7 +274,9 @@ func SaveConfig(filename string, config *ConfigStructure) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
defer func() {
|
||||
_ = f.Close()
|
||||
}()
|
||||
|
||||
encoded, err := json.MarshalIndent(&config, "", " ")
|
||||
if err != nil {
|
||||
@@ -289,7 +293,9 @@ func SaveConfigRaw(filename string, conf []byte) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
defer func() {
|
||||
_ = f.Close()
|
||||
}()
|
||||
|
||||
_, err = f.Write(conf)
|
||||
return err
|
||||
@@ -301,7 +307,9 @@ func SaveConfigYAML(filename string, config *ConfigStructure) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
defer func() {
|
||||
_ = f.Close()
|
||||
}()
|
||||
|
||||
yamlData, err := yaml.Marshal(&config)
|
||||
if err != nil {
|
||||
|
||||
+21
-15
@@ -16,8 +16,8 @@ var _ = Suite(&ConfigSuite{})
|
||||
func (s *ConfigSuite) TestLoadConfig(c *C) {
|
||||
configname := filepath.Join(c.MkDir(), "aptly.json1")
|
||||
f, _ := os.Create(configname)
|
||||
f.WriteString(configFile)
|
||||
f.Close()
|
||||
_, _ = f.WriteString(configFile)
|
||||
_ = f.Close()
|
||||
|
||||
// start with empty config
|
||||
s.config = ConfigStructure{}
|
||||
@@ -62,11 +62,13 @@ func (s *ConfigSuite) TestSaveConfig(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
f, _ := os.Open(configname)
|
||||
defer f.Close()
|
||||
defer func() {
|
||||
_ = f.Close()
|
||||
}()
|
||||
|
||||
st, _ := f.Stat()
|
||||
buf := make([]byte, st.Size())
|
||||
f.Read(buf)
|
||||
_, _ = f.Read(buf)
|
||||
|
||||
c.Check(string(buf), Equals, ""+
|
||||
"{\n" +
|
||||
@@ -162,8 +164,8 @@ func (s *ConfigSuite) TestSaveConfig(c *C) {
|
||||
func (s *ConfigSuite) TestLoadYAMLConfig(c *C) {
|
||||
configname := filepath.Join(c.MkDir(), "aptly.yaml1")
|
||||
f, _ := os.Create(configname)
|
||||
f.WriteString(configFileYAML)
|
||||
f.Close()
|
||||
_, _ = f.WriteString(configFileYAML)
|
||||
_ = f.Close()
|
||||
|
||||
// start with empty config
|
||||
s.config = ConfigStructure{}
|
||||
@@ -178,8 +180,8 @@ func (s *ConfigSuite) TestLoadYAMLConfig(c *C) {
|
||||
func (s *ConfigSuite) TestLoadYAMLErrorConfig(c *C) {
|
||||
configname := filepath.Join(c.MkDir(), "aptly.yaml2")
|
||||
f, _ := os.Create(configname)
|
||||
f.WriteString(configFileYAMLError)
|
||||
f.Close()
|
||||
_, _ = f.WriteString(configFileYAMLError)
|
||||
_ = f.Close()
|
||||
|
||||
// start with empty config
|
||||
s.config = ConfigStructure{}
|
||||
@@ -191,8 +193,8 @@ func (s *ConfigSuite) TestLoadYAMLErrorConfig(c *C) {
|
||||
func (s *ConfigSuite) TestSaveYAMLConfig(c *C) {
|
||||
configname := filepath.Join(c.MkDir(), "aptly.yaml3")
|
||||
f, _ := os.Create(configname)
|
||||
f.WriteString(configFileYAML)
|
||||
f.Close()
|
||||
_, _ = f.WriteString(configFileYAML)
|
||||
_ = f.Close()
|
||||
|
||||
// start with empty config
|
||||
s.config = ConfigStructure{}
|
||||
@@ -204,11 +206,13 @@ func (s *ConfigSuite) TestSaveYAMLConfig(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
f, _ = os.Open(configname)
|
||||
defer f.Close()
|
||||
defer func() {
|
||||
_ = f.Close()
|
||||
}()
|
||||
|
||||
st, _ := f.Stat()
|
||||
buf := make([]byte, st.Size())
|
||||
f.Read(buf)
|
||||
_, _ = f.Read(buf)
|
||||
|
||||
c.Check(string(buf), Equals, configFileYAML)
|
||||
}
|
||||
@@ -225,11 +229,13 @@ func (s *ConfigSuite) TestSaveYAML2Config(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
f, _ := os.Open(configname)
|
||||
defer f.Close()
|
||||
defer func() {
|
||||
_ = f.Close()
|
||||
}()
|
||||
|
||||
st, _ := f.Stat()
|
||||
buf := make([]byte, st.Size())
|
||||
f.Read(buf)
|
||||
_, _ = f.Read(buf)
|
||||
|
||||
c.Check(string(buf), Equals, "" +
|
||||
"root_dir: \"\"\n" +
|
||||
@@ -275,7 +281,7 @@ func (s *ConfigSuite) TestSaveYAML2Config(c *C) {
|
||||
func (s *ConfigSuite) TestLoadEmptyConfig(c *C) {
|
||||
configname := filepath.Join(c.MkDir(), "aptly.yaml5")
|
||||
f, _ := os.Create(configname)
|
||||
f.Close()
|
||||
_ = f.Close()
|
||||
|
||||
// start with empty config
|
||||
s.config = ConfigStructure{}
|
||||
|
||||
+4
-2
@@ -11,7 +11,9 @@ func CopyFile(src, dst string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer sf.Close()
|
||||
defer func() {
|
||||
_ = sf.Close()
|
||||
}()
|
||||
|
||||
df, err := os.Create(dst)
|
||||
if err != nil {
|
||||
@@ -20,7 +22,7 @@ func CopyFile(src, dst string) error {
|
||||
|
||||
_, err = io.Copy(df, sf)
|
||||
if err != nil {
|
||||
df.Close()
|
||||
_ = df.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ func DirIsAccessible(filename string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Remove leading '/', remove '..', '$' and '`'
|
||||
// SanitizePath removes leading '/', remove '..', '$' and '`'
|
||||
func SanitizePath(path string) (result string) {
|
||||
result = strings.Replace(path, "..", "", -1)
|
||||
result = strings.Replace(result, "$", "", -1)
|
||||
|
||||
Reference in New Issue
Block a user