* refactor(worker): Move tcp_proxy into its own package This refactors: - the tcp_proxy.go into worker/proxy/tcp - add a missing unit test for the HandleTcpProxyV1 - refactors session.go into worker/session, needed to avoid import cycle - adds a baseline for a mock controller session client - go lint fixes * Add sleep between spinning listener goroutine and dialing Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package worker
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
pbs "github.com/hashicorp/boundary/internal/gen/controller/servers/services"
|
|
"github.com/hashicorp/boundary/internal/servers/worker/session"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestTestWorkerLookupSession(t *testing.T) {
|
|
require := require.New(t)
|
|
// This loads the golang reference time, see those docs for more details. We
|
|
// just use this as a stable non-zero time.
|
|
refTime, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05+07:00")
|
|
require.NoError(err)
|
|
|
|
tw := new(TestWorker)
|
|
tw.w = &Worker{
|
|
sessionInfoMap: new(sync.Map),
|
|
}
|
|
tw.w.sessionInfoMap.Store("foo", &session.Info{
|
|
Id: "foo",
|
|
Status: pbs.SESSIONSTATUS_SESSIONSTATUS_ACTIVE,
|
|
ConnInfoMap: map[string]*session.ConnInfo{
|
|
"one": {
|
|
Id: "one",
|
|
Status: pbs.CONNECTIONSTATUS_CONNECTIONSTATUS_CLOSED,
|
|
CloseTime: refTime,
|
|
},
|
|
},
|
|
})
|
|
|
|
expected := TestSessionInfo{
|
|
Id: "foo",
|
|
Status: pbs.SESSIONSTATUS_SESSIONSTATUS_ACTIVE,
|
|
Connections: map[string]TestConnectionInfo{
|
|
"one": {
|
|
Id: "one",
|
|
Status: pbs.CONNECTIONSTATUS_CONNECTIONSTATUS_CLOSED,
|
|
CloseTime: refTime,
|
|
},
|
|
},
|
|
}
|
|
|
|
actual, ok := tw.LookupSession("foo")
|
|
require.True(ok)
|
|
require.Equal(expected, actual)
|
|
}
|
|
|
|
func TestTestWorkerLookupSessionMissing(t *testing.T) {
|
|
require := require.New(t)
|
|
tw := new(TestWorker)
|
|
tw.w = &Worker{
|
|
sessionInfoMap: new(sync.Map),
|
|
}
|
|
actual, ok := tw.LookupSession("missing")
|
|
require.False(ok)
|
|
require.Equal(TestSessionInfo{}, actual)
|
|
}
|