mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
94b49818a1
* Drop multi-threaded downloader. It doesn't really belong here - some places require it, some do not, but it's definitely not the right place to handle it, as it's being used only when updating mirrors * Pass expectedChecksums as pointer, so it's easy to drive `nil` value, and also downloader can fill back checksums (not implemented right now). * Break down downloader and tests into more files * Use pkg/errors instead of fmt
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package http
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/smira/aptly/utils"
|
|
|
|
. "gopkg.in/check.v1"
|
|
)
|
|
|
|
type TempSuite struct {
|
|
DownloaderSuiteBase
|
|
}
|
|
|
|
var _ = Suite(&TempSuite{})
|
|
|
|
func (s *TempSuite) SetUpTest(c *C) {
|
|
s.DownloaderSuiteBase.SetUpTest(c)
|
|
}
|
|
|
|
func (s *TempSuite) TearDownTest(c *C) {
|
|
s.DownloaderSuiteBase.TearDownTest(c)
|
|
}
|
|
|
|
func (s *TempSuite) TestDownloadTemp(c *C) {
|
|
f, err := DownloadTemp(s.d, s.url+"/test")
|
|
c.Assert(err, IsNil)
|
|
defer f.Close()
|
|
|
|
buf := make([]byte, 1)
|
|
|
|
f.Read(buf)
|
|
c.Assert(buf, DeepEquals, []byte("H"))
|
|
|
|
_, err = os.Stat(f.Name())
|
|
c.Assert(os.IsNotExist(err), Equals, true)
|
|
}
|
|
|
|
func (s *TempSuite) TestDownloadTempWithChecksum(c *C) {
|
|
f, err := DownloadTempWithChecksum(s.d, s.url+"/test", &utils.ChecksumInfo{Size: 12, MD5: "a1acb0fe91c7db45ec4d775192ec5738",
|
|
SHA1: "921893bae6ad6fd818401875d6779254ef0ff0ec", SHA256: "b3c92ee1246176ed35f6e8463cd49074f29442f5bbffc3f8591cde1dcc849dac"}, false, 1)
|
|
defer f.Close()
|
|
c.Assert(err, IsNil)
|
|
|
|
_, err = DownloadTempWithChecksum(s.d, s.url+"/test", &utils.ChecksumInfo{Size: 13}, false, 1)
|
|
c.Assert(err, ErrorMatches, ".*size check mismatch 12 != 13")
|
|
}
|
|
|
|
func (s *TempSuite) TestDownloadTempError(c *C) {
|
|
f, err := DownloadTemp(s.d, s.url+"/doesntexist")
|
|
c.Assert(err, NotNil)
|
|
c.Assert(f, IsNil)
|
|
c.Assert(err, ErrorMatches, "HTTP code 404.*")
|
|
}
|