Added test case to catch deleting local source file when checksum doesn't match

pull/2605/head
Chris Bednarski 11 years ago
parent 424ee65866
commit 7ecfb057ff

@ -3,6 +3,7 @@ package common
import (
"crypto/md5"
"encoding/hex"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
@ -338,3 +339,40 @@ func TestHashForType(t *testing.T) {
t.Fatalf("fake hash is not nil")
}
}
func TestDownloadFileUrl(t *testing.T) {
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("Unable to detect working directory: %s", err)
}
// source_path is a file path and source is a network path
sourcePath := fmt.Sprintf("%s/test-fixtures/fileurl/%s", cwd, "cake")
source := fmt.Sprintf("file://" + sourcePath)
t.Logf("Trying to download %s", source)
config := &DownloadConfig{
Url: source,
// This should be wrong. We want to make sure we don't delete
Checksum: []byte("nope"),
Hash: HashForType("sha256"),
CopyFile: false,
}
client := NewDownloadClient(config)
filename, err := client.Get()
defer os.Remove(config.TargetPath)
if err != nil {
t.Fatalf("Failed to download test file")
}
if sourcePath != filename {
t.Errorf("Filename doesn't match; expected %s got %s", sourcePath, filename)
}
if _, err = os.Stat(sourcePath); err != nil {
t.Errorf("Could not stat source file: %s", sourcePath)
}
}

Loading…
Cancel
Save