Files
go2rtc/pkg/hap/hds/hds_test.go
T
Sergey Krashevich a591186da6 test(homekit): add tests and benchmarks for HDS protocol and HKSV consumer
HDS protocol tests (15 tests, 4 benchmarks):
- Message structure for SendMediaInit and SendMediaFragment
- Multi-chunk splitting for fragments > 256KB
- Chunk boundary handling and sequence preservation
- WriteEvent/WriteResponse/WriteRequest round-trip
- opack helper functions

HKSV consumer tests (14 tests, 3 benchmarks):
- Consumer creation and field initialization
- GOP buffer flush with sequence numbering
- Activate with init segment and seqNum=2
- Activate timeout and error handling
- Stop safety (double-stop, deactivation)
- WriteTo blocking until Stop

Also fixes broken hds_test.go (undefined Client → NewConn).
2026-03-05 06:43:11 +03:00

36 lines
670 B
Go

package hds
import (
"net"
"testing"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/stretchr/testify/require"
)
func TestEncryption(t *testing.T) {
key := []byte(core.RandString(16, 0))
salt := core.RandString(32, 0)
c1, c2 := net.Pipe()
t.Cleanup(func() { c1.Close(); c2.Close() })
writer, err := NewConn(c1, key, salt, true)
require.NoError(t, err)
reader, err := NewConn(c2, key, salt, false)
require.NoError(t, err)
go func() {
n, err := writer.Write([]byte("test"))
require.NoError(t, err)
require.Equal(t, 4, n)
}()
b := make([]byte, 32)
n, err := reader.Read(b)
require.NoError(t, err)
require.Equal(t, "test", string(b[:n]))
}