Add client core, handshake pending frames, and in-memory Conn tests
This commit is contained in:
37
conn_test.go
Normal file
37
conn_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package ownwire_sdk_test
|
||||
|
||||
import "context"
|
||||
|
||||
// sdk_test_inmem_conn is a test-only in-memory Conn implementation.
|
||||
// It lets tests drive protocol logic deterministically without a real websocket
|
||||
// or a server.
|
||||
type sdk_test_inmem_conn struct {
|
||||
write_ch chan string
|
||||
read_ch chan string
|
||||
}
|
||||
|
||||
func sdk_test_new_inmem_conn() *sdk_test_inmem_conn {
|
||||
return &sdk_test_inmem_conn{
|
||||
write_ch: make(chan string, 16),
|
||||
read_ch: make(chan string, 16),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *sdk_test_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 *sdk_test_inmem_conn) ReadText(ctx context.Context) (string, error) {
|
||||
select {
|
||||
case s := <-c.read_ch:
|
||||
return s, nil
|
||||
case <-ctx.Done():
|
||||
return "", ctx.Err()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user