Skip to content

Commit 3b76609

Browse files
Merge pull request #5 from macadmins/fix_plist_unit_test
Embed a binary plist
2 parents f80d33f + 6e3947c commit 3b76609

File tree

3 files changed

+8
-21
lines changed

3 files changed

+8
-21
lines changed
142 Bytes
Binary file not shown.

pkg/launchservices/plist.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,12 @@ func ReadPlist(path string) (Plist, error) {
5656
if err != nil {
5757
return p, err
5858
}
59-
plistFile, err := os.Open(path)
59+
data, err := os.ReadFile(path)
6060
if err != nil {
6161
return p, err
6262
}
63-
defer plistFile.Close()
6463

65-
err = plist.NewBinaryDecoder(plistFile).Decode(&p)
64+
err = plist.Unmarshal(data, &p)
6665
if err != nil {
6766
return p, err
6867
}

pkg/launchservices/plist_test.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,21 @@ import (
55
"path/filepath"
66
"testing"
77

8+
_ "embed"
9+
810
"github.com/stretchr/testify/assert"
911
)
1012

13+
//go:embed binary_data.plist
14+
var binaryplist []byte
15+
1116
func TestReadPlist(t *testing.T) {
1217
// Create a temporary file with fake plist data
1318
tmpfile, err := os.CreateTemp("", "test.plist")
1419
assert.NoError(t, err, "TempFile should not return an error")
1520
defer os.Remove(tmpfile.Name())
1621

17-
fakePlistData := `
18-
<?xml version="1.0" encoding="UTF-8"?>
19-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
20-
<plist version="1.0">
21-
<dict>
22-
<key>LSHandlers</key>
23-
<array>
24-
<dict>
25-
<key>LSHandlerContentType</key>
26-
<string>public.html</string>
27-
<key>LSHandlerRoleAll</key>
28-
<string>com.apple.safari</string>
29-
</dict>
30-
</array>
31-
</dict>
32-
</plist>
33-
`
34-
_, err = tmpfile.Write([]byte(fakePlistData))
22+
_, err = tmpfile.Write([]byte(binaryplist))
3523
assert.NoError(t, err, "Write should not return an error")
3624
err = tmpfile.Close()
3725
assert.NoError(t, err, "Close should not return an error")

0 commit comments

Comments
 (0)