remote_test.go 42.2 KB
Newer Older
1 2 3 4
package deb

import (
	"errors"
5 6 7 8 9
	"io"
	"io/ioutil"
	"os"
	"sort"

10 11 12 13 14 15 16
	"github.com/aptly-dev/aptly/aptly"
	"github.com/aptly-dev/aptly/console"
	"github.com/aptly-dev/aptly/database"
	"github.com/aptly-dev/aptly/files"
	"github.com/aptly-dev/aptly/http"
	"github.com/aptly-dev/aptly/pgp"
	"github.com/aptly-dev/aptly/utils"
17 18

	. "gopkg.in/check.v1"
19 20 21 22 23 24 25 26 27 28 29 30
)

type NullVerifier struct {
}

func (n *NullVerifier) InitKeyring() error {
	return nil
}

func (n *NullVerifier) AddKeyring(keyring string) {
}

31
func (n *NullVerifier) VerifyDetachedSignature(signature, cleartext io.Reader, hint bool) error {
32 33 34
	return nil
}

35
func (n *NullVerifier) VerifyClearsigned(clearsigned io.Reader, hint bool) (*pgp.KeyInfo, error) {
36
	return nil, nil
37 38 39 40 41 42 43 44 45 46 47
}

func (n *NullVerifier) ExtractClearsigned(clearsigned io.Reader) (text *os.File, err error) {
	text, _ = ioutil.TempFile("", "aptly-test")
	io.Copy(text, clearsigned)
	text.Seek(0, 0)
	os.Remove(text.Name())

	return
}

48 49 50 51
func (n *NullVerifier) IsClearSigned(clearsign io.Reader) (bool, error) {
	return false, nil
}

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
type PackageListMixinSuite struct {
	p1, p2, p3 *Package
	list       *PackageList
	reflist    *PackageRefList
}

func (s *PackageListMixinSuite) SetUpPackages() {
	s.list = NewPackageList()

	s.p1 = NewPackageFromControlFile(packageStanza.Copy())
	stanza := packageStanza.Copy()
	stanza["Package"] = "mars-invaders"
	s.p2 = NewPackageFromControlFile(stanza)
	stanza = packageStanza.Copy()
	stanza["Package"] = "lonely-strangers"
	s.p3 = NewPackageFromControlFile(stanza)

	s.list.Add(s.p1)
	s.list.Add(s.p2)
	s.list.Add(s.p3)

	s.reflist = NewPackageRefListFromPackageList(s.list)
}

type RemoteRepoSuite struct {
	PackageListMixinSuite
	repo              *RemoteRepo
	flat              *RemoteRepo
	downloader        *http.FakeDownloader
	progress          aptly.Progress
	db                database.Storage
	collectionFactory *CollectionFactory
	packagePool       aptly.PackagePool
85
	cs                aptly.ChecksumStorage
86 87 88 89 90
}

var _ = Suite(&RemoteRepoSuite{})

func (s *RemoteRepoSuite) SetUpTest(c *C) {
91 92
	s.repo, _ = NewRemoteRepo("yandex", "http://mirror.yandex.ru/debian", "squeeze", []string{"main"}, []string{}, false, false)
	s.flat, _ = NewRemoteRepo("exp42", "http://repos.express42.com/virool/precise/", "./", []string{}, []string{}, false, false)
93 94
	s.downloader = http.NewFakeDownloader().ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/Release", exampleReleaseFile)
	s.progress = console.NewProgress()
95
	s.db, _ = database.NewOpenDB(c.MkDir())
96
	s.collectionFactory = NewCollectionFactory(s.db)
97 98
	s.packagePool = files.NewPackagePool(c.MkDir(), false)
	s.cs = files.NewMockChecksumStorage()
99 100 101 102 103 104 105 106 107 108
	s.SetUpPackages()
	s.progress.Start()
}

func (s *RemoteRepoSuite) TearDownTest(c *C) {
	s.progress.Shutdown()
	s.db.Close()
}

func (s *RemoteRepoSuite) TestInvalidURL(c *C) {
109
	_, err := NewRemoteRepo("s", "http://lolo%2", "squeeze", []string{"main"}, []string{}, false, false)
110
	c.Assert(err, ErrorMatches, ".*(hexadecimal escape in host|percent-encoded characters in host|invalid URL escape).*")
111 112 113
}

func (s *RemoteRepoSuite) TestFlatCreation(c *C) {
114 115
	c.Check(s.flat.IsFlat(), Equals, true)
	c.Check(s.flat.Distribution, Equals, "./")
116 117 118
	c.Check(s.flat.Architectures, IsNil)
	c.Check(s.flat.Components, IsNil)

119
	flat2, _ := NewRemoteRepo("flat2", "http://pkg.jenkins-ci.org/debian-stable", "binary/", []string{}, []string{}, false, false)
120 121 122
	c.Check(flat2.IsFlat(), Equals, true)
	c.Check(flat2.Distribution, Equals, "./binary/")

123
	_, err := NewRemoteRepo("fl", "http://some.repo/", "./", []string{"main"}, []string{}, false, false)
124 125 126 127 128 129 130 131
	c.Check(err, ErrorMatches, "components aren't supported for flat repos")
}

func (s *RemoteRepoSuite) TestString(c *C) {
	c.Check(s.repo.String(), Equals, "[yandex]: http://mirror.yandex.ru/debian/ squeeze")
	c.Check(s.flat.String(), Equals, "[exp42]: http://repos.express42.com/virool/precise/ ./")

	s.repo.DownloadSources = true
132
	s.repo.DownloadUdebs = true
133
	s.flat.DownloadSources = true
134
	c.Check(s.repo.String(), Equals, "[yandex]: http://mirror.yandex.ru/debian/ squeeze [src] [udeb]")
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
	c.Check(s.flat.String(), Equals, "[exp42]: http://repos.express42.com/virool/precise/ ./ [src]")
}

