From aa16899c60d0adfbf18127f2d8d98c24c7f7fde8 Mon Sep 17 00:00:00 2001 From: Clemens Rabe Date: Fri, 24 Mar 2017 06:25:46 +0100 Subject: [PATCH] Adaption of tests. --- cmd/mirror_update.go | 6 ++-- deb/remote.go | 6 ++-- deb/remote_test.go | 70 ++++++++++++++++++++++++-------------------- 3 files changed, 44 insertions(+), 38 deletions(-) diff --git a/cmd/mirror_update.go b/cmd/mirror_update.go index 0962201e0..887ff0c81 100644 --- a/cmd/mirror_update.go +++ b/cmd/mirror_update.go @@ -81,10 +81,10 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error { queue []deb.PackageDownloadTask ) - skip_existing_packages := context.Flags().Lookup("skip-existing-packages").Value.Get().(bool) + skipExistingPackages := context.Flags().Lookup("skip-existing-packages").Value.Get().(bool) context.Progress().Printf("Building download queue...\n") - queue, downloadSize, err = repo.BuildDownloadQueue(context.PackagePool(), skip_existing_packages) + queue, downloadSize, err = repo.BuildDownloadQueue(context.PackagePool(), skipExistingPackages) if err != nil { return fmt.Errorf("unable to update: %s", err) } @@ -190,7 +190,7 @@ Example: cmd.Flag.Bool("force", false, "force update mirror even if it is locked by another process") cmd.Flag.Bool("ignore-checksums", false, "ignore checksum mismatches while downloading package files and metadata") cmd.Flag.Bool("ignore-signatures", false, "disable verification of Release file signatures") - cmd.Flag.Bool("skip-existing-packages", false, "do not check file existance for packages listed in the internal database of the mirror") + cmd.Flag.Bool("skip-existing-packages", false, "do not check file existence for packages listed in the internal database of the mirror") cmd.Flag.Int64("download-limit", 0, "limit download speed (kbytes/sec)") cmd.Flag.Int("max-tries", 1, "max download tries till process fails with download error") cmd.Flag.Var(&keyRingsFlag{}, "keyring", "gpg keyring to use when verifying Release file (could be specified multiple times)") diff --git a/deb/remote.go b/deb/remote.go index 526127aeb..dcbb8b61d 100644 --- a/deb/remote.go +++ b/deb/remote.go @@ -506,14 +506,14 @@ func (repo *RemoteRepo) ApplyFilter(dependencyOptions int, filterQuery PackageQu } // BuildDownloadQueue builds queue, discards current PackageList -func (repo *RemoteRepo) BuildDownloadQueue(packagePool aptly.PackagePool, skip_existing_packages bool) (queue []PackageDownloadTask, downloadSize int64, err error) { +func (repo *RemoteRepo) BuildDownloadQueue(packagePool aptly.PackagePool, skipExistingPackages bool) (queue []PackageDownloadTask, downloadSize int64, err error) { queue = make([]PackageDownloadTask, 0, repo.packageList.Len()) seen := make(map[string]struct{}, repo.packageList.Len()) err = repo.packageList.ForEach(func(p *Package) error { download := true - if repo.packageRefs != nil && skip_existing_packages { - download = ! repo.packageRefs.Has(p) + if repo.packageRefs != nil && skipExistingPackages { + download = !repo.packageRefs.Has(p) } if download { diff --git a/deb/remote_test.go b/deb/remote_test.go index fe1994d16..a4bb00b1c 100644 --- a/deb/remote_test.go +++ b/deb/remote_test.go @@ -284,11 +284,11 @@ func (s *RemoteRepoSuite) TestDownload(c *C) { err = s.repo.Fetch(s.downloader, nil) c.Assert(err, IsNil) - s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.bz2", &http.HTTPError{Code: 404}) - s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.gz", &http.HTTPError{Code: 404}) + s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.bz2", &http.Error{Code: 404}) + s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.gz", &http.Error{Code: 404}) s.downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages", examplePackagesFile) - err = s.repo.DownloadPackageIndexes(s.progress, s.downloader, s.collectionFactory, false) + err = s.repo.DownloadPackageIndexes(s.progress, s.downloader, s.collectionFactory, false, 1) c.Assert(err, IsNil) c.Assert(s.downloader.Empty(), Equals, true) @@ -304,11 +304,11 @@ func (s *RemoteRepoSuite) TestDownload(c *C) { err = s.repo.Fetch(s.downloader, nil) c.Assert(err, IsNil) - s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.bz2", &http.HTTPError{Code: 404}) - s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.gz", &http.HTTPError{Code: 404}) + s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.bz2", &http.Error{Code: 404}) + s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.gz", &http.Error{Code: 404}) s.downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages", examplePackagesFile) - err = s.repo.DownloadPackageIndexes(s.progress, s.downloader, s.collectionFactory, false) + err = s.repo.DownloadPackageIndexes(s.progress, s.downloader, s.collectionFactory, false, 1) c.Assert(err, IsNil) c.Assert(s.downloader.Empty(), Equals, true) @@ -371,14 +371,14 @@ func (s *RemoteRepoSuite) TestDownloadWithSources(c *C) { err = s.repo.Fetch(s.downloader, nil) c.Assert(err, IsNil) - s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.bz2", &http.HTTPError{Code: 404}) - s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.gz", &http.HTTPError{Code: 404}) + s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.bz2", &http.Error{Code: 404}) + s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.gz", &http.Error{Code: 404}) s.downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages", examplePackagesFile) - s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/source/Sources.bz2", &http.HTTPError{Code: 404}) - s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/source/Sources.gz", &http.HTTPError{Code: 404}) + s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/source/Sources.bz2", &http.Error{Code: 404}) + s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/source/Sources.gz", &http.Error{Code: 404}) s.downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/main/source/Sources", exampleSourcesFile) - err = s.repo.DownloadPackageIndexes(s.progress, s.downloader, s.collectionFactory, false) + err = s.repo.DownloadPackageIndexes(s.progress, s.downloader, s.collectionFactory, false, 1) c.Assert(err, IsNil) c.Assert(s.downloader.Empty(), Equals, true) @@ -395,14 +395,14 @@ func (s *RemoteRepoSuite) TestDownloadWithSources(c *C) { err = s.repo.Fetch(s.downloader, nil) c.Assert(err, IsNil) - s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.bz2", &http.HTTPError{Code: 404}) - s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.gz", &http.HTTPError{Code: 404}) + s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.bz2", &http.Error{Code: 404}) + s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.gz", &http.Error{Code: 404}) s.downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages", examplePackagesFile) - s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/source/Sources.bz2", &http.HTTPError{Code: 404}) - s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/source/Sources.gz", &http.HTTPError{Code: 404}) + s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/source/Sources.bz2", &http.Error{Code: 404}) + s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/source/Sources.gz", &http.Error{Code: 404}) s.downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/main/source/Sources", exampleSourcesFile) - err = s.repo.DownloadPackageIndexes(s.progress, s.downloader, s.collectionFactory, false) + err = s.repo.DownloadPackageIndexes(s.progress, s.downloader, s.collectionFactory, false, 1) c.Assert(err, IsNil) c.Assert(s.downloader.Empty(), Equals, true) @@ -444,14 +444,15 @@ func (s *RemoteRepoSuite) TestDownloadFlat(c *C) { // Next call must return an empty download list with option "skip-existing-packages" downloader.ExpectResponse("http://repos.express42.com/virool/precise/Release", exampleReleaseFile) - downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.bz2", &http.HTTPError{Code: 404}) - downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.gz", &http.HTTPError{Code: 404}) + downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.bz2", &http.Error{Code: 404}) + downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.gz", &http.Error{Code: 404}) + downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.xz", &http.Error{Code: 404}) downloader.ExpectResponse("http://repos.express42.com/virool/precise/Packages", examplePackagesFile) err = s.flat.Fetch(downloader, nil) c.Assert(err, IsNil) - err = s.flat.DownloadPackageIndexes(s.progress, downloader, s.collectionFactory, true) + err = s.flat.DownloadPackageIndexes(s.progress, downloader, s.collectionFactory, true, 1) c.Assert(err, IsNil) c.Assert(downloader.Empty(), Equals, true) @@ -464,14 +465,15 @@ func (s *RemoteRepoSuite) TestDownloadFlat(c *C) { // Next call must return the download list without option "skip-existing-packages" downloader.ExpectResponse("http://repos.express42.com/virool/precise/Release", exampleReleaseFile) - downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.bz2", &http.HTTPError{Code: 404}) - downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.gz", &http.HTTPError{Code: 404}) + downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.bz2", &http.Error{Code: 404}) + downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.gz", &http.Error{Code: 404}) + downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.xz", &http.Error{Code: 404}) downloader.ExpectResponse("http://repos.express42.com/virool/precise/Packages", examplePackagesFile) err = s.flat.Fetch(downloader, nil) c.Assert(err, IsNil) - err = s.flat.DownloadPackageIndexes(s.progress, downloader, s.collectionFactory, true) + err = s.flat.DownloadPackageIndexes(s.progress, downloader, s.collectionFactory, true, 1) c.Assert(err, IsNil) c.Assert(downloader.Empty(), Equals, true) @@ -534,17 +536,19 @@ func (s *RemoteRepoSuite) TestDownloadWithSourcesFlat(c *C) { // Next call must return an empty download list with option "skip-existing-packages" downloader.ExpectResponse("http://repos.express42.com/virool/precise/Release", exampleReleaseFile) - downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.bz2", &http.HTTPError{Code: 404}) - downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.gz", &http.HTTPError{Code: 404}) + downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.bz2", &http.Error{Code: 404}) + downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.gz", &http.Error{Code: 404}) + downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.xz", &http.Error{Code: 404}) downloader.ExpectResponse("http://repos.express42.com/virool/precise/Packages", examplePackagesFile) - downloader.ExpectError("http://repos.express42.com/virool/precise/Sources.bz2", &http.HTTPError{Code: 404}) - downloader.ExpectError("http://repos.express42.com/virool/precise/Sources.gz", &http.HTTPError{Code: 404}) + downloader.ExpectError("http://repos.express42.com/virool/precise/Sources.bz2", &http.Error{Code: 404}) + downloader.ExpectError("http://repos.express42.com/virool/precise/Sources.gz", &http.Error{Code: 404}) + downloader.ExpectError("http://repos.express42.com/virool/precise/Sources.xz", &http.Error{Code: 404}) downloader.ExpectResponse("http://repos.express42.com/virool/precise/Sources", exampleSourcesFile) err = s.flat.Fetch(downloader, nil) c.Assert(err, IsNil) - err = s.flat.DownloadPackageIndexes(s.progress, downloader, s.collectionFactory, true) + err = s.flat.DownloadPackageIndexes(s.progress, downloader, s.collectionFactory, true, 1) c.Assert(err, IsNil) c.Assert(downloader.Empty(), Equals, true) @@ -557,17 +561,19 @@ func (s *RemoteRepoSuite) TestDownloadWithSourcesFlat(c *C) { // Next call must return the download list without option "skip-existing-packages" downloader.ExpectResponse("http://repos.express42.com/virool/precise/Release", exampleReleaseFile) - downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.bz2", &http.HTTPError{Code: 404}) - downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.gz", &http.HTTPError{Code: 404}) + downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.bz2", &http.Error{Code: 404}) + downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.gz", &http.Error{Code: 404}) + downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.xz", &http.Error{Code: 404}) downloader.ExpectResponse("http://repos.express42.com/virool/precise/Packages", examplePackagesFile) - downloader.ExpectError("http://repos.express42.com/virool/precise/Sources.bz2", &http.HTTPError{Code: 404}) - downloader.ExpectError("http://repos.express42.com/virool/precise/Sources.gz", &http.HTTPError{Code: 404}) + downloader.ExpectError("http://repos.express42.com/virool/precise/Sources.bz2", &http.Error{Code: 404}) + downloader.ExpectError("http://repos.express42.com/virool/precise/Sources.gz", &http.Error{Code: 404}) + downloader.ExpectError("http://repos.express42.com/virool/precise/Sources.xz", &http.Error{Code: 404}) downloader.ExpectResponse("http://repos.express42.com/virool/precise/Sources", exampleSourcesFile) err = s.flat.Fetch(downloader, nil) c.Assert(err, IsNil) - err = s.flat.DownloadPackageIndexes(s.progress, downloader, s.collectionFactory, true) + err = s.flat.DownloadPackageIndexes(s.progress, downloader, s.collectionFactory, true, 1) c.Assert(err, IsNil) c.Assert(downloader.Empty(), Equals, true)