Wrote ChannelReadWriter that simulates a connection inmemory. This is used by the agentserver test for testing the initialization. The first test is already working.
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package comms
|
|
|
|
import (
|
|
"context"
|
|
"git.wamblee.org/converge/pkg/support/iowrappers"
|
|
"github.com/stretchr/testify/suite"
|
|
"log"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
type AgentServerTestSuite struct {
|
|
suite.Suite
|
|
}
|
|
|
|
func (suite *AgentServerTestSuite) SetupTest() {
|
|
}
|
|
|
|
func (suite *AgentServerTestSuite) TearDownTest() {
|
|
}
|
|
|
|
func TestAgentServerTestSuite(t *testing.T) {
|
|
suite.Run(t, &AgentServerTestSuite{})
|
|
}
|
|
|
|
func (suite *AgentServerTestSuite) TestNewCommChannel() {
|
|
bitpipe := iowrappers.NewInmemoryConnection(context.Background(), "inmemory")
|
|
agentConnection := bitpipe.Front()
|
|
serverConnection := bitpipe.Back()
|
|
requires := suite.Require()
|
|
|
|
wg := sync.WaitGroup{}
|
|
wg.Add(2)
|
|
go func() {
|
|
log.Println("Agent initializing")
|
|
commChannel, err := NewCommChannel(Agent, agentConnection)
|
|
requires.Nil(err)
|
|
protocolVersion := ProtocolVersion{Version: 10}
|
|
err = SendWithTimeout[ProtocolVersion](commChannel.SideChannel, protocolVersion)
|
|
requires.Nil(err)
|
|
log.Printf("Sent one message %v", protocolVersion)
|
|
wg.Done()
|
|
}()
|
|
|
|
go func() {
|
|
log.Println("Server initializing")
|
|
commChannel, err := NewCommChannel(ConvergeServer, serverConnection)
|
|
requires.Nil(err)
|
|
protocolVersion, err := ReceiveWithTimeout[ProtocolVersion](commChannel.SideChannel)
|
|
requires.Nil(err)
|
|
log.Printf("Received one message %v", protocolVersion)
|
|
wg.Done()
|
|
}()
|
|
wg.Wait()
|
|
|
|
}
|