func (s *RemoteRepoSuite) TestNumPackages(c *C) {
	c.Check(s.repo.NumPackages(), Equals, 0)
	s.repo.packageRefs = s.reflist
	c.Check(s.repo.NumPackages(), Equals, 3)
}

func (s *RemoteRepoSuite) TestIsFlat(c *C) {
	c.Check(s.repo.IsFlat(), Equals, false)
	c.Check(s.flat.IsFlat(), Equals, true)
}

func (s *RemoteRepoSuite) TestRefList(c *C) {
	s.repo.packageRefs = s.reflist
	c.Check(s.repo.RefList(), Equals, s.reflist)
}

func (s *RemoteRepoSuite) TestReleaseURL(c *C) {
	c.Assert(s.repo.ReleaseURL("Release").String(), Equals, "http://mirror.yandex.ru/debian/dists/squeeze/Release")
	c.Assert(s.repo.ReleaseURL("InRelease").String(), Equals, "http://mirror.yandex.ru/debian/dists/squeeze/InRelease")

	c.Assert(s.flat.ReleaseURL("Release").String(), Equals, "http://repos.express42.com/virool/precise/Release")
}

161 162 163 164 165 166 167 168
func (s *RemoteRepoSuite) TestIndexesRootURL(c *C) {
	c.Assert(s.repo.IndexesRootURL().String(), Equals, "http://mirror.yandex.ru/debian/dists/squeeze/")

	c.Assert(s.flat.IndexesRootURL().String(), Equals, "http://repos.express42.com/virool/precise/")
}

func (s *RemoteRepoSuite) TestBinaryPath(c *C) {
	c.Assert(s.repo.BinaryPath("main", "amd64"), Equals, "main/binary-amd64/Packages")
169 170
}

171 172
func (s *RemoteRepoSuite) TestUdebPath(c *C) {
	c.Assert(s.repo.UdebPath("main", "amd64"), Equals, "main/debian-installer/binary-amd64/Packages")
173 174
}

175 176
func (s *RemoteRepoSuite) TestSourcesPath(c *C) {
	c.Assert(s.repo.SourcesPath("main"), Equals, "main/source/Sources")
177 178
}

179 180
func (s *RemoteRepoSuite) TestFlatBinaryPath(c *C) {
	c.Assert(s.flat.FlatBinaryPath(), Equals, "Packages")
181 182
}

183 184
func (s *RemoteRepoSuite) TestFlatSourcesPath(c *C) {
	c.Assert(s.flat.FlatSourcesPath(), Equals, "Sources")
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
}

func (s *RemoteRepoSuite) TestPackageURL(c *C) {
	c.Assert(s.repo.PackageURL("pool/main/0/0ad/0ad_0~r11863-2_i386.deb").String(), Equals,
		"http://mirror.yandex.ru/debian/pool/main/0/0ad/0ad_0~r11863-2_i386.deb")
}

func (s *RemoteRepoSuite) TestFetch(c *C) {
	err := s.repo.Fetch(s.downloader, nil)
	c.Assert(err, IsNil)
	c.Assert(s.repo.Architectures, DeepEquals, []string{"amd64", "armel", "armhf", "i386", "powerpc"})
	c.Assert(s.repo.Components, DeepEquals, []string{"main"})
	c.Assert(s.downloader.Empty(), Equals, true)

	c.Check(s.repo.ReleaseFiles, HasLen, 39)
	c.Check(s.repo.ReleaseFiles["main/binary-i386/Packages.bz2"], DeepEquals,
		utils.ChecksumInfo{
			Size:   734,
			MD5:    "7954ed80936429687122b554620c1b5b",
			SHA1:   "95a463a0739bf9ff622c8d68f6e4598d400f5248",
			SHA256: "377890a26f99db55e117dfc691972dcbbb7d8be1630c8fc8297530c205377f2b"})
}

func (s *RemoteRepoSuite) TestFetchNullVerifier1(c *C) {
	downloader := http.NewFakeDownloader()
210
	downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/InRelease", &http.Error{Code: 404})
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
	downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/Release", exampleReleaseFile)
	downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/Release.gpg", "GPG")

	err := s.repo.Fetch(downloader, &NullVerifier{})
	c.Assert(err, IsNil)
	c.Assert(s.repo.Architectures, DeepEquals, []string{"amd64", "armel", "armhf", "i386", "powerpc"})
	c.Assert(s.repo.Components, DeepEquals, []string{"main"})
	c.Assert(downloader.Empty(), Equals, true)
}

func (s *RemoteRepoSuite) TestFetchNullVerifier2(c *C) {
	downloader := http.NewFakeDownloader()
	downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/InRelease", exampleReleaseFile)

	err := s.repo.Fetch(downloader, &NullVerifier{})
	c.Assert(err, IsNil)
	c.Assert(s.repo.Architectures, DeepEquals, []string{"amd64", "armel", "armhf", "i386", "powerpc"})
	c.Assert(s.repo.Components, DeepEquals, []string{"main"})
	c.Assert(downloader.Empty(), Equals, true)
}

func (s *RemoteRepoSuite) TestFetchWrongArchitecture(c *C) {
233
	s.repo, _ = NewRemoteRepo("s", "http://mirror.yandex.ru/debian/", "squeeze", []string{"main"}, []string{"xyz"}, false, false)
234 235 236 237 238
	err := s.repo.Fetch(s.downloader, nil)
	c.Assert(err, ErrorMatches, "architecture xyz not available in repo.*")
}

func (s *RemoteRepoSuite) TestFetchWrongComponent(c *C) {
239
	s.repo, _ = NewRemoteRepo("s", "http://mirror.yandex.ru/debian/", "squeeze", []string{"xyz"}, []string{"i386"}, false, false)
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
	err := s.repo.Fetch(s.downloader, nil)
	c.Assert(err, ErrorMatches, "component xyz not available in repo.*")
}

