Skip to content

Commit

Permalink
helpers/helpers_test: init
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Sep 1, 2024
1 parent 18d5f92 commit 4998d1b
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions helpers/helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package helpers

import (
"os/user"
"testing"

"github.com/thiagokokada/hyprland-go/internal/assert"
)

func TestGetSocketWithXdg(t *testing.T) {
t.Setenv("HYPRLAND_INSTANCE_SIGNATURE", "foo")
t.Setenv("XDG_RUNTIME_DIR", "/xdg")

socket, err := GetSocket(RequestSocket)
assert.NoError(t, err)
assert.Equal(t, socket, "/xdg/hypr/foo/.socket.sock")

socket, err = GetSocket(EventSocket)
assert.NoError(t, err)
assert.Equal(t, socket, "/xdg/hypr/foo/.socket2.sock")
}

func TestGetSocketWithoutXdg(t *testing.T) {
t.Setenv("HYPRLAND_INSTANCE_SIGNATURE", "bar")
t.Setenv("XDG_RUNTIME_DIR", "")

socket, err := GetSocket(RequestSocket)
assert.NoError(t, err)
assert.Equal(t, socket, "/run/user/"+getUid(t)+"/hypr/bar/.socket.sock")

socket, err = GetSocket(EventSocket)
assert.NoError(t, err)
assert.Equal(t, socket, "/run/user/"+getUid(t)+"/hypr/bar/.socket2.sock")
}

func getUid(t *testing.T) string {
t.Helper()
u, err := user.Current()
assert.NoError(t, err)
return u.Uid
}

0 comments on commit 4998d1b

Please sign in to comment.