Implemented conn.go and hanshake.go + unit tests

This commit is contained in:
robert
2026-01-04 20:24:15 +00:00
parent e98625ef58
commit 786533bbfc
4 changed files with 304 additions and 0 deletions

44
conn_inmem_test.go Normal file
View File

@@ -0,0 +1,44 @@
// This file defines an in-memory implementation of the Conn interface that is
// used ONLY by unit tests.
//
// The inmem_conn replaces a real WebSocket or network connection with simple
// Go channels. This allows handshake, sequencing, and message logic to be
// tested deterministically without spinning up a server, opening sockets,
// or relying on timing.
package ownwire_sdk
import (
"context"
)
type inmem_conn struct {
write_ch chan string
read_ch chan string
}
func new_inmem_conn() *inmem_conn {
return &inmem_conn{
write_ch: make(chan string, 16),
read_ch: make(chan string, 16),
}
}
func (c *inmem_conn) WriteText(ctx context.Context, s string) error {
select {
case c.write_ch <- s:
return nil
case <-ctx.Done():
return ctx.Err()
}
}
func (c *inmem_conn) ReadText(ctx context.Context) (string, error) {
select {
case s := <-c.read_ch:
return s, nil
case <-ctx.Done():
return "", ctx.Err()
}
}