func (s *RemoteRepoSuite) TestEncodeDecode(c *C) {
	repo := &RemoteRepo{}
	err := repo.Decode(s.repo.Encode())
	c.Assert(err, IsNil)

	c.Check(repo.Name, Equals, "yandex")
	c.Check(repo.ArchiveRoot, Equals, "http://mirror.yandex.ru/debian/")
}

func (s *RemoteRepoSuite) TestKey(c *C) {
	c.Assert(len(s.repo.Key()), Equals, 37)
	c.Assert(s.repo.Key()[0], Equals, byte('R'))
}

func (s *RemoteRepoSuite) TestRefKey(c *C) {
	c.Assert(len(s.repo.RefKey()), Equals, 37)
	c.Assert(s.repo.RefKey()[0], Equals, byte('E'))
	c.Assert(s.repo.RefKey()[1:], DeepEquals, s.repo.Key()[1:])
}

func (s *RemoteRepoSuite) TestDownload(c *C) {
	s.repo.Architectures = []string{"i386"}

	err := s.repo.Fetch(s.downloader, nil)
	c.Assert(err, IsNil)

270 271
	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})
272 273
	s.downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages", examplePackagesFile)

274
	err = s.repo.DownloadPackageIndexes(s.progress, s.downloader, s.collectionFactory, false, 1)
275 276
	c.Assert(err, IsNil)
	c.Assert(s.downloader.Empty(), Equals, true)
277

278 279
	queue, size, err := s.repo.BuildDownloadQueue(s.packagePool, s.collectionFactory.PackageCollection(), s.cs, false)
	c.Assert(err, IsNil)
280 281
	c.Check(size, Equals, int64(3))
	c.Check(queue, HasLen, 1)
282
	c.Check(queue[0].File.DownloadURL(), Equals, "pool/main/a/amanda/amanda-client_3.3.1-3~bpo60+1_amd64.deb")
283

284
	s.repo.FinalizeDownload(s.collectionFactory, nil)
285 286 287 288 289 290
	c.Assert(s.repo.packageRefs, NotNil)

	pkg, err := s.collectionFactory.PackageCollection().ByKey(s.repo.packageRefs.Refs[0])
	c.Assert(err, IsNil)

	c.Check(pkg.Name, Equals, "amanda-client")
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333

	// Next call must return an empty download list with option "skip-existing-packages"
	s.downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/Release", exampleReleaseFile)
	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.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, 1)
	c.Assert(err, IsNil)
	c.Assert(s.downloader.Empty(), Equals, true)

	queue, size, err = s.repo.BuildDownloadQueue(s.packagePool, s.collectionFactory.PackageCollection(), s.cs, true)
	c.Assert(err, IsNil)
	c.Check(size, Equals, int64(0))
	c.Check(queue, HasLen, 0)

	s.repo.FinalizeDownload(s.collectionFactory, nil)
	c.Assert(s.repo.packageRefs, NotNil)

	// Next call must return the download list without option "skip-existing-packages"
	s.downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/Release", exampleReleaseFile)
	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.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, 1)
	c.Assert(err, IsNil)
	c.Assert(s.downloader.Empty(), Equals, true)

	queue, size, err = s.repo.BuildDownloadQueue(s.packagePool, s.collectionFactory.PackageCollection(), s.cs, false)
	c.Assert(err, IsNil)
	c.Check(size, Equals, int64(3))
	c.Check(queue, HasLen, 1)
	c.Check(queue[0].File.DownloadURL(), Equals, "pool/main/a/amanda/amanda-client_3.3.1-3~bpo60+1_amd64.deb")

	s.repo.FinalizeDownload(s.collectionFactory, nil)
	c.Assert(s.repo.packageRefs, NotNil)
334 335 336 337 338 339 340 341 342
}

func (s *RemoteRepoSuite) TestDownloadWithSources(c *C) {
	s.repo.Architectures = []string{"i386"}
	s.repo.DownloadSources = true

	err := s.repo.Fetch(s.downloader, nil)
	c.Assert(err, IsNil)

343 344
	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})
345
	s.downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages", examplePackagesFile)
346 347
	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})
348 349
	s.downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/main/source/Sources", exampleSourcesFile)

350
	err = s.repo.DownloadPackageIndexes(s.progress, s.downloader, s.collectionFactory, false, 1)
351 352
	c.Assert(err, IsNil)
	c.Assert(s.downloader.Empty(), Equals, true)
353

354 355
	queue, size, err := s.repo.BuildDownloadQueue(s.packagePool, s.collectionFactory.PackageCollection(), s.cs, false)
	c.Assert(err, IsNil)
356 357 358 359 360
	c.Check(size, Equals, int64(15))
	c.Check(queue, HasLen, 4)

	q := make([]string, 4)
	for i := range q {
361
		q[i] = queue[i].File.DownloadURL()
362 363 364 365 366 367 368
	}
	sort.Strings(q)
	c.Check(q[3], Equals, "pool/main/a/amanda/amanda-client_3.3.1-3~bpo60+1_amd64.deb")
	c.Check(q[1], Equals, "pool/main/a/access-modifier-checker/access-modifier-checker_1.0-4.dsc")
	c.Check(q[2], Equals, "pool/main/a/access-modifier-checker/access-modifier-checker_1.0.orig.tar.gz")
	c.Check(q[0], Equals, "pool/main/a/access-modifier-checker/access-modifier-checker_1.0-4.debian.tar.gz")

369
	s.repo.FinalizeDownload(s.collectionFactory, nil)
