package main import ( "testing" ) func TestRingBuffer(t *testing.T) { t.Run("write and read", func(t *testing.T) { rb := NewRingBuffer(10) rb.Write([]byte("hello")) got := rb.Bytes() if string(got) != "hello" { t.Errorf("got %q, want %q", got, "hello") } }) t.Run("wrap around", func(t *testing.T) { rb := NewRingBuffer(5) rb.Write([]byte("abcdefgh")) // wraps around got := rb.Bytes() if string(got) != "defgh" { t.Errorf("got %q, want %q", got, "defgh") } }) t.Run("exact size", func(t *testing.T) { rb := NewRingBuffer(5) rb.Write([]byte("abcde")) got := rb.Bytes() if string(got) != "abcde" { t.Errorf("got %q, want %q", got, "abcde") } }) t.Run("empty", func(t *testing.T) { rb := NewRingBuffer(10) got := rb.Bytes() if len(got) != 0 { t.Errorf("expected empty, got %q", got) } }) t.Run("multiple writes", func(t *testing.T) { rb := NewRingBuffer(8) rb.Write([]byte("abc")) rb.Write([]byte("def")) got := rb.Bytes() if string(got) != "abcdef" { t.Errorf("got %q, want %q", got, "abcdef") } }) t.Run("overflow multiple writes", func(t *testing.T) { rb := NewRingBuffer(5) rb.Write([]byte("abc")) rb.Write([]byte("defgh")) // total 8, buffer 5 got := rb.Bytes() if string(got) != "defgh" { t.Errorf("got %q, want %q", got, "defgh") } }) } func TestPTYSessionManager(t *testing.T) { t.Run("new manager has no sessions", func(t *testing.T) { m := &PTYSessionManager{ sessions: make(map[string]*PTYSession), stopCh: make(chan struct{}), } if len(m.sessions) != 0 { t.Error("expected empty sessions") } }) }