More Go linters enabled, issues fixed

Ref: #528

Enables "staticcheck", "varcheck", "structcheck", "aligncheck"
This commit is contained in:
Andrey Smirnov
2017-05-03 00:56:18 +03:00
parent 7a7c9cd26c
commit 51213899b7
14 changed files with 50 additions and 49 deletions

View File

@@ -28,7 +28,6 @@ type printTask struct {
// Progress is a progress displaying subroutine, it allows to show download and other operations progress // Progress is a progress displaying subroutine, it allows to show download and other operations progress
// mixed with progress bar // mixed with progress bar
type Progress struct { type Progress struct {
stop chan bool
stopped chan bool stopped chan bool
queue chan printTask queue chan printTask
bar *pb.ProgressBar bar *pb.ProgressBar

View File

@@ -34,8 +34,6 @@ const (
type PackageList struct { type PackageList struct {
// Straight list of packages as map // Straight list of packages as map
packages map[string]*Package packages map[string]*Package
// Has index been prepared?
indexed bool
// Indexed list of packages, sorted by name internally // Indexed list of packages, sorted by name internally
packagesIndex []*Package packagesIndex []*Package
// Map of packages for each virtual package (provides) // Map of packages for each virtual package (provides)
@@ -44,6 +42,8 @@ type PackageList struct {
keyFunc func(p *Package) string keyFunc func(p *Package) string
// Allow duplicates? // Allow duplicates?
duplicatesAllowed bool duplicatesAllowed bool
// Has index been prepared?
indexed bool
} }
// PackageConflictError means that package can't be added to the list due to error // PackageConflictError means that package can't be added to the list due to error

View File

@@ -98,14 +98,14 @@ func (s *LocalRepoCollectionSuite) TearDownTest(c *C) {
} }
func (s *LocalRepoCollectionSuite) TestAddByName(c *C) { func (s *LocalRepoCollectionSuite) TestAddByName(c *C) {
r, err := s.collection.ByName("local1") _, err := s.collection.ByName("local1")
c.Assert(err, ErrorMatches, "*.not found") c.Assert(err, ErrorMatches, "*.not found")
repo := NewLocalRepo("local1", "Comment 1") repo := NewLocalRepo("local1", "Comment 1")
c.Assert(s.collection.Add(repo), IsNil) c.Assert(s.collection.Add(repo), IsNil)
c.Assert(s.collection.Add(repo), ErrorMatches, ".*already exists") c.Assert(s.collection.Add(repo), ErrorMatches, ".*already exists")
r, err = s.collection.ByName("local1") r, err := s.collection.ByName("local1")
c.Assert(err, IsNil) c.Assert(err, IsNil)
c.Assert(r.String(), Equals, repo.String()) c.Assert(r.String(), Equals, repo.String())
@@ -116,13 +116,13 @@ func (s *LocalRepoCollectionSuite) TestAddByName(c *C) {
} }
func (s *LocalRepoCollectionSuite) TestByUUID(c *C) { func (s *LocalRepoCollectionSuite) TestByUUID(c *C) {
r, err := s.collection.ByUUID("some-uuid") _, err := s.collection.ByUUID("some-uuid")
c.Assert(err, ErrorMatches, "*.not found") c.Assert(err, ErrorMatches, "*.not found")
repo := NewLocalRepo("local1", "Comment 1") repo := NewLocalRepo("local1", "Comment 1")
c.Assert(s.collection.Add(repo), IsNil) c.Assert(s.collection.Add(repo), IsNil)
r, err = s.collection.ByUUID(repo.UUID) r, err := s.collection.ByUUID(repo.UUID)
c.Assert(err, IsNil) c.Assert(err, IsNil)
c.Assert(r.String(), Equals, repo.String()) c.Assert(r.String(), Equals, repo.String())
} }

View File

@@ -24,12 +24,12 @@ type Package struct {
Source string Source string
// List of virtual packages this package provides // List of virtual packages this package provides
Provides []string Provides []string
// Hash of files section
FilesHash uint64
// Is this source package // Is this source package
IsSource bool IsSource bool
// Is this udeb package // Is this udeb package
IsUdeb bool IsUdeb bool
// Hash of files section
FilesHash uint64
// Is this >= 0.6 package? // Is this >= 0.6 package?
V06Plus bool V06Plus bool
// Offload fields // Offload fields

View File

@@ -45,8 +45,6 @@ type PublishedRepo struct {
Architectures []string Architectures []string
// SourceKind is "local"/"repo" // SourceKind is "local"/"repo"
SourceKind string SourceKind string
// Skip contents generation
SkipContents bool
// Map of sources by each component: component name -> source UUID // Map of sources by each component: component name -> source UUID
Sources map[string]string Sources map[string]string
@@ -55,10 +53,12 @@ type PublishedRepo struct {
Component string Component string
// SourceUUID is UUID of either snapshot or local repo // SourceUUID is UUID of either snapshot or local repo
SourceUUID string `codec:"SnapshotUUID"` SourceUUID string `codec:"SnapshotUUID"`
// Map of component to source items // Map of component to source items
sourceItems map[string]repoSourceItem sourceItems map[string]repoSourceItem
// Skip contents generation
SkipContents bool
// True if repo is being re-published // True if repo is being re-published
rePublishing bool rePublishing bool
} }
@@ -166,23 +166,19 @@ func NewPublishedRepo(storage, prefix, distribution string, architectures []stri
component string component string
snapshot *Snapshot snapshot *Snapshot
localRepo *LocalRepo localRepo *LocalRepo
ok bool
) )
// get first source // get first source
source = sources[0] source = sources[0]
// figure out source kind // figure out source kind
snapshot, ok = source.(*Snapshot) switch source.(type) {
if ok { case *Snapshot:
result.SourceKind = "snapshot" result.SourceKind = "snapshot"
} else { case *LocalRepo:
localRepo, ok = source.(*LocalRepo) result.SourceKind = "local"
if ok { default:
result.SourceKind = "local" panic("unknown source kind")
} else {
panic("unknown source kind")
}
} }
for i := range sources { for i := range sources {

View File

@@ -277,7 +277,7 @@ func (s *PublishedRepoSuite) TestDistributionComponentGuessing(c *C) {
c.Check(repo.Distribution, Equals, "squeeze") c.Check(repo.Distribution, Equals, "squeeze")
c.Check(repo.Components(), DeepEquals, []string{"main"}) c.Check(repo.Components(), DeepEquals, []string{"main"})
repo, err = NewPublishedRepo("", "ppa", "", nil, []string{"main"}, []interface{}{s.localRepo}, s.factory) _, err = NewPublishedRepo("", "ppa", "", nil, []string{"main"}, []interface{}{s.localRepo}, s.factory)
c.Check(err, ErrorMatches, "unable to guess distribution name, please specify explicitly") c.Check(err, ErrorMatches, "unable to guess distribution name, please specify explicitly")
s.localRepo.DefaultDistribution = "precise" s.localRepo.DefaultDistribution = "precise"
@@ -301,7 +301,7 @@ func (s *PublishedRepoSuite) TestDistributionComponentGuessing(c *C) {
c.Check(repo.Distribution, Equals, "squeeze") c.Check(repo.Distribution, Equals, "squeeze")
c.Check(repo.Components(), DeepEquals, []string{"contrib", "main"}) c.Check(repo.Components(), DeepEquals, []string{"contrib", "main"})
repo, err = NewPublishedRepo("", "ppa", "", nil, []string{"", ""}, []interface{}{s.snapshot, s.snapshot2}, s.factory) _, err = NewPublishedRepo("", "ppa", "", nil, []string{"", ""}, []interface{}{s.snapshot, s.snapshot2}, s.factory)
c.Check(err, ErrorMatches, "duplicate component name: main") c.Check(err, ErrorMatches, "duplicate component name: main")
} }
@@ -477,7 +477,7 @@ func (s *PublishedRepoCollectionSuite) TearDownTest(c *C) {
} }
func (s *PublishedRepoCollectionSuite) TestAddByStoragePrefixDistribution(c *C) { func (s *PublishedRepoCollectionSuite) TestAddByStoragePrefixDistribution(c *C) {
r, err := s.collection.ByStoragePrefixDistribution("", "ppa", "anaconda") _, err := s.collection.ByStoragePrefixDistribution("", "ppa", "anaconda")
c.Assert(err, ErrorMatches, "*.not found") c.Assert(err, ErrorMatches, "*.not found")
c.Assert(s.collection.Add(s.repo1), IsNil) c.Assert(s.collection.Add(s.repo1), IsNil)
@@ -489,7 +489,7 @@ func (s *PublishedRepoCollectionSuite) TestAddByStoragePrefixDistribution(c *C)
c.Assert(s.collection.Add(s.repo4), IsNil) c.Assert(s.collection.Add(s.repo4), IsNil)
c.Assert(s.collection.Add(s.repo5), IsNil) c.Assert(s.collection.Add(s.repo5), IsNil)
r, err = s.collection.ByStoragePrefixDistribution("", "ppa", "anaconda") r, err := s.collection.ByStoragePrefixDistribution("", "ppa", "anaconda")
c.Assert(err, IsNil) c.Assert(err, IsNil)
err = s.collection.LoadComplete(r, s.factory) err = s.collection.LoadComplete(r, s.factory)
@@ -510,12 +510,12 @@ func (s *PublishedRepoCollectionSuite) TestAddByStoragePrefixDistribution(c *C)
} }
func (s *PublishedRepoCollectionSuite) TestByUUID(c *C) { func (s *PublishedRepoCollectionSuite) TestByUUID(c *C) {
r, err := s.collection.ByUUID(s.repo1.UUID) _, err := s.collection.ByUUID(s.repo1.UUID)
c.Assert(err, ErrorMatches, "*.not found") c.Assert(err, ErrorMatches, "*.not found")
c.Assert(s.collection.Add(s.repo1), IsNil) c.Assert(s.collection.Add(s.repo1), IsNil)
r, err = s.collection.ByUUID(s.repo1.UUID) r, err := s.collection.ByUUID(s.repo1.UUID)
c.Assert(err, IsNil) c.Assert(err, IsNil)
err = s.collection.LoadComplete(r, s.factory) err = s.collection.LoadComplete(r, s.factory)

View File

@@ -45,10 +45,6 @@ type RemoteRepo struct {
Components []string Components []string
// List of architectures to fetch, if empty, then fetch all architectures // List of architectures to fetch, if empty, then fetch all architectures
Architectures []string Architectures []string
// Should we download sources?
DownloadSources bool
// Should we download .udebs?
DownloadUdebs bool
// Meta-information about repository // Meta-information about repository
Meta Stanza Meta Stanza
// Last update date // Last update date
@@ -57,20 +53,22 @@ type RemoteRepo struct {
ReleaseFiles map[string]utils.ChecksumInfo ReleaseFiles map[string]utils.ChecksumInfo
// Filter for packages // Filter for packages
Filter string Filter string
// Status marks state of repository (being updated, no action)
Status int
// WorkerPID is PID of the process modifying the mirror (if any)
WorkerPID int
// FilterWithDeps to include dependencies from filter query // FilterWithDeps to include dependencies from filter query
FilterWithDeps bool FilterWithDeps bool
// SkipComponentCheck skips component list verification // SkipComponentCheck skips component list verification
SkipComponentCheck bool SkipComponentCheck bool
// SkipArchitectureCheck skips architecture list verification // SkipArchitectureCheck skips architecture list verification
SkipArchitectureCheck bool SkipArchitectureCheck bool
// Status marks state of repository (being updated, no action) // Should we download sources?
Status int DownloadSources bool
// WorkerPID is PID of the process modifying the mirror (if any) // Should we download .udebs?
WorkerPID int DownloadUdebs bool
// "Snapshot" of current list of packages // "Snapshot" of current list of packages
packageRefs *PackageRefList packageRefs *PackageRefList
// Temporary list of package refs
tempPackageRefs *PackageRefList
// Parsed archived root // Parsed archived root
archiveRootURL *url.URL archiveRootURL *url.URL
// Current list of packages (filled while updating mirror) // Current list of packages (filled while updating mirror)

View File

@@ -618,14 +618,14 @@ func (s *RemoteRepoCollectionSuite) TearDownTest(c *C) {
} }
func (s *RemoteRepoCollectionSuite) TestAddByName(c *C) { func (s *RemoteRepoCollectionSuite) TestAddByName(c *C) {
r, err := s.collection.ByName("yandex") _, err := s.collection.ByName("yandex")
c.Assert(err, ErrorMatches, "*.not found") c.Assert(err, ErrorMatches, "*.not found")
repo, _ := NewRemoteRepo("yandex", "http://mirror.yandex.ru/debian/", "squeeze", []string{"main"}, []string{}, false, false) repo, _ := NewRemoteRepo("yandex", "http://mirror.yandex.ru/debian/", "squeeze", []string{"main"}, []string{}, false, false)
c.Assert(s.collection.Add(repo), IsNil) c.Assert(s.collection.Add(repo), IsNil)
c.Assert(s.collection.Add(repo), ErrorMatches, ".*already exists") c.Assert(s.collection.Add(repo), ErrorMatches, ".*already exists")
r, err = s.collection.ByName("yandex") r, err := s.collection.ByName("yandex")
c.Assert(err, IsNil) c.Assert(err, IsNil)
c.Assert(r.String(), Equals, repo.String()) c.Assert(r.String(), Equals, repo.String())
@@ -636,13 +636,13 @@ func (s *RemoteRepoCollectionSuite) TestAddByName(c *C) {
} }
func (s *RemoteRepoCollectionSuite) TestByUUID(c *C) { func (s *RemoteRepoCollectionSuite) TestByUUID(c *C) {
r, err := s.collection.ByUUID("some-uuid") _, err := s.collection.ByUUID("some-uuid")
c.Assert(err, ErrorMatches, "*.not found") c.Assert(err, ErrorMatches, "*.not found")
repo, _ := NewRemoteRepo("yandex", "http://mirror.yandex.ru/debian/", "squeeze", []string{"main"}, []string{}, false, false) repo, _ := NewRemoteRepo("yandex", "http://mirror.yandex.ru/debian/", "squeeze", []string{"main"}, []string{}, false, false)
c.Assert(s.collection.Add(repo), IsNil) c.Assert(s.collection.Add(repo), IsNil)
r, err = s.collection.ByUUID(repo.UUID) r, err := s.collection.ByUUID(repo.UUID)
c.Assert(err, IsNil) c.Assert(err, IsNil)
c.Assert(r.String(), Equals, repo.String()) c.Assert(r.String(), Equals, repo.String())
} }

View File

@@ -138,7 +138,7 @@ func (s *SnapshotCollectionSuite) TearDownTest(c *C) {
} }
func (s *SnapshotCollectionSuite) TestAddByNameByUUID(c *C) { func (s *SnapshotCollectionSuite) TestAddByNameByUUID(c *C) {
snapshot, err := s.collection.ByName("snap1") _, err := s.collection.ByName("snap1")
c.Assert(err, ErrorMatches, "*.not found") c.Assert(err, ErrorMatches, "*.not found")
c.Assert(s.collection.Add(s.snapshot1), IsNil) c.Assert(s.collection.Add(s.snapshot1), IsNil)
@@ -146,7 +146,7 @@ func (s *SnapshotCollectionSuite) TestAddByNameByUUID(c *C) {
c.Assert(s.collection.Add(s.snapshot2), IsNil) c.Assert(s.collection.Add(s.snapshot2), IsNil)
snapshot, err = s.collection.ByName("snap1") snapshot, err := s.collection.ByName("snap1")
c.Assert(err, IsNil) c.Assert(err, IsNil)
c.Assert(snapshot.String(), Equals, s.snapshot1.String()) c.Assert(snapshot.String(), Equals, s.snapshot1.String())

View File

@@ -84,7 +84,7 @@ func (s *CompressionSuite) TestDownloadTryCompression(c *C) {
d = NewFakeDownloader() d = NewFakeDownloader()
d.ExpectError("http://example.com/file.bz2", &Error{Code: 404}) d.ExpectError("http://example.com/file.bz2", &Error{Code: 404})
d.ExpectResponse("http://example.com/file.gz", "x") d.ExpectResponse("http://example.com/file.gz", "x")
_, file, err = DownloadTryCompression(d, "http://example.com/file", nil, true, 1) _, _, err = DownloadTryCompression(d, "http://example.com/file", nil, true, 1)
c.Assert(err, ErrorMatches, "unexpected EOF") c.Assert(err, ErrorMatches, "unexpected EOF")
c.Assert(d.Empty(), Equals, true) c.Assert(d.Empty(), Equals, true)
} }

View File

@@ -39,9 +39,10 @@ func (s *TempSuite) TestDownloadTemp(c *C) {
func (s *TempSuite) TestDownloadTempWithChecksum(c *C) { func (s *TempSuite) TestDownloadTempWithChecksum(c *C) {
f, err := DownloadTempWithChecksum(s.d, s.url+"/test", &utils.ChecksumInfo{Size: 12, MD5: "a1acb0fe91c7db45ec4d775192ec5738", f, err := DownloadTempWithChecksum(s.d, s.url+"/test", &utils.ChecksumInfo{Size: 12, MD5: "a1acb0fe91c7db45ec4d775192ec5738",
SHA1: "921893bae6ad6fd818401875d6779254ef0ff0ec", SHA256: "b3c92ee1246176ed35f6e8463cd49074f29442f5bbffc3f8591cde1dcc849dac"}, false, 1) SHA1: "921893bae6ad6fd818401875d6779254ef0ff0ec", SHA256: "b3c92ee1246176ed35f6e8463cd49074f29442f5bbffc3f8591cde1dcc849dac"}, false, 1)
defer f.Close()
c.Assert(err, IsNil) c.Assert(err, IsNil)
c.Assert(f.Close(), IsNil)
_, err = DownloadTempWithChecksum(s.d, s.url+"/test", &utils.ChecksumInfo{Size: 13}, false, 1) _, err = DownloadTempWithChecksum(s.d, s.url+"/test", &utils.ChecksumInfo{Size: 13}, false, 1)
c.Assert(err, ErrorMatches, ".*size check mismatch 12 != 13") c.Assert(err, ErrorMatches, ".*size check mismatch 12 != 13")
} }

View File

@@ -8,7 +8,11 @@
"goimports", "goimports",
"misspell", "misspell",
"gosimple", "gosimple",
"ineffassign" "ineffassign",
"staticcheck",
"varcheck",
"structcheck",
"aligncheck"
], ],
"Deadline": "15m" "Deadline": "15m"
} }

View File

@@ -52,7 +52,10 @@ func NewPublishedStorageRaw(
storageClass = "" storageClass = ""
} }
sess := session.New(config) sess, err := session.NewSession(config)
if err != nil {
return nil, err
}
result := &PublishedStorage{ result := &PublishedStorage{
s3: s3.New(sess), s3: s3.New(sess),

View File

@@ -7,7 +7,7 @@ import (
) )
// ConfigStructure is structure of main configuration // ConfigStructure is structure of main configuration
type ConfigStructure struct { type ConfigStructure struct { // nolint: aligncheck
RootDir string `json:"rootDir"` RootDir string `json:"rootDir"`
DownloadConcurrency int `json:"downloadConcurrency"` DownloadConcurrency int `json:"downloadConcurrency"`
DownloadLimit int64 `json:"downloadSpeedLimit"` DownloadLimit int64 `json:"downloadSpeedLimit"`