370 371 372 373 374 375 376 377 378 379
	c.Assert(s.repo.packageRefs, NotNil)

	pkg, err := s.collectionFactory.PackageCollection().ByKey(s.repo.packageRefs.Refs[0])
	c.Assert(err, IsNil)

	c.Check(pkg.Name, Equals, "amanda-client")

	pkg, err = s.collectionFactory.PackageCollection().ByKey(s.repo.packageRefs.Refs[1])
	c.Assert(err, IsNil)
	c.Check(pkg.Name, Equals, "access-modifier-checker")
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429

	// Next call must return an empty download list with option "skip-existing-packages"
	s.downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/Release", exampleReleaseFile)

	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.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.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, 1)
	c.Assert(err, IsNil)
	c.Assert(s.downloader.Empty(), Equals, true)

	queue, size, err = s.repo.BuildDownloadQueue(s.packagePool, s.collectionFactory.PackageCollection(), s.cs, true)
	c.Assert(err, IsNil)
	c.Check(size, Equals, int64(0))
	c.Check(queue, HasLen, 0)

	s.repo.FinalizeDownload(s.collectionFactory, nil)
	c.Assert(s.repo.packageRefs, NotNil)

	// Next call must return the download list without option "skip-existing-packages"
	s.downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/Release", exampleReleaseFile)

	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.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.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, 1)
	c.Assert(err, IsNil)
	c.Assert(s.downloader.Empty(), Equals, true)

	queue, size, err = s.repo.BuildDownloadQueue(s.packagePool, s.collectionFactory.PackageCollection(), s.cs, false)
	c.Assert(err, IsNil)
	c.Check(size, Equals, int64(15))
	c.Check(queue, HasLen, 4)

	s.repo.FinalizeDownload(s.collectionFactory, nil)
	c.Assert(s.repo.packageRefs, NotNil)
430 431 432 433 434
}

func (s *RemoteRepoSuite) TestDownloadFlat(c *C) {
	downloader := http.NewFakeDownloader()
	downloader.ExpectResponse("http://repos.express42.com/virool/precise/Release", exampleReleaseFile)
435 436 437
	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})
438 439 440 441 442
	downloader.ExpectResponse("http://repos.express42.com/virool/precise/Packages", examplePackagesFile)

	err := s.flat.Fetch(downloader, nil)
	c.Assert(err, IsNil)

443
	err = s.flat.DownloadPackageIndexes(s.progress, downloader, s.collectionFactory, true, 1)
444 445
	c.Assert(err, IsNil)
	c.Assert(downloader.Empty(), Equals, true)
446

447 448
	queue, size, err := s.flat.BuildDownloadQueue(s.packagePool, s.collectionFactory.PackageCollection(), s.cs, false)
	c.Assert(err, IsNil)
449 450
	c.Check(size, Equals, int64(3))
	c.Check(queue, HasLen, 1)
451
	c.Check(queue[0].File.DownloadURL(), Equals, "pool/main/a/amanda/amanda-client_3.3.1-3~bpo60+1_amd64.deb")
452

453
	s.flat.FinalizeDownload(s.collectionFactory, nil)
454 455 456 457 458 459
	c.Assert(s.flat.packageRefs, NotNil)

	pkg, err := s.collectionFactory.PackageCollection().ByKey(s.flat.packageRefs.Refs[0])
	c.Assert(err, IsNil)

	c.Check(pkg.Name, Equals, "amanda-client")
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504

	// 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.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, 1)
	c.Assert(err, IsNil)
	c.Assert(downloader.Empty(), Equals, true)

	queue, size, err = s.flat.BuildDownloadQueue(s.packagePool, s.collectionFactory.PackageCollection(), s.cs, true)
	c.Assert(err, IsNil)
	c.Check(size, Equals, int64(0))
	c.Check(queue, HasLen, 0)

	s.flat.FinalizeDownload(s.collectionFactory, nil)
	c.Assert(s.flat.packageRefs, NotNil)

	// 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.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, 1)
	c.Assert(err, IsNil)
	c.Assert(downloader.Empty(), Equals, true)

	queue, size, err = s.flat.BuildDownloadQueue(s.packagePool, s.collectionFactory.PackageCollection(), s.cs, false)
	c.Assert(err, IsNil)
	c.Check(size, Equals, int64(3))
	c.Check(queue, HasLen, 1)
	c.Check(queue[0].File.DownloadURL(), Equals, "pool/main/a/amanda/amanda-client_3.3.1-3~bpo60+1_amd64.deb")

	s.flat.FinalizeDownload(s.collectionFactory, nil)
	c.Assert(s.flat.packageRefs, NotNil)
505 506 507 508 509 510 511
}

func (s *RemoteRepoSuite) TestDownloadWithSourcesFlat(c *C) {
	s.flat.DownloadSources = true

	downloader := http.NewFakeDownloader()
	downloader.ExpectResponse("http://repos.express42.com/virool/precise/Release", exampleReleaseFile)
512 513 514
	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})
515
	downloader.ExpectResponse("http://repos.express42.com/virool/precise/Packages", examplePackagesFile)
516 517 518
	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})
519 520 521 522 523
	downloader.ExpectResponse("http://repos.express42.com/virool/precise/Sources", exampleSourcesFile)

	err := s.flat.Fetch(downloader, nil)
	c.Assert(err, IsNil)

524
	err = s.flat.DownloadPackageIndexes(s.progress, downloader, s.collectionFactory, true, 1)
525 526
	c.Assert(err, IsNil)
	c.Assert(downloader.Empty(), Equals, true)
527

528 529
	queue, size, err := s.flat.BuildDownloadQueue(s.packagePool, s.collectionFactory.PackageCollection(), s.cs, false)
	c.Assert(err, IsNil)
