Refactor Downloader: it accepts channel, not generates it.

This commit is contained in:
Andrey Smirnov
2013-12-18 12:56:30 +04:00
parent 055c38a4d9
commit e738ac7ed8
3 changed files with 23 additions and 20 deletions
+12 -4
View File
@@ -48,32 +48,40 @@ func (s *DownloaderSuite) TestStartupShutdown(c *C) {
func (s *DownloaderSuite) TestDownloadOK(c *C) {
d := NewDownloader(2)
defer d.Shutdown()
ch := make(chan error)
res := <-d.Download("http://smira.ru/", s.tempfile.Name())
d.Download("http://smira.ru/", s.tempfile.Name(), ch)
res := <-ch
c.Assert(res, IsNil)
}
func (s *DownloaderSuite) TestDownload404(c *C) {
d := NewDownloader(2)
defer d.Shutdown()
ch := make(chan error)
res := <-d.Download("http://smira.ru/doesntexist", s.tempfile.Name())
d.Download("http://smira.ru/doesntexist", s.tempfile.Name(), ch)
res := <-ch
c.Assert(res, ErrorMatches, "HTTP code 404.*")
}
func (s *DownloaderSuite) TestDownloadConnectError(c *C) {
d := NewDownloader(2)
defer d.Shutdown()
ch := make(chan error)
res := <-d.Download("http://nosuch.smira.ru/", s.tempfile.Name())
d.Download("http://nosuch.smira.ru/", s.tempfile.Name(), ch)
res := <-ch
c.Assert(res, ErrorMatches, ".*no such host")
}
func (s *DownloaderSuite) TestDownloadFileError(c *C) {
d := NewDownloader(2)
defer d.Shutdown()
ch := make(chan error)
res := <-d.Download("http://smira.ru/", "/")
d.Download("http://smira.ru/", "/", ch)
res := <-ch
c.Assert(res, ErrorMatches, ".*permission denied")
}