aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pipewire/pipewire_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-12-03 01:29:19 +0900
committerOphestra <cat@gensokyo.uk>2025-12-03 01:35:43 +0900
commitc34439fc5fe52db3f346131bd6398da8a69fe0bf (patch)
tree57ae75188a59345416899c49186638e083147bc3 /internal/pipewire/pipewire_test.go
parent32fb137bb2e6eed465e94fd791abfaaab40bf674 (diff)
internal/pipewire: collect non-protocol errors
These errors are recoverable and should not terminate event handling. Only terminate event handling for protocol errors or inconsistent state that makes further event handling impossible. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pipewire/pipewire_test.go')
-rw-r--r--internal/pipewire/pipewire_test.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/internal/pipewire/pipewire_test.go b/internal/pipewire/pipewire_test.go
index 950311d6..f7df3ab1 100644
--- a/internal/pipewire/pipewire_test.go
+++ b/internal/pipewire/pipewire_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"time"
+ "hakurei.app/container/stub"
"hakurei.app/internal/pipewire"
)
@@ -862,3 +863,67 @@ func splitMessages(iovec string) (messages [][3][]byte) {
}
return
}
+
+func TestContextErrors(t *testing.T) {
+ t.Parallel()
+
+ testCases := []struct {
+ name string
+ err error
+ want string
+ }{
+ {"ProxyConsumeError invalid", pipewire.ProxyConsumeError{}, "invalid proxy consume error"},
+ {"ProxyConsumeError single", pipewire.ProxyConsumeError{
+ stub.UniqueError(0),
+ }, "unique error 0 injected by the test suite"},
+ {"ProxyConsumeError multiple", pipewire.ProxyConsumeError{
+ stub.UniqueError(1),
+ stub.UniqueError(2),
+ stub.UniqueError(3),
+ stub.UniqueError(4),
+ stub.UniqueError(5),
+ stub.UniqueError(6),
+ stub.UniqueError(7),
+ }, "unique error 1 injected by the test suite; 7 additional proxy errors occurred after this point"},
+
+ {"ProxyFatalError", &pipewire.ProxyFatalError{
+ Err: stub.UniqueError(8),
+ }, "unique error 8 injected by the test suite"},
+ {"ProxyFatalError proxy errors", &pipewire.ProxyFatalError{
+ Err: stub.UniqueError(9),
+ ProxyErrs: make([]error, 1<<4),
+ }, "unique error 9 injected by the test suite; 16 additional proxy errors occurred before this point"},
+
+ {"UnexpectedFileCountError", &pipewire.UnexpectedFileCountError{0, -1}, "received -1 files instead of the expected 0"},
+ {"UnacknowledgedProxyError", make(pipewire.UnacknowledgedProxyError, 1<<4), "server did not acknowledge 16 proxies"},
+ {"DanglingFilesError", make(pipewire.DanglingFilesError, 1<<4), "received 16 dangling files"},
+ {"UnexpectedFilesError", pipewire.UnexpectedFilesError(1 << 4), "server message headers claim to have sent more than 16 files"},
+ {"UnexpectedSequenceError", pipewire.UnexpectedSequenceError(1 << 4), "unexpected seq 16"},
+ {"UnsupportedFooterOpcodeError", pipewire.UnsupportedFooterOpcodeError(1 << 4), "unsupported footer opcode 16"},
+
+ {"RoundtripUnexpectedEOFError ErrRoundtripEOFHeader", pipewire.ErrRoundtripEOFHeader, "unexpected EOF decoding message header"},
+ {"RoundtripUnexpectedEOFError ErrRoundtripEOFBody", pipewire.ErrRoundtripEOFBody, "unexpected EOF establishing message body bounds"},
+ {"RoundtripUnexpectedEOFError ErrRoundtripEOFFooter", pipewire.ErrRoundtripEOFFooter, "unexpected EOF establishing message footer bounds"},
+ {"RoundtripUnexpectedEOFError ErrRoundtripEOFFooterOpcode", pipewire.ErrRoundtripEOFFooterOpcode, "unexpected EOF decoding message footer opcode"},
+ {"RoundtripUnexpectedEOFError invalid", pipewire.RoundtripUnexpectedEOFError(0xbad), "unexpected EOF"},
+
+ {"UnsupportedOpcodeError", &pipewire.UnsupportedOpcodeError{
+ Opcode: 0xff,
+ Interface: pipewire.PW_TYPE_INFO_INTERFACE_BASE + "Invalid",
+ }, "unsupported PipeWire:Interface:Invalid opcode 255"},
+
+ {"UnknownIdError", &pipewire.UnknownIdError{
+ Id: -1,
+ Data: "\x00",
+ }, "unknown proxy id -1"},
+ }
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ t.Parallel()
+
+ if got := tc.err.Error(); got != tc.want {
+ t.Errorf("Error: %q, want %q", got, tc.want)
+ }
+ })
+ }
+}