530 531 532 533 534
	c.Check(size, Equals, int64(15))
	c.Check(queue, HasLen, 4)

	q := make([]string, 4)
	for i := range q {
535
		q[i] = queue[i].File.DownloadURL()
536 537 538 539 540 541 542
	}
	sort.Strings(q)
	c.Check(q[3], Equals, "pool/main/a/amanda/amanda-client_3.3.1-3~bpo60+1_amd64.deb")
	c.Check(q[1], Equals, "pool/main/a/access-modifier-checker/access-modifier-checker_1.0-4.dsc")
	c.Check(q[2], Equals, "pool/main/a/access-modifier-checker/access-modifier-checker_1.0.orig.tar.gz")
	c.Check(q[0], Equals, "pool/main/a/access-modifier-checker/access-modifier-checker_1.0-4.debian.tar.gz")

543
	s.flat.FinalizeDownload(s.collectionFactory, nil)
544 545 546 547 548 549 550 551 552 553 554
	c.Assert(s.flat.packageRefs, NotNil)

	pkg, err := s.collectionFactory.PackageCollection().ByKey(s.flat.packageRefs.Refs[0])
	c.Assert(err, IsNil)

	c.Check(pkg.Name, Equals, "amanda-client")

	pkg, err = s.collectionFactory.PackageCollection().ByKey(s.flat.packageRefs.Refs[1])
	c.Assert(err, IsNil)

	c.Check(pkg.Name, Equals, "access-modifier-checker")
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606

	// 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.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.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, 1)
	c.Assert(err, IsNil)
	c.Assert(downloader.Empty(), Equals, true)

	queue, size, err = s.flat.BuildDownloadQueue(s.packagePool, s.collectionFactory.PackageCollection(), s.cs, true)
	c.Assert(err, IsNil)
	c.Check(size, Equals, int64(0))
	c.Check(queue, HasLen, 0)

	s.flat.FinalizeDownload(s.collectionFactory, nil)
	c.Assert(s.flat.packageRefs, NotNil)

	// 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.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.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, 1)
	c.Assert(err, IsNil)
	c.Assert(downloader.Empty(), Equals, true)

	queue, size, err = s.flat.BuildDownloadQueue(s.packagePool, s.collectionFactory.PackageCollection(), s.cs, false)
	c.Assert(err, IsNil)
	c.Check(size, Equals, int64(15))
	c.Check(queue, HasLen, 4)

	s.flat.FinalizeDownload(s.collectionFactory, nil)
	c.Assert(s.flat.packageRefs, NotNil)
607 608 609 610 611 612 613 614 615 616 617
}

type RemoteRepoCollectionSuite struct {
	PackageListMixinSuite
	db         database.Storage
	collection *RemoteRepoCollection
}

var _ = Suite(&RemoteRepoCollectionSuite{})

func (s *RemoteRepoCollectionSuite) SetUpTest(c *C) {
618
	s.db, _ = database.NewOpenDB(c.MkDir())
619 620 621 622 623 624 625 626 627
	s.collection = NewRemoteRepoCollection(s.db)
	s.SetUpPackages()
}

func (s *RemoteRepoCollectionSuite) TearDownTest(c *C) {
	s.db.Close()
}

func (s *RemoteRepoCollectionSuite) TestAddByName(c *C) {
628
	_, err := s.collection.ByName("yandex")
629 630
	c.Assert(err, ErrorMatches, "*.not found")

631
	repo, _ := NewRemoteRepo("yandex", "http://mirror.yandex.ru/debian/", "squeeze", []string{"main"}, []string{}, false, false)
632 633 634
	c.Assert(s.collection.Add(repo), IsNil)
	c.Assert(s.collection.Add(repo), ErrorMatches, ".*already exists")

635
	r, err := s.collection.ByName("yandex")
636 637 638 639 640 641 642 643 644 645
	c.Assert(err, IsNil)
	c.Assert(r.String(), Equals, repo.String())

	collection := NewRemoteRepoCollection(s.db)
	r, err = collection.ByName("yandex")
	c.Assert(err, IsNil)
	c.Assert(r.String(), Equals, repo.String())
}

func (s *RemoteRepoCollectionSuite) TestByUUID(c *C) {
646
	_, err := s.collection.ByUUID("some-uuid")
647 648
	c.Assert(err, ErrorMatches, "*.not found")

649
	repo, _ := NewRemoteRepo("yandex", "http://mirror.yandex.ru/debian/", "squeeze", []string{"main"}, []string{}, false, false)
650 651
	c.Assert(s.collection.Add(repo), IsNil)

652
	r, err := s.collection.ByUUID(repo.UUID)
653 654 655 656 657
	c.Assert(err, IsNil)
	c.Assert(r.String(), Equals, repo.String())
}

func (s *RemoteRepoCollectionSuite) TestUpdateLoadComplete(c *C) {
658
	repo, _ := NewRemoteRepo("yandex", "http://mirror.yandex.ru/debian/", "squeeze", []string{"main"}, []string{}, false, false)
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
	c.Assert(s.collection.Update(repo), IsNil)

	collection := NewRemoteRepoCollection(s.db)
	r, err := collection.ByName("yandex")
	c.Assert(err, IsNil)
	c.Assert(r.packageRefs, IsNil)

	repo.packageRefs = s.reflist
	c.Assert(s.collection.Update(repo), IsNil)

	collection = NewRemoteRepoCollection(s.db)
	r, err = collection.ByName("yandex")
	c.Assert(err, IsNil)
	c.Assert(r.packageRefs, IsNil)
	c.Assert(r.NumPackages(), Equals, 0)
	c.Assert(s.collection.LoadComplete(r), IsNil)
	c.Assert(r.NumPackages(), Equals, 3)
}

