-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_test.go
More file actions
35 lines (27 loc) · 895 Bytes
/
extract_test.go
File metadata and controls
35 lines (27 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"os"
"path/filepath"
"testing"
)
func TestExtractFileDirCreationFailure(t *testing.T) {
tmp := t.TempDir()
// create a file that will act as the destination root
destFile := filepath.Join(tmp, "destfile")
if err := os.WriteFile(destFile, []byte("test"), 0644); err != nil {
t.Fatalf("setup dest file: %v", err)
}
archivePath = filepath.Join(tmp, "dummy.goxa")
if err := os.WriteFile(archivePath, []byte{}, 0644); err != nil {
t.Fatalf("setup archive: %v", err)
}
doForce = true
defer func() { doForce = false }()
item := FileEntry{Path: filepath.Join("sub", "file.txt"), Offset: 1}
f, _ := os.Open(archivePath)
defer f.Close()
_ = extractFile(f, destFile+string(os.PathSeparator), 0, compGzip, &item, &progressData{})
if _, err := os.Stat(filepath.Join(tmp, "destfile", "sub")); err == nil {
t.Fatalf("directory should not be created")
}
}