Ensure adding a broken tar doesn't silently fail

Signed-off-by: Aidan Hobson Sayers <aidanhs@cantab.net>
This commit is contained in:
Aidan Hobson Sayers 2015-11-20 16:49:33 +00:00
parent 688bb55544
commit 12fc11efd0
2 changed files with 64 additions and 5 deletions

View file

@ -49,6 +49,45 @@ func TestIsArchive7zip(t *testing.T) {
}
}
func TestIsArchivePathDir(t *testing.T) {
cmd := exec.Command("/bin/sh", "-c", "mkdir -p /tmp/archivedir")
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("Fail to create an archive file for test : %s.", output)
}
if IsArchivePath("/tmp/archivedir") {
t.Fatalf("Incorrectly recognised directory as an archive")
}
}
func TestIsArchivePathInvalidFile(t *testing.T) {
cmd := exec.Command("/bin/sh", "-c", "dd if=/dev/zero bs=1K count=1 of=/tmp/archive && gzip --stdout /tmp/archive > /tmp/archive.gz")
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("Fail to create an archive file for test : %s.", output)
}
if IsArchivePath("/tmp/archive") {
t.Fatalf("Incorrectly recognised invalid tar path as archive")
}
if IsArchivePath("/tmp/archive.gz") {
t.Fatalf("Incorrectly recognised invalid compressed tar path as archive")
}
}
func TestIsArchivePathTar(t *testing.T) {
cmd := exec.Command("/bin/sh", "-c", "touch /tmp/archivedata && tar -cf /tmp/archive /tmp/archivedata && gzip --stdout /tmp/archive > /tmp/archive.gz")
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("Fail to create an archive file for test : %s.", output)
}
if !IsArchivePath("/tmp/archive") {
t.Fatalf("Did not recognise valid tar path as archive")
}
if !IsArchivePath("/tmp/archive.gz") {
t.Fatalf("Did not recognise valid compressed tar path as archive")
}
}
func TestDecompressStreamGzip(t *testing.T) {
cmd := exec.Command("/bin/sh", "-c", "touch /tmp/archive && gzip -f /tmp/archive")
output, err := cmd.CombinedOutput()