basic gobchannel tests now done.
This commit is contained in:
parent
2e8107ddbd
commit
bf837d31b2
@ -49,9 +49,7 @@ func TestAgentServerTestSuite(t *testing.T) {
|
|||||||
suite.Run(t, &AgentServerTestSuite{})
|
suite.Run(t, &AgentServerTestSuite{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AgentServerTestSuite) TestNewCommChannel() {
|
func (s *AgentServerTestSuite) createCommChannel() (CommChannel, CommChannel) {
|
||||||
|
|
||||||
// Setup Comm channel
|
|
||||||
commChannels := testsupport.RunAndWait(
|
commChannels := testsupport.RunAndWait(
|
||||||
&s.Suite,
|
&s.Suite,
|
||||||
func() any {
|
func() any {
|
||||||
@ -71,6 +69,12 @@ func (s *AgentServerTestSuite) TestNewCommChannel() {
|
|||||||
s.Equal(2, len(commChannels))
|
s.Equal(2, len(commChannels))
|
||||||
agentCommChannel := commChannels[0].(CommChannel)
|
agentCommChannel := commChannels[0].(CommChannel)
|
||||||
serverCommChannel := commChannels[1].(CommChannel)
|
serverCommChannel := commChannels[1].(CommChannel)
|
||||||
|
return agentCommChannel, serverCommChannel
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AgentServerTestSuite) TestNewCommChannel() {
|
||||||
|
// Setup Comm channel
|
||||||
|
agentCommChannel, serverCommChannel := s.createCommChannel()
|
||||||
|
|
||||||
// verify the side channel is working by sending an object
|
// verify the side channel is working by sending an object
|
||||||
testsupport.RunAndWait(
|
testsupport.RunAndWait(
|
||||||
@ -92,3 +96,11 @@ func (s *AgentServerTestSuite) TestNewCommChannel() {
|
|||||||
|
|
||||||
log.Printf("%v %v", agentCommChannel, serverCommChannel)
|
log.Printf("%v %v", agentCommChannel, serverCommChannel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *AgentServerTestSuite) Test_ListenForAgentEvents() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AgentServerTestSuite) Test_LIstenForServerEvents() {
|
||||||
|
|
||||||
|
}
|
||||||
|
94
pkg/comms/gobchannel_test.go
Normal file
94
pkg/comms/gobchannel_test.go
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
package comms
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"git.wamblee.org/converge/pkg/testsupport"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GOBChannelTestSuite struct {
|
||||||
|
suite.Suite
|
||||||
|
|
||||||
|
ctx context.Context
|
||||||
|
cancelFunc context.CancelFunc
|
||||||
|
pprofServer *http.Server
|
||||||
|
|
||||||
|
agentConnection net.Conn
|
||||||
|
serverConnection net.Conn
|
||||||
|
|
||||||
|
agentGOB GOBChannel
|
||||||
|
serverGOB GOBChannel
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GOBChannelTestSuite) SetupSuite() {
|
||||||
|
s.pprofServer = testsupport.StartPprof("")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GOBChannelTestSuite) TearDownSuite() {
|
||||||
|
testsupport.StopPprof(s.ctx, s.pprofServer)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GOBChannelTestSuite) SetupTest() {
|
||||||
|
ctx, cancelFunc := testsupport.CreateTestContext(context.Background(), 10*time.Second)
|
||||||
|
s.ctx = ctx
|
||||||
|
s.cancelFunc = cancelFunc
|
||||||
|
agentConnection, serverConnection := net.Pipe()
|
||||||
|
deadline := time.Now().Add(10 * time.Second)
|
||||||
|
agentConnection.SetDeadline(deadline)
|
||||||
|
serverConnection.SetDeadline(deadline)
|
||||||
|
s.agentConnection = agentConnection
|
||||||
|
s.serverConnection = serverConnection
|
||||||
|
s.agentGOB = NewGOBChannel(s.agentConnection)
|
||||||
|
s.serverGOB = NewGOBChannel(s.serverConnection)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GOBChannelTestSuite) TearDownTest() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNewGOBChannel(t *testing.T) {
|
||||||
|
suite.Run(t, &GOBChannelTestSuite{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GOBChannelTestSuite) Test_SendConcreteObject() {
|
||||||
|
protocol := ProtocolVersion{
|
||||||
|
Version: 10,
|
||||||
|
}
|
||||||
|
testsupport.RunAndWait(
|
||||||
|
&s.Suite,
|
||||||
|
func() any {
|
||||||
|
s.Nil(SendWithTimeout[ProtocolVersion](s.agentGOB, protocol))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
func() any {
|
||||||
|
protocol2, err := ReceiveWithTimeout[ProtocolVersion](s.serverGOB)
|
||||||
|
s.Nil(err)
|
||||||
|
s.Equal(protocol, protocol2)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GOBChannelTestSuite) Test_SendInterface() {
|
||||||
|
|
||||||
|
session := NewSessionInfo("abc", "ftp")
|
||||||
|
testsupport.RunAndWait(
|
||||||
|
&s.Suite,
|
||||||
|
func() any {
|
||||||
|
s.Nil(SendWithTimeout[ConvergeMessage](s.agentGOB,
|
||||||
|
ConvergeMessage{
|
||||||
|
Value: session,
|
||||||
|
}))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
func() any {
|
||||||
|
session2, err := ReceiveWithTimeout[ConvergeMessage](s.serverGOB)
|
||||||
|
s.Nil(err)
|
||||||
|
s.Equal(session, session2.Value)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
@ -40,7 +40,6 @@ func (rw *ChannelReadWriter) Read(p []byte) (n int, err error) {
|
|||||||
|
|
||||||
nread := copy(p, rw.readBuf)
|
nread := copy(p, rw.readBuf)
|
||||||
if nread > 0 {
|
if nread > 0 {
|
||||||
log.Printf("Read %v bytes", nread)
|
|
||||||
rw.readBuf = rw.readBuf[nread:]
|
rw.readBuf = rw.readBuf[nread:]
|
||||||
return nread, nil
|
return nread, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user