Skip to content

Commit

Permalink
Fix unit-tests. aptly-dev#324
Browse files Browse the repository at this point in the history
  • Loading branch information
smira committed Dec 24, 2015
1 parent 631fe44 commit 7bb052a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions deb/remote_test.go
Expand Up @@ -334,7 +334,7 @@ func (s *RemoteRepoSuite) TestDownloadFlat(c *C) {
err := s.flat.Fetch(downloader, nil)
c.Assert(err, IsNil)

err = s.flat.DownloadPackageIndexes(s.progress, downloader, s.collectionFactory, false)
err = s.flat.DownloadPackageIndexes(s.progress, downloader, s.collectionFactory, true)
c.Assert(err, IsNil)
c.Assert(downloader.Empty(), Equals, true)

Expand Down Expand Up @@ -367,7 +367,7 @@ func (s *RemoteRepoSuite) TestDownloadWithSourcesFlat(c *C) {
err := s.flat.Fetch(downloader, nil)
c.Assert(err, IsNil)

err = s.flat.DownloadPackageIndexes(s.progress, downloader, s.collectionFactory, false)
err = s.flat.DownloadPackageIndexes(s.progress, downloader, s.collectionFactory, true)
c.Assert(err, IsNil)
c.Assert(downloader.Empty(), Equals, true)

Expand Down
4 changes: 4 additions & 0 deletions http/download.go
Expand Up @@ -349,5 +349,9 @@ func DownloadTryCompression(downloader aptly.Downloader, url string, expectedChe

return uncompressed, file, err
}

if err == nil {
err = fmt.Errorf("no candidates for %s found", url)
}
return nil, nil, err
}
13 changes: 9 additions & 4 deletions http/download_test.go
Expand Up @@ -257,27 +257,32 @@ func (s *DownloaderSuite) TestDownloadTryCompression(c *C) {
d = NewFakeDownloader()
d.ExpectError("http://example.com/file.bz2", &HTTPError{Code: 404})
d.ExpectResponse("http://example.com/file.gz", "x")
r, file, err = DownloadTryCompression(d, "http://example.com/file", nil, false)
r, file, err = DownloadTryCompression(d, "http://example.com/file", nil, true)
c.Assert(err, ErrorMatches, "unexpected EOF")
c.Assert(d.Empty(), Equals, true)
}

func (s *DownloaderSuite) TestDownloadTryCompressionErrors(c *C) {
d := NewFakeDownloader()
_, _, err := DownloadTryCompression(d, "http://example.com/file", nil, false)
_, _, err := DownloadTryCompression(d, "http://example.com/file", nil, true)
c.Assert(err, ErrorMatches, "unexpected request.*")

d = NewFakeDownloader()
d.ExpectError("http://example.com/file.bz2", &HTTPError{Code: 404})
d.ExpectError("http://example.com/file.gz", &HTTPError{Code: 404})
d.ExpectError("http://example.com/file", errors.New("403"))
_, _, err = DownloadTryCompression(d, "http://example.com/file", nil, false)
_, _, err = DownloadTryCompression(d, "http://example.com/file", nil, true)
c.Assert(err, ErrorMatches, "403")

d = NewFakeDownloader()
d.ExpectError("http://example.com/file.bz2", &HTTPError{Code: 404})
d.ExpectError("http://example.com/file.gz", &HTTPError{Code: 404})
d.ExpectResponse("http://example.com/file", rawData)
_, _, err = DownloadTryCompression(d, "http://example.com/file", map[string]utils.ChecksumInfo{"file": {Size: 7}}, false)
expectedChecksums := map[string]utils.ChecksumInfo{
"file.bz2": {Size: 7},
"file.gz": {Size: 7},
"file": {Size: 7},
}
_, _, err = DownloadTryCompression(d, "http://example.com/file", expectedChecksums, false)
c.Assert(err, ErrorMatches, "checksums don't match.*")
}

0 comments on commit 7bb052a

Please sign in to comment.