-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathembed_test.go
More file actions
100 lines (88 loc) · 2.31 KB
/
Copy pathembed_test.go
File metadata and controls
100 lines (88 loc) · 2.31 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
package macwifi
import (
"os"
"path/filepath"
"testing"
"testing/fstest"
)
func TestCopyEmbedTree(t *testing.T) {
src := fstest.MapFS{
"embedded/WifiScanner.app/Contents/Info.plist": {
Data: []byte("plist"),
},
"embedded/WifiScanner.app/Contents/MacOS/wifi-scanner": {
Data: []byte("#!/bin/sh\n"),
},
"embedded/WifiScanner.app/Contents/_CodeSignature/CodeResources": {
Data: []byte("signature"),
},
}
dst := filepath.Join(t.TempDir(), "WifiScanner.app")
if err := copyEmbedTree(src, scannerSourcePrefix, dst); err != nil {
t.Fatal(err)
}
assertFile(t, filepath.Join(dst, "Contents", "Info.plist"), "plist", 0o644)
assertFile(t, filepath.Join(dst, "Contents", "MacOS", "wifi-scanner"), "#!/bin/sh\n", 0o755)
assertFile(t, filepath.Join(dst, "Contents", "_CodeSignature", "CodeResources"), "signature", 0o644)
}
func TestFSTreeDigestChangesWhenContentChanges(t *testing.T) {
src := fstest.MapFS{
"embedded/WifiScanner.app/Contents/Info.plist": {
Data: []byte("one"),
},
}
changed := fstest.MapFS{
"embedded/WifiScanner.app/Contents/Info.plist": {
Data: []byte("two"),
},
}
got, err := fsTreeDigest(src, scannerSourcePrefix)
if err != nil {
t.Fatal(err)
}
gotAgain, err := fsTreeDigest(src, scannerSourcePrefix)
if err != nil {
t.Fatal(err)
}
if got != gotAgain {
t.Fatalf("fsTreeDigest() = %q, then %q; want stable digest", got, gotAgain)
}
changedDigest, err := fsTreeDigest(changed, scannerSourcePrefix)
if err != nil {
t.Fatal(err)
}
if got == changedDigest {
t.Fatalf("fsTreeDigest() = %q for different content", got)
}
}
func TestResolveAppPathUsesExistingOverride(t *testing.T) {
app := filepath.Join(t.TempDir(), "WifiScanner.app")
if err := os.Mkdir(app, 0o755); err != nil {
t.Fatal(err)
}
t.Setenv("MACWIFI_APP", app)
got, err := resolveAppPath()
if err != nil {
t.Fatal(err)
}
if got != app {
t.Fatalf("resolveAppPath() = %q, want %q", got, app)
}
}
func assertFile(t *testing.T, path, want string, wantMode os.FileMode) {
t.Helper()
got, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
if string(got) != want {
t.Fatalf("%s = %q, want %q", path, got, want)
}
info, err := os.Stat(path)
if err != nil {
t.Fatal(err)
}
if info.Mode().Perm() != wantMode {
t.Fatalf("%s mode = %o, want %o", path, info.Mode().Perm(), wantMode)
}
}