Repository navigation
Expand file tree
/
Copy pathscan_test.go
More file actions
109 lines (100 loc) 路 3.23 KB
/
Copy pathscan_test.go
File metadata and controls
109 lines (100 loc) 路 3.23 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package dash
import (
"context"
"os"
"path/filepath"
"strings"
"testing"
"github.com/itchio/lake/pools"
"github.com/itchio/lake/tlc"
)
func TestScanDirectoryIndexes(t *testing.T) {
container := &tlc.Container{
Files: []*tlc.File{
{Path: "Game/Data/level.dat"},
{Path: "Game/run.sh"},
{Path: "Game/Data/Sub/x.js"},
{Path: "Other/a.js"},
},
Dirs: []*tlc.Dir{{Path: "Game"}, {Path: "Empty/Nested"}},
}
s := newScan(ConfigureParams{}, nil, container)
if got := s.originalDir("game/data"); got != "Game/Data" {
t.Fatalf("originalDir = %q", got)
}
if got := s.originalDir("empty/nested"); got != "Empty/Nested" {
t.Fatalf("originalDir from dir entry = %q", got)
}
if got := s.originalDir("missing"); got != "missing" {
t.Fatalf("originalDir fallback = %q", got)
}
if got := s.filesInDir["game/data"]; len(got) != 1 || got[0] != 0 {
t.Fatalf("filesInDir = %v", got)
}
if got := s.filesInDir["game"]; len(got) != 1 || got[0] != 1 {
t.Fatalf("filesInDir root of game = %v", got)
}
}
func TestScanCandidateIndexFollowsAppends(t *testing.T) {
container := &tlc.Container{Files: []*tlc.File{
{Path: "App.app/Contents/MacOS/Game"},
{Path: "App.app/Contents/MacOS/Helper"},
{Path: "lib/x86_64/game"},
}}
s := newScan(ConfigureParams{}, nil, container)
first := s.addFileCandidate(0, FlavorNativeMacos, nil)
if s.candidateAt("app.app/contents/macos/game") != first {
t.Fatal("candidateAt should find the first candidate")
}
if got := s.nativesIn("app.app/contents/macos"); len(got) != 1 {
t.Fatalf("nativesIn = %d", len(got))
}
s.addFileCandidate(1, FlavorNativeMacos, nil)
s.addFileCandidate(2, FlavorNativeLinux, nil)
s.addDirCandidate("App.app", FlavorAppMacos, nil)
if got := s.nativesIn("app.app/contents/macos"); len(got) != 2 || got[0] != first {
t.Fatalf("nativesIn after append = %d", len(got))
}
if got := s.nativesUnder("app.app"); len(got) != 2 {
t.Fatalf("nativesUnder = %d", len(got))
}
if got := s.nativesUnder(""); len(got) != 4 {
t.Fatalf("nativesUnder root = %d", len(got))
}
if c := s.candidateAt("app.app"); c == nil || c.Flavor != FlavorAppMacos {
t.Fatalf("dir candidate = %+v", c)
}
}
func TestReadBundleExecutableSizeCap(t *testing.T) {
root := t.TempDir()
plist := `<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0"><dict><key>CFBundleExecutable</key><string>Game</string></dict></plist>`
big := "<plist>" + strings.Repeat("<array>", maxBundlePlistSize/7) + "</plist>"
for name, content := range map[string]string{"ok.plist": plist, "big.plist": big} {
if err := os.WriteFile(filepath.Join(root, name), []byte(content), 0o644); err != nil {
t.Fatal(err)
}
}
container, err := tlc.WalkDir(root, tlc.WalkOpts{Filter: tlc.KeepAllFilter})
if err != nil {
t.Fatal(err)
}
pool, err := pools.New(context.Background(), container, root)
if err != nil {
t.Fatal(err)
}
defer pool.Close()
for i, f := range container.Files {
exe, err := readBundleExecutable(pool, int64(i))
switch f.Path {
case "ok.plist":
if err != nil || exe != "Game" {
t.Fatalf("ok.plist: exe=%q err=%v", exe, err)
}
case "big.plist":
if err == nil || !strings.Contains(err.Error(), "exceeds") {
t.Fatalf("big.plist: expected size error, got exe=%q err=%v", exe, err)
}
}
}
}