converge/pkg/support/iowrappers/inmemoryconnection.go
Erik Brakkee 3867b0432d a lot of progress in setting up tests for the communication.
Wrote ChannelReadWriter that simulates a connection inmemory.
This is used by the agentserver test for testing the initialization. The
first test is already working.
2024-08-19 22:31:02 +02:00

33 lines
904 B
Go

package iowrappers
import "context"
type InmemoryConnection struct {
ctx context.Context
frontToBack chan ([]byte)
backToFront chan ([]byte)
addr string
}
func NewInmemoryConnection(ctx context.Context, addr string) *InmemoryConnection {
pipe := InmemoryConnection{
ctx: ctx,
frontToBack: make(chan []byte),
backToFront: make(chan []byte),
addr: addr,
}
return &pipe
}
func (bitpipe *InmemoryConnection) Front() *ChannelReadWriter {
return pipe(bitpipe.ctx, bitpipe.backToFront, bitpipe.frontToBack, bitpipe.addr)
}
func (bitpipe *InmemoryConnection) Back() *ChannelReadWriter {
return pipe(bitpipe.ctx, bitpipe.frontToBack, bitpipe.backToFront, bitpipe.addr)
}
func pipe(ctx context.Context, receiveBuffer <-chan []byte, sendBuffer chan<- []byte, remoteAddr string) *ChannelReadWriter {
return NewChannelReadWriter(ctx, receiveBuffer, sendBuffer)
}