forked from mholt/archiver
-
Notifications
You must be signed in to change notification settings - Fork 3
/
tar_test.go
67 lines (53 loc) · 1.77 KB
/
tar_test.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package archiver_test
import (
"io/ioutil"
"os"
"path"
"testing"
"github.com/go-vela/archiver"
)
func requireRegularFile(t *testing.T, path string) os.FileInfo {
fileInfo, err := os.Stat(path)
if err != nil {
t.Fatalf("fileInfo on '%s': %v", path, err)
}
if !fileInfo.Mode().IsRegular() {
t.Fatalf("'%s' expected to be a regular file", path)
}
return fileInfo
}
func assertSameFile(t *testing.T, f1, f2 os.FileInfo) {
if !os.SameFile(f1, f2) {
t.Errorf("expected '%s' and '%s' to be the same file", f1.Name(), f2.Name())
}
}
func TestDefaultTar_Unarchive_HardlinkSuccess(t *testing.T) {
source := "testdata/gnu-hardlinks.tar"
destination, err := ioutil.TempDir("", "archiver_tar_test")
if err != nil {
t.Fatalf("creating temp dir: %v", err)
}
defer os.RemoveAll(destination)
err = archiver.DefaultTar.Unarchive(source, destination)
if err != nil {
t.Fatalf("unarchiving '%s' to '%s': %v", source, destination, err)
}
fileaInfo := requireRegularFile(t, path.Join(destination, "dir-1", "dir-2", "file-a"))
filebInfo := requireRegularFile(t, path.Join(destination, "dir-1", "dir-2", "file-b"))
assertSameFile(t, fileaInfo, filebInfo)
}
func TestDefaultTar_Extract_HardlinkSuccess(t *testing.T) {
source := "testdata/gnu-hardlinks.tar"
destination, err := ioutil.TempDir("", "archiver_tar_test")
if err != nil {
t.Fatalf("creating temp dir: %v", err)
}
defer os.RemoveAll(destination)
err = archiver.DefaultTar.Extract(source, path.Join("dir-1", "dir-2"), destination)
if err != nil {
t.Fatalf("unarchiving '%s' to '%s': %v", source, destination, err)
}
fileaInfo := requireRegularFile(t, path.Join(destination, "dir-2", "file-a"))
filebInfo := requireRegularFile(t, path.Join(destination, "dir-2", "file-b"))
assertSameFile(t, fileaInfo, filebInfo)
}