-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathfileid_internal_test.go
More file actions
77 lines (59 loc) · 1.94 KB
/
Copy pathfileid_internal_test.go
File metadata and controls
77 lines (59 loc) · 1.94 KB
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
68
69
70
71
72
73
74
75
76
77
package xtractr
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestRememberFileHardlinks(t *testing.T) {
t.Parallel()
dir := t.TempDir()
orig := filepath.Join(dir, "orig.zip")
alias := filepath.Join(dir, "alias.zip")
require.NoError(t, os.WriteFile(orig, []byte("pk"), 0o600))
err := os.Link(orig, alias)
if err != nil {
t.Skipf("hardlinks unavailable: %v", err)
}
other := filepath.Join(dir, "other.zip")
require.NoError(t, os.WriteFile(other, []byte("pk2"), 0o600))
seen := make(map[string]struct{})
assert.True(t, rememberFile(seen, orig))
assert.False(t, rememberFile(seen, alias))
assert.True(t, rememberFile(seen, other))
}
func TestRememberFileSymlinkAliases(t *testing.T) {
t.Parallel()
dir := t.TempDir()
orig := filepath.Join(dir, "orig.zip")
require.NoError(t, os.WriteFile(orig, []byte("pk"), 0o600))
link := filepath.Join(dir, "link.zip")
err := os.Symlink(orig, link)
if err != nil {
t.Skipf("symlinks unavailable: %v", err)
}
seen := make(map[string]struct{})
assert.True(t, rememberFile(seen, orig))
assert.False(t, rememberFile(seen, link))
}
func TestExtrasAcceptSkipsRecursionAndHardlinks(t *testing.T) {
t.Parallel()
dir := t.TempDir()
orig := filepath.Join(dir, "orig.zip")
alias := filepath.Join(dir, "alias.zip")
cue := filepath.Join(dir, "copied.cue.zip")
other := filepath.Join(dir, "other.zip")
require.NoError(t, os.WriteFile(orig, []byte("pk"), 0o600))
require.NoError(t, os.WriteFile(cue, []byte("pk"), 0o600))
require.NoError(t, os.WriteFile(other, []byte("pk2"), 0o600))
err := os.Link(orig, alias)
if err != nil {
t.Skipf("hardlinks unavailable: %v", err)
}
accept := extrasAccept([]string{cue})
assert.False(t, accept(ArchiveCandidate{Path: cue}))
assert.True(t, accept(ArchiveCandidate{Path: orig}))
assert.False(t, accept(ArchiveCandidate{Path: alias}))
assert.True(t, accept(ArchiveCandidate{Path: other}))
}