func (s *RemoteRepoCollectionSuite) TestForEachAndLen(c *C) {
679
	repo, _ := NewRemoteRepo("yandex", "http://mirror.yandex.ru/debian/", "squeeze", []string{"main"}, []string{}, false, false)
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
	s.collection.Add(repo)

	count := 0
	err := s.collection.ForEach(func(*RemoteRepo) error {
		count++
		return nil
	})
	c.Assert(count, Equals, 1)
	c.Assert(err, IsNil)

	c.Check(s.collection.Len(), Equals, 1)

	e := errors.New("c")

	err = s.collection.ForEach(func(*RemoteRepo) error {
		return e
	})
	c.Assert(err, Equals, e)
}

func (s *RemoteRepoCollectionSuite) TestDrop(c *C) {
701
	repo1, _ := NewRemoteRepo("yandex", "http://mirror.yandex.ru/debian/", "squeeze", []string{"main"}, []string{}, false, false)
702 703
	s.collection.Add(repo1)

704
	repo2, _ := NewRemoteRepo("tyndex", "http://mirror.yandex.ru/debian/", "wheezy", []string{"main"}, []string{}, false, false)
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877
	s.collection.Add(repo2)

	r1, _ := s.collection.ByUUID(repo1.UUID)
	c.Check(r1, Equals, repo1)

	err := s.collection.Drop(repo1)
	c.Check(err, IsNil)

	_, err = s.collection.ByUUID(repo1.UUID)
	c.Check(err, ErrorMatches, "mirror .* not found")

	collection := NewRemoteRepoCollection(s.db)
	_, err = collection.ByName("yandex")
	c.Check(err, ErrorMatches, "mirror .* not found")

	r2, _ := collection.ByName("tyndex")
	c.Check(r2.String(), Equals, repo2.String())

	c.Check(func() { s.collection.Drop(repo1) }, Panics, "repo not found!")
}

