diff --git a/common/download.go b/common/download.go index be53dfed4..4826d1dd1 100644 --- a/common/download.go +++ b/common/download.go @@ -86,8 +86,13 @@ func HashForType(t string) hash.Hash { func NewDownloadClient(c *DownloadConfig, bar *pb.ProgressBar) *DownloadClient { const mtu = 1500 /* ethernet */ - 20 /* ipv4 */ - 20 /* tcp */ + // If no custom progress-bar was specified, then create a default one. + if bar == nil { + bar = pb.New64(0) + } + + // Create downloader map if it hasn't been specified already. if c.DownloaderMap == nil { - // Create downloader map c.DownloaderMap = map[string]Downloader{ "file": &FileDownloader{progress: bar, bufferSize: nil}, "ftp": &FTPDownloader{progress: bar, userInfo: url.UserPassword("anonymous", "anonymous@"), mtu: mtu}, diff --git a/common/download_test.go b/common/download_test.go index a62fceb96..50bdfa971 100644 --- a/common/download_test.go +++ b/common/download_test.go @@ -36,7 +36,7 @@ func TestDownloadClientVerifyChecksum(t *testing.T) { Checksum: checksum, } - d := NewDownloadClient(config) + d := NewDownloadClient(config, nil) result, err := d.VerifyChecksum(tf.Name()) if err != nil { t.Fatalf("Verify err: %s", err) @@ -59,7 +59,7 @@ func TestDownloadClient_basic(t *testing.T) { Url: ts.URL + "/basic.txt", TargetPath: tf.Name(), CopyFile: true, - }) + }, nil) path, err := client.Get() if err != nil { @@ -95,7 +95,7 @@ func TestDownloadClient_checksumBad(t *testing.T) { Hash: HashForType("md5"), Checksum: checksum, CopyFile: true, - }) + }, nil) if _, err := client.Get(); err == nil { t.Fatal("should error") } @@ -120,7 +120,7 @@ func TestDownloadClient_checksumGood(t *testing.T) { Hash: HashForType("md5"), Checksum: checksum, CopyFile: true, - }) + }, nil) path, err := client.Get() if err != nil { t.Fatalf("err: %s", err) @@ -151,7 +151,7 @@ func TestDownloadClient_checksumNoDownload(t *testing.T) { Hash: HashForType("md5"), Checksum: checksum, CopyFile: true, - }) + }, nil) path, err := client.Get() if err != nil { t.Fatalf("err: %s", err) @@ -190,7 +190,7 @@ func TestDownloadClient_resume(t *testing.T) { Url: ts.URL, TargetPath: tf.Name(), CopyFile: true, - }) + }, nil) path, err := client.Get() if err != nil { t.Fatalf("err: %s", err) @@ -250,7 +250,7 @@ func TestDownloadClient_usesDefaultUserAgent(t *testing.T) { CopyFile: true, } - client := NewDownloadClient(config) + client := NewDownloadClient(config, nil) _, err = client.Get() if err != nil { t.Fatal(err) @@ -282,7 +282,7 @@ func TestDownloadClient_setsUserAgent(t *testing.T) { CopyFile: true, } - client := NewDownloadClient(config) + client := NewDownloadClient(config, nil) _, err = client.Get() if err != nil { t.Fatal(err) @@ -381,7 +381,7 @@ func TestDownloadFileUrl(t *testing.T) { CopyFile: false, } - client := NewDownloadClient(config) + client := NewDownloadClient(config, nil) // Verify that we fail to match the checksum _, err = client.Get() @@ -412,7 +412,7 @@ func SimulateFileUriDownload(t *testing.T, uri string) (string, error) { } // go go go - client := NewDownloadClient(config) + client := NewDownloadClient(config, nil) path, err := client.Get() // ignore any non-important checksum errors if it's not a unc path diff --git a/common/step_download.go b/common/step_download.go index 2ce48cfff..a4f249290 100644 --- a/common/step_download.go +++ b/common/step_download.go @@ -96,7 +96,7 @@ func (s *StepDownload) Run(state multistep.StateBag) multistep.StepAction { } downloadConfigs[i] = config - if match, _ := NewDownloadClient(config).VerifyChecksum(config.TargetPath); match { + if match, _ := NewDownloadClient(config, nil).VerifyChecksum(config.TargetPath); match { ui.Message(fmt.Sprintf("Found already downloaded, initial checksum matched, no download needed: %s", url)) finalPath = config.TargetPath break