-
Notifications
You must be signed in to change notification settings - Fork 0
/
systemuri_linux_test.go
56 lines (51 loc) · 1.33 KB
/
systemuri_linux_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
//go:build linux
package systemuri
import (
"errors"
"fmt"
"os"
"os/user"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
// TODO use https://pkg.go.dev/github.com/go-git/go-billy to mock filesystem?
func TestRegisterURLHandler(t *testing.T) {
testCases := []struct {
name string
schema string
applicationPath string
wantErr bool
}{
{
name: "Valid case",
schema: "test",
applicationPath: "/usr/bin/testapp",
wantErr: false,
},
{
name: "Invalid application path",
schema: "test",
applicationPath: "",
wantErr: true,
},
}
for _, testcase := range testCases {
t.Run(testcase.name, func(t *testing.T) {
err := registerURLHandler(testcase.name, testcase.schema, testcase.applicationPath, "--extra-env\"TEST=%s\"")
if testcase.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
usr, _ := user.Current()
xdgDataHome := os.Getenv("XDG_DATA_HOME")
if xdgDataHome == "" {
xdgDataHome = filepath.Join(usr.HomeDir, ".local", "share")
}
desktopFilePath := filepath.Join(xdgDataHome, "applications", fmt.Sprintf("%s-url-handler.desktop", testcase.schema))
_, err := os.Stat(desktopFilePath)
assert.False(t, errors.Is(err, os.ErrNotExist))
}
})
}
}