const exampleReleaseFile = `Origin: LP-PPA-agenda-developers-daily
Label: Agenda Daily Builds
Suite: precise
Version: 12.04
Codename: precise
Date: Thu, 05 Dec 2013  8:14:32 UTC
Architectures: amd64 armel armhf i386 powerpc
Components: main
Description: Ubuntu Precise 12.04
MD5Sum:
 6a5fc91b7277021999268e04a8d74d4c              134 main/binary-amd64/Release
 01ff4a18aab39546fde304a35350fc2d              643 main/binary-amd64/Packages.gz
 52ded91eeb8490b02016335aa3343492             1350 main/binary-amd64/Packages
 5216f9ffe55d151cd7ce7b98b7a43bd7              735 main/binary-amd64/Packages.bz2
 d41d8cd98f00b204e9800998ecf8427e                0 main/binary-armel/Packages
 4059d198768f9f8dc9372dc1c54bc3c3               14 main/binary-armel/Packages.bz2
 7a9de1fb7bf60d416a77d9c9a9716675              134 main/binary-armel/Release
 9d10bb61e59bd799891ae4fbcf447ec9               29 main/binary-armel/Packages.gz
 9d10bb61e59bd799891ae4fbcf447ec9               29 main/binary-armhf/Packages.gz
 c63d31e8e3a5650c29a7124e541d6c23              134 main/binary-armhf/Release
 4059d198768f9f8dc9372dc1c54bc3c3               14 main/binary-armhf/Packages.bz2
 d41d8cd98f00b204e9800998ecf8427e                0 main/binary-armhf/Packages
 c8d336856df67d509032bb54145c2f89              826 main/binary-i386/Packages
 92262f0668b265401291f0467bc93763              133 main/binary-i386/Release
 7954ed80936429687122b554620c1b5b              734 main/binary-i386/Packages.bz2
 e2eef4fe7d285b12c511adfa3a39069e              641 main/binary-i386/Packages.gz
 4059d198768f9f8dc9372dc1c54bc3c3               14 main/binary-powerpc/Packages.bz2
 9d10bb61e59bd799891ae4fbcf447ec9               29 main/binary-powerpc/Packages.gz
 d41d8cd98f00b204e9800998ecf8427e                0 main/binary-powerpc/Packages
 b079563fd3367c11f7be049bc686dd10              136 main/binary-powerpc/Release
 9d10bb61e59bd799891ae4fbcf447ec9               29 main/debian-installer/binary-amd64/Packages.gz
 d41d8cd98f00b204e9800998ecf8427e                0 main/debian-installer/binary-amd64/Packages
 4059d198768f9f8dc9372dc1c54bc3c3               14 main/debian-installer/binary-amd64/Packages.bz2
 9d10bb61e59bd799891ae4fbcf447ec9               29 main/debian-installer/binary-armel/Packages.gz
 d41d8cd98f00b204e9800998ecf8427e                0 main/debian-installer/binary-armel/Packages
 4059d198768f9f8dc9372dc1c54bc3c3               14 main/debian-installer/binary-armel/Packages.bz2
 9d10bb61e59bd799891ae4fbcf447ec9               29 main/debian-installer/binary-armhf/Packages.gz
 d41d8cd98f00b204e9800998ecf8427e                0 main/debian-installer/binary-armhf/Packages
 4059d198768f9f8dc9372dc1c54bc3c3               14 main/debian-installer/binary-armhf/Packages.bz2
 d41d8cd98f00b204e9800998ecf8427e                0 main/debian-installer/binary-i386/Packages
 9d10bb61e59bd799891ae4fbcf447ec9               29 main/debian-installer/binary-i386/Packages.gz
 4059d198768f9f8dc9372dc1c54bc3c3               14 main/debian-installer/binary-i386/Packages.bz2
 d41d8cd98f00b204e9800998ecf8427e                0 main/debian-installer/binary-powerpc/Packages
 4059d198768f9f8dc9372dc1c54bc3c3               14 main/debian-installer/binary-powerpc/Packages.bz2
 9d10bb61e59bd799891ae4fbcf447ec9               29 main/debian-installer/binary-powerpc/Packages.gz
 3481d65651306df1596dca9078c2506a              135 main/source/Release
 0459b7e4512db5479cb982bac6e2f9a1             2003 main/source/Sources
 3d83a489f1bd3c04226aa6520b8a6d07              656 main/source/Sources.bz2
 b062b5b77094aeeb05ca8dbb1ecf68a9              592 main/source/Sources.gz
SHA1:
 fb0b7c8935623ed7d8c45044ba62225fd8cbd4ad              134 main/binary-amd64/Release
 b5d62bcec4ec18b88d664255e9051645bab7bd01              643 main/binary-amd64/Packages.gz
 ed47aae8926d22d529c27b40b61604aed2cb5f2f             1350 main/binary-amd64/Packages
 5b9b171ffcea36e869eba31bcc0e1bfb2a6ad84f              735 main/binary-amd64/Packages.bz2
 da39a3ee5e6b4b0d3255bfef95601890afd80709                0 main/binary-armel/Packages
 64a543afbb5f4bf728636bdcbbe7a2ed0804adc2               14 main/binary-armel/Packages.bz2
 b89234a7efb74d02f15b88e264b5cd2ae1e5dc2d              134 main/binary-armel/Release
 3df6ca52b6e8ecfb4a8fac6b8e02c777e3c7960d               29 main/binary-armel/Packages.gz
 3df6ca52b6e8ecfb4a8fac6b8e02c777e3c7960d               29 main/binary-armhf/Packages.gz
 585a452e27c2e7e047c49d4b0a7459d8c627aa08              134 main/binary-armhf/Release
 64a543afbb5f4bf728636bdcbbe7a2ed0804adc2               14 main/binary-armhf/Packages.bz2
 da39a3ee5e6b4b0d3255bfef95601890afd80709                0 main/binary-armhf/Packages
 1d2f0cd7a3c9e687b853eb277e241cd712b6e3b1              826 main/binary-i386/Packages
 16020809662f9bda36eb516d0995658dd94d1ad5              133 main/binary-i386/Release
 95a463a0739bf9ff622c8d68f6e4598d400f5248              734 main/binary-i386/Packages.bz2
 bf8c0dec9665ba78311c97cae1755d4b2e60af76              641 main/binary-i386/Packages.gz
 64a543afbb5f4bf728636bdcbbe7a2ed0804adc2               14 main/binary-powerpc/Packages.bz2
 3df6ca52b6e8ecfb4a8fac6b8e02c777e3c7960d               29 main/binary-powerpc/Packages.gz
 da39a3ee5e6b4b0d3255bfef95601890afd80709                0 main/binary-powerpc/Packages
 cf2ae2d98f535d90209f2c4e5790f95b393d8c2b              136 main/binary-powerpc/Release
 3df6ca52b6e8ecfb4a8fac6b8e02c777e3c7960d               29 main/debian-installer/binary-amd64/Packages.gz
 da39a3ee5e6b4b0d3255bfef95601890afd80709                0 main/debian-installer/binary-amd64/Packages
 64a543afbb5f4bf728636bdcbbe7a2ed0804adc2               14 main/debian-installer/binary-amd64/Packages.bz2
 3df6ca52b6e8ecfb4a8fac6b8e02c777e3c7960d               29 main/debian-installer/binary-armel/Packages.gz
 da39a3ee5e6b4b0d3255bfef95601890afd80709                0 main/debian-installer/binary-armel/Packages
 64a543afbb5f4bf728636bdcbbe7a2ed0804adc2               14 main/debian-installer/binary-armel/Packages.bz2
 3df6ca52b6e8ecfb4a8fac6b8e02c777e3c7960d               29 main/debian-installer/binary-armhf/Packages.gz
 da39a3ee5e6b4b0d3255bfef95601890afd80709                0 main/debian-installer/binary-armhf/Packages
 64a543afbb5f4bf728636bdcbbe7a2ed0804adc2               14 main/debian-installer/binary-armhf/Packages.bz2
 da39a3ee5e6b4b0d3255bfef95601890afd80709                0 main/debian-installer/binary-i386/Packages
 3df6ca52b6e8ecfb4a8fac6b8e02c777e3c7960d               29 main/debian-installer/binary-i386/Packages.gz
 64a543afbb5f4bf728636bdcbbe7a2ed0804adc2               14 main/debian-installer/binary-i386/Packages.bz2
 da39a3ee5e6b4b0d3255bfef95601890afd80709                0 main/debian-installer/binary-powerpc/Packages
 64a543afbb5f4bf728636bdcbbe7a2ed0804adc2               14 main/debian-installer/binary-powerpc/Packages.bz2
 3df6ca52b6e8ecfb4a8fac6b8e02c777e3c7960d               29 main/debian-installer/binary-powerpc/Packages.gz
 49cfec0c9b1df3a25e983a3ddf29d15b0e376e02              135 main/source/Release
 6b92e0fc84307226172696fde59ca5f33f380b57             2003 main/source/Sources
 ecb8afea11030a5df46941cb8ec297ca24c85736              656 main/source/Sources.bz2
 923e71383969c91146f12fa8cd121397f2467a2e              592 main/source/Sources.gz
SHA256:
 8c0314cfb1b48a8daf47f77420330fd0d78a31897eeb46e05a51964c9f2c02df              134 main/binary-amd64/Release
 81b072773d2fdd8471473e060d3bf73255e4c00d322cf387654736ea196e83b4              643 main/binary-amd64/Packages.gz
 c7bb299483277bbf7bf4165042edaf547f5fa18f5782c7d2cd8407a38a327cc8             1350 main/binary-amd64/Packages
 d263f735c3830caa33ae6441529bd4f8e382205af597ab2cdfcea73afdaa21ab              735 main/binary-amd64/Packages.bz2
 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855                0 main/binary-armel/Packages
 d3dda84eb03b9738d118eb2be78e246106900493c0ae07819ad60815134a8058               14 main/binary-armel/Packages.bz2
 75ede815b020626c6aa16201d24099ed7e06f03643d0cf38ef194f1029ea648b              134 main/binary-armel/Release
 825d493158fe0f50ca1acd70367aefa391170563af2e4ee9cedbcbe6796c8384               29 main/binary-armel/Packages.gz
 825d493158fe0f50ca1acd70367aefa391170563af2e4ee9cedbcbe6796c8384               29 main/binary-armhf/Packages.gz
 d25382b633c4a1621f8df6ce86e5c63da2e506a377e05ae9453238bb18191540              134 main/binary-armhf/Release
 d3dda84eb03b9738d118eb2be78e246106900493c0ae07819ad60815134a8058               14 main/binary-armhf/Packages.bz2
 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855                0 main/binary-armhf/Packages
 b1bb341bb613363ca29440c2eb9c08a9289de5458209990ec502ed27711a83a2              826 main/binary-i386/Packages
 e5aaceaac5ecb59143a4b4ed2bf700fe85d6cf08addd10cf2058bde697b7b219              133 main/binary-i386/Release
 377890a26f99db55e117dfc691972dcbbb7d8be1630c8fc8297530c205377f2b              734 main/binary-i386/Packages.bz2
 6361e8efc67d2e7c1a8db45388aec0311007c0a1bd96698623ddeb5ed0bdc914              641 main/binary-i386/Packages.gz
 d3dda84eb03b9738d118eb2be78e246106900493c0ae07819ad60815134a8058               14 main/binary-powerpc/Packages.bz2
 825d493158fe0f50ca1acd70367aefa391170563af2e4ee9cedbcbe6796c8384               29 main/binary-powerpc/Packages.gz
 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855                0 main/binary-powerpc/Packages
 03b5c97a99aa799964eb5a77f8a62ad38a241b93a87eacac6cf75a270a6d417c              136 main/binary-powerpc/Release
 825d493158fe0f50ca1acd70367aefa391170563af2e4ee9cedbcbe6796c8384               29 main/debian-installer/binary-amd64/Packages.gz
 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855                0 main/debian-installer/binary-amd64/Packages
 d3dda84eb03b9738d118eb2be78e246106900493c0ae07819ad60815134a8058               14 main/debian-installer/binary-amd64/Packages.bz2
 825d493158fe0f50ca1acd70367aefa391170563af2e4ee9cedbcbe6796c8384               29 main/debian-installer/binary-armel/Packages.gz
 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855                0 main/debian-installer/binary-armel/Packages
 d3dda84eb03b9738d118eb2be78e246106900493c0ae07819ad60815134a8058               14 main/debian-installer/binary-armel/Packages.bz2
 825d493158fe0f50ca1acd70367aefa391170563af2e4ee9cedbcbe6796c8384               29 main/debian-installer/binary-armhf/Packages.gz
 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855                0 main/debian-installer/binary-armhf/Packages
 d3dda84eb03b9738d118eb2be78e246106900493c0ae07819ad60815134a8058               14 main/debian-installer/binary-armhf/Packages.bz2
 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855                0 main/debian-installer/binary-i386/Packages
 825d493158fe0f50ca1acd70367aefa391170563af2e4ee9cedbcbe6796c8384               29 main/debian-installer/binary-i386/Packages.gz
 d3dda84eb03b9738d118eb2be78e246106900493c0ae07819ad60815134a8058               14 main/debian-installer/binary-i386/Packages.bz2
 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855                0 main/debian-installer/binary-powerpc/Packages
 d3dda84eb03b9738d118eb2be78e246106900493c0ae07819ad60815134a8058               14 main/debian-installer/binary-powerpc/Packages.bz2
 825d493158fe0f50ca1acd70367aefa391170563af2e4ee9cedbcbe6796c8384               29 main/debian-installer/binary-powerpc/Packages.gz
 d683102993b6f11067ce86d73111f067e36a199e9dc1f4295c8b19c274dc9ef8              135 main/source/Release
 45f868fd5d9efe611d67572ffcf96a00a5b9ec38ea5102753290c38c36b8c282             2003 main/source/Sources
 d178f1e310218d9f0f16c37d0780637f1cf3640a94a7fb0e24dc940c51b1e115              656 main/source/Sources.bz2
 080228b550da407fb8ac73fb30b37323468fd2b2de98dd56a324ee7d701f6103              592 main/source/Sources.gz`

