From ce45c59d334a260027d563247c754f34556f67a9 Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Wed, 21 Aug 2024 17:11:32 +0200 Subject: [PATCH] added initialization test --- pkg/comms/agentserver_test.go | 22 ++++++++++++++++++++++ pkg/comms/events.go | 2 ++ 2 files changed, 24 insertions(+) diff --git a/pkg/comms/agentserver_test.go b/pkg/comms/agentserver_test.go index acf6e2b..061b897 100644 --- a/pkg/comms/agentserver_test.go +++ b/pkg/comms/agentserver_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/suite" "io" "log" + "math/rand" "net/http" "testing" "time" @@ -141,6 +142,27 @@ func (s *AgentServerTestSuite) Test_ConnectThroughYamux() { }) } +func (s *AgentServerTestSuite) Test_Initialization() { + serverTestId := rand.Int() + agentShell := "agentshell" + testsupport.RunAndWait( + &s.Suite, + func() any { + serverInfo, err := AgentInitialization(s.agentConnection, + NewEnvironmentInfo(agentShell)) + s.Nil(err) + s.Equal(serverTestId, serverInfo.TestId) + return nil + }, + func() any { + serverInfo := ServerInfo{TestId: serverTestId} + environmentInfo, err := ServerInitialization(s.serverConnection, serverInfo) + s.Nil(err) + s.Equal(agentShell, environmentInfo.Shell) + return nil + }) +} + func (s *AgentServerTestSuite) Test_ListenForAgentEvents() { } diff --git a/pkg/comms/events.go b/pkg/comms/events.go index a3f9200..cf4d88f 100644 --- a/pkg/comms/events.go +++ b/pkg/comms/events.go @@ -50,6 +50,8 @@ type ProtocolVersion struct { // initialization mesaage when agent connects to server type ServerInfo struct { + // used for testing only. + TestId int } // confirmation message when agent connects