Files
shadowdaoandClaude Sonnet 5.5 962d708fdd Rename Go module paths to repo.anhonesthost.net/CyberCoveLLC/threshold
Rename root, api and sdk module paths (imports, go.mod, go_package,
ldflags, build scripts, buf configs) and regenerate protobuf/gateway
code with the project's pinned toolchain. Wire identifiers unchanged.
api gets a local replace for sdk; root/api/sdk require v0.1.0.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-12 10:33:41 -07:00

60 lines
1.7 KiB
Go

// Copyright IBM Corp. 2020, 2026
// SPDX-License-Identifier: BUSL-1.1
package session
import (
"sync"
"testing"
pbs "repo.anhonesthost.net/CyberCoveLLC/threshold/internal/gen/controller/servers/services"
"github.com/stretchr/testify/require"
)
// TestManager wraps a session manager. This wrapper allows direct manipulation of the sessions map for testing.
type TestManager struct {
*manager
}
// NewTestManager returns a wrapped session manager that allows direct manipulation of the sessions map for testing
func NewTestManager(t *testing.T, client pbs.SessionServiceClient) *TestManager {
sm, err := NewManager(client)
require.NoError(t, err)
return &TestManager{
manager: sm,
}
}
// StoreSession will mock an active local session with no connections in the session manager
func (m *TestManager) StoreSession(sessionId string) {
m.manager.sessionMap.Store(sessionId, &sess{
lock: sync.RWMutex{},
sessionId: sessionId,
connInfoMap: make(map[string]*ConnInfo),
status: pbs.SESSIONSTATUS_SESSIONSTATUS_ACTIVE,
})
}
// StoreConnection will mock a connection for the given session. The session is expected to already exist
// in the session manager.
func (m *TestManager) StoreConnection(t *testing.T, sessionId, connectionId string) {
s, ok := m.manager.sessionMap.Load(sessionId)
require.True(t, ok)
localSession := s.(*sess)
info := &ConnInfo{
Id: connectionId,
Status: pbs.CONNECTIONSTATUS_CONNECTIONSTATUS_CONNECTED,
BytesUp: func() int64 {
return 0
},
BytesDown: func() int64 {
return 0
},
}
info.connCtxCancelFunc = func() {
info.Status = pbs.CONNECTIONSTATUS_CONNECTIONSTATUS_CLOSED
}
localSession.connInfoMap[connectionId] = info
m.manager.sessionMap.Store(sessionId, localSession)
}