aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-10-18 01:30:33 +0900
committerOphestra <cat@gensokyo.uk>2025-10-18 01:30:33 +0900
commit78d7955abd29174d6266e3c81e8fb1e64a974316 (patch)
tree3e112d36926edf3421999b731a9630191ee595ee
parentb066495a7d59a0e0fc2c0935634634edff3ab286 (diff)
internal/app/sppulse: check cookie discovery
There's quite a bit of code duplication here, but since this is already quite simple it is best to leave it as is for now. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--internal/app/sppulse_test.go113
1 files changed, 113 insertions, 0 deletions
diff --git a/internal/app/sppulse_test.go b/internal/app/sppulse_test.go
index 6940f227..c6220731 100644
--- a/internal/app/sppulse_test.go
+++ b/internal/app/sppulse_test.go
@@ -241,6 +241,119 @@ func TestSpPulseOp(t *testing.T) {
})
}
+func TestDiscoverPulseCookie(t *testing.T) {
+ t.Parallel()
+
+ fCheckPathname := func(k *kstub) error {
+ a, err := discoverPulseCookie(k)
+ k.Verbose(a)
+ return err
+ }
+
+ checkSimple(t, "discoverPulseCookie", []simpleTestCase{
+ {"override notAbs", fCheckPathname, stub.Expect{Calls: []stub.Call{
+ call("lookupEnv", stub.ExpectArgs{"PULSE_COOKIE"}, "proc/nonexistent/pulse-cookie", nil),
+ call("verbose", stub.ExpectArgs{[]any{(*check.Absolute)(nil)}}, nil, nil),
+ }}, &hst.AppError{
+ Step: "locate PulseAudio cookie",
+ Err: &check.AbsoluteError{Pathname: "proc/nonexistent/pulse-cookie"},
+ }},
+
+ {"success override", fCheckPathname, stub.Expect{Calls: []stub.Call{
+ call("lookupEnv", stub.ExpectArgs{"PULSE_COOKIE"}, "/proc/nonexistent/pulse-cookie", nil),
+ call("verbose", stub.ExpectArgs{[]any{m("/proc/nonexistent/pulse-cookie")}}, nil, nil),
+ }}, nil},
+
+ {"home notAbs", fCheckPathname, stub.Expect{Calls: []stub.Call{
+ call("lookupEnv", stub.ExpectArgs{"PULSE_COOKIE"}, nil, nil),
+ call("lookupEnv", stub.ExpectArgs{"HOME"}, "proc/nonexistent/home", nil),
+ call("verbose", stub.ExpectArgs{[]any{(*check.Absolute)(nil)}}, nil, nil),
+ }}, &hst.AppError{
+ Step: "locate PulseAudio cookie",
+ Err: &check.AbsoluteError{Pathname: "proc/nonexistent/home"},
+ }},
+
+ {"home stat", fCheckPathname, stub.Expect{Calls: []stub.Call{
+ call("lookupEnv", stub.ExpectArgs{"PULSE_COOKIE"}, nil, nil),
+ call("lookupEnv", stub.ExpectArgs{"HOME"}, "/proc/nonexistent/home", nil),
+ call("stat", stub.ExpectArgs{"/proc/nonexistent/home/.pulse-cookie"}, (*stubFi)(nil), stub.UniqueError(1)),
+ call("verbose", stub.ExpectArgs{[]any{(*check.Absolute)(nil)}}, nil, nil),
+ }}, &hst.AppError{
+ Step: "access PulseAudio cookie",
+ Err: stub.UniqueError(1),
+ }},
+
+ {"home nonexistent", fCheckPathname, stub.Expect{Calls: []stub.Call{
+ call("lookupEnv", stub.ExpectArgs{"PULSE_COOKIE"}, nil, nil),
+ call("lookupEnv", stub.ExpectArgs{"HOME"}, "/proc/nonexistent/home", nil),
+ call("stat", stub.ExpectArgs{"/proc/nonexistent/home/.pulse-cookie"}, (*stubFi)(nil), os.ErrNotExist),
+ call("lookupEnv", stub.ExpectArgs{"XDG_CONFIG_HOME"}, nil, nil),
+ call("verbose", stub.ExpectArgs{[]any{(*check.Absolute)(nil)}}, nil, nil),
+ }}, nil},
+
+ {"success home", fCheckPathname, stub.Expect{Calls: []stub.Call{
+ call("lookupEnv", stub.ExpectArgs{"PULSE_COOKIE"}, nil, nil),
+ call("lookupEnv", stub.ExpectArgs{"HOME"}, "/proc/nonexistent/home", nil),
+ call("stat", stub.ExpectArgs{"/proc/nonexistent/home/.pulse-cookie"}, &stubFi{}, nil),
+ call("verbose", stub.ExpectArgs{[]any{m("/proc/nonexistent/home/.pulse-cookie")}}, nil, nil),
+ }}, nil},
+
+ {"xdg notAbs", fCheckPathname, stub.Expect{Calls: []stub.Call{
+ call("lookupEnv", stub.ExpectArgs{"PULSE_COOKIE"}, nil, nil),
+ call("lookupEnv", stub.ExpectArgs{"HOME"}, nil, nil),
+ call("lookupEnv", stub.ExpectArgs{"XDG_CONFIG_HOME"}, "proc/nonexistent/xdg", nil),
+ call("verbose", stub.ExpectArgs{[]any{(*check.Absolute)(nil)}}, nil, nil),
+ }}, &hst.AppError{
+ Step: "locate PulseAudio cookie",
+ Err: &check.AbsoluteError{Pathname: "proc/nonexistent/xdg"},
+ }},
+
+ {"xdg stat", fCheckPathname, stub.Expect{Calls: []stub.Call{
+ call("lookupEnv", stub.ExpectArgs{"PULSE_COOKIE"}, nil, nil),
+ call("lookupEnv", stub.ExpectArgs{"HOME"}, nil, nil),
+ call("lookupEnv", stub.ExpectArgs{"XDG_CONFIG_HOME"}, "/proc/nonexistent/xdg", nil),
+ call("stat", stub.ExpectArgs{"/proc/nonexistent/xdg/pulse/cookie"}, (*stubFi)(nil), stub.UniqueError(0)),
+ call("verbose", stub.ExpectArgs{[]any{(*check.Absolute)(nil)}}, nil, nil),
+ }}, &hst.AppError{
+ Step: "access PulseAudio cookie",
+ Err: stub.UniqueError(0),
+ }},
+
+ {"xdg dir", fCheckPathname, stub.Expect{Calls: []stub.Call{
+ call("lookupEnv", stub.ExpectArgs{"PULSE_COOKIE"}, nil, nil),
+ call("lookupEnv", stub.ExpectArgs{"HOME"}, nil, nil),
+ call("lookupEnv", stub.ExpectArgs{"XDG_CONFIG_HOME"}, "/proc/nonexistent/xdg", nil),
+ call("stat", stub.ExpectArgs{"/proc/nonexistent/xdg/pulse/cookie"}, &stubFi{isDir: true}, nil),
+ call("verbose", stub.ExpectArgs{[]any{(*check.Absolute)(nil)}}, nil, nil),
+ }}, nil},
+
+ {"success home dir xdg nonexistent", fCheckPathname, stub.Expect{Calls: []stub.Call{
+ call("lookupEnv", stub.ExpectArgs{"PULSE_COOKIE"}, nil, nil),
+ call("lookupEnv", stub.ExpectArgs{"HOME"}, "/proc/nonexistent/home", nil),
+ call("stat", stub.ExpectArgs{"/proc/nonexistent/home/.pulse-cookie"}, &stubFi{isDir: true}, nil),
+ call("lookupEnv", stub.ExpectArgs{"XDG_CONFIG_HOME"}, "/proc/nonexistent/xdg", nil),
+ call("stat", stub.ExpectArgs{"/proc/nonexistent/xdg/pulse/cookie"}, (*stubFi)(nil), os.ErrNotExist),
+ call("verbose", stub.ExpectArgs{[]any{(*check.Absolute)(nil)}}, nil, nil),
+ }}, nil},
+
+ {"success home nonexistent xdg", fCheckPathname, stub.Expect{Calls: []stub.Call{
+ call("lookupEnv", stub.ExpectArgs{"PULSE_COOKIE"}, nil, nil),
+ call("lookupEnv", stub.ExpectArgs{"HOME"}, "/proc/nonexistent/home", nil),
+ call("stat", stub.ExpectArgs{"/proc/nonexistent/home/.pulse-cookie"}, (*stubFi)(nil), os.ErrNotExist),
+ call("lookupEnv", stub.ExpectArgs{"XDG_CONFIG_HOME"}, "/proc/nonexistent/xdg", nil),
+ call("stat", stub.ExpectArgs{"/proc/nonexistent/xdg/pulse/cookie"}, &stubFi{}, nil),
+ call("verbose", stub.ExpectArgs{[]any{m("/proc/nonexistent/xdg/pulse/cookie")}}, nil, nil),
+ }}, nil},
+
+ {"success empty environ", fCheckPathname, stub.Expect{Calls: []stub.Call{
+ call("lookupEnv", stub.ExpectArgs{"PULSE_COOKIE"}, nil, nil),
+ call("lookupEnv", stub.ExpectArgs{"HOME"}, nil, nil),
+ call("lookupEnv", stub.ExpectArgs{"XDG_CONFIG_HOME"}, nil, nil),
+ call("verbose", stub.ExpectArgs{[]any{(*check.Absolute)(nil)}}, nil, nil),
+ }}, nil},
+ })
+}
+
func TestLoadFile(t *testing.T) {
t.Parallel()