fix(quick-terminal): make host-shell PTYs durable across reloads (#2345)
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/kandev/kandev/internal/agent/loginpty"
|
||||
"github.com/kandev/kandev/internal/common/config"
|
||||
"github.com/kandev/kandev/internal/common/logger"
|
||||
"go.uber.org/goleak"
|
||||
@@ -30,6 +31,31 @@ func TestBuildHTTPServerAbortsWhenInterlockTokenGenerationFails(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildLoginPTYServicesRegistersStopAllCleanup(t *testing.T) {
|
||||
var cleanups []func() error
|
||||
loginMgr, _ := buildLoginPTYServices(testLogger(t), nil, nil, nil, func(fn func() error) {
|
||||
cleanups = append(cleanups, fn)
|
||||
})
|
||||
if len(cleanups) != 1 {
|
||||
t.Fatalf("cleanup count = %d, want 1", len(cleanups))
|
||||
}
|
||||
|
||||
sess, err := loginMgr.StartWithKey("_host_shell:tab-a", loginpty.HostShellAgentID, []string{"sh", "-c", "sleep 1"}, 80, 24)
|
||||
if err != nil {
|
||||
t.Fatalf("StartWithKey: %v", err)
|
||||
}
|
||||
t.Cleanup(func() { _ = loginMgr.StopAll() })
|
||||
if err := cleanups[0](); err != nil {
|
||||
t.Fatalf("cleanup: %v", err)
|
||||
}
|
||||
if loginMgr.GetByID(sess.ID) != nil {
|
||||
t.Fatal("cleanup returned before login session stopped")
|
||||
}
|
||||
if err := cleanups[0](); err != nil {
|
||||
t.Fatalf("second cleanup: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func testLogger(t *testing.T) *logger.Logger {
|
||||
t.Helper()
|
||||
log, err := logger.NewFromZap(zap.NewNop())
|
||||
|
||||
Reference in New Issue
Block a user