Added second argument for custom-formatted progress-bar to NewDownloadClient in common/download_test.go. This second parameter was added as a result of commit f0bd9018f3e318caafb1fe7d46e04c470e07c092 which lets you customize the progress-bar format.

This commit is contained in:
Ali Rizvi-Santiago 2017-12-07 11:57:40 -06:00
parent 69e5eec1ce
commit 8c6efe336c
3 changed files with 17 additions and 12 deletions

View File

@ -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},

View File

@ -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

View File

@ -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