66
63
status := <-dl.Done()
67
defer os.Remove(status.File.Name())
68
defer status.File.Close()
69
64
c.Assert(status.Err, gc.IsNil)
70
c.Assert(status.File, gc.NotNil)
72
dir, _ := filepath.Split(status.File.Name())
65
dir, _ := filepath.Split(status.Filename)
73
66
c.Assert(filepath.Clean(dir), gc.Equals, tmp)
74
assertFileContents(c, status.File, "archive")
67
assertFileContents(c, status.Filename, "archive")
77
70
func (s *DownloaderSuite) TestDownloadWithoutDisablingSSLHostnameVerification(c *gc.C) {
78
s.testDownload(c, utils.VerifySSLHostnames)
71
s.testStart(c, utils.VerifySSLHostnames)
81
74
func (s *DownloaderSuite) TestDownloadWithDisablingSSLHostnameVerification(c *gc.C) {
82
s.testDownload(c, utils.NoVerifySSLHostnames)
75
s.testStart(c, utils.NoVerifySSLHostnames)
85
func (s *DownloaderSuite) TestDownloadError(c *gc.C) {
86
gitjujutesting.Server.Response(404, nil, nil)
87
dlr := downloader.New(downloader.NewArgs{
88
HostnameVerification: utils.VerifySSLHostnames,
90
dl := dlr.Start(downloader.Request{
78
func (s *DownloaderSuite) TestDownload(c *gc.C) {
80
gitjujutesting.Server.Response(200, nil, []byte("archive"))
81
dlr := downloader.New(downloader.NewArgs{})
82
filename, err := dlr.Download(downloader.Request{
91
83
URL: s.URL(c, "/archive.tgz"),
95
c.Assert(status.File, gc.IsNil)
96
c.Assert(status.Err, gc.ErrorMatches, `cannot download ".*": bad http response: 404 Not Found`)
99
func (s *DownloaderSuite) TestStopDownload(c *gc.C) {
101
dlr := downloader.New(downloader.NewArgs{
102
HostnameVerification: utils.VerifySSLHostnames,
104
dl := dlr.Start(downloader.Request{
105
URL: s.URL(c, "/x.tgz"),
110
case status := <-dl.Done():
111
c.Fatalf("received status %#v after stop", status)
112
case <-time.After(testing.ShortWait):
114
infos, err := ioutil.ReadDir(tmp)
115
86
c.Assert(err, jc.ErrorIsNil)
116
c.Assert(infos, gc.HasLen, 0)
87
dir, _ := filepath.Split(filename)
88
c.Assert(filepath.Clean(dir), gc.Equals, tmp)
89
assertFileContents(c, filename, "archive")