const examplePackagesFile = `Package: amanda-client
Source: amanda
Version: 1:3.3.1-3~bpo60+1
Installed-Size: 880
Maintainer: Bdale Garbee <bdale@gag.com>
Architecture: i386
Replaces: amanda-common (<< 1:2.5.2p1-3)
Depends: libc6 (>= 2.3), libcurl3 (>= 7.16.2-1), libglib2.0-0 (>= 2.12.0), libreadline6 (>= 6.0), libssl0.9.8 (>= 0.9.8m-1), amanda-common (= 1:3.3.1-3~bpo60+1)
Suggests: gnuplot, dump, smbclient
Conflicts: amanda, amanda-common (<< 1:2.5.2p1-3)
Description: Advanced Maryland Automatic Network Disk Archiver (Client)
Description-md5: 21af3684379a64cacc51c39152ab1062
Section: utils
Priority: optional
Filename: pool/main/a/amanda/amanda-client_3.3.1-3~bpo60+1_amd64.deb
Size: 3
MD5sum: d16fb36f0911f878998c136191af705e
SHA1: 66b27417d37e024c46526c2f6d358a754fc552f3
SHA256: 3608bca1e44ea6c4d268eb6db02260269892c0b42b86bbf1e77a6fa16c3c9282
`

const exampleSourcesFile = sourcePackageMeta