check / check (push) Waiting to run
ADMIN's location and email lines come from service.AdminLines, and KillUser applies the default reason, so both transports send the same reply. The Disconnect test now allows a quarter of one write window, so a Disconnect that writes before returning fails it. QueryUserMode and UserhostReply are tested with a read that fails. The handler tests again cover USERHOST for a nick with no session, MODE +o on your own nick, and the status of a successful KILL. handleMode's comment says what it does. Model: opus-5-5
79 lines
1.6 KiB
Go
79 lines
1.6 KiB
Go
package ircserver
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"net"
|
|
"time"
|
|
|
|
"sneak.berlin/go/neoirc/internal/broker"
|
|
"sneak.berlin/go/neoirc/internal/config"
|
|
"sneak.berlin/go/neoirc/internal/db"
|
|
"sneak.berlin/go/neoirc/internal/globals"
|
|
"sneak.berlin/go/neoirc/internal/service"
|
|
)
|
|
|
|
// NewTestServer creates a Server suitable for testing.
|
|
// The caller must call Stop() when finished.
|
|
func NewTestServer(
|
|
log *slog.Logger,
|
|
cfg *config.Config,
|
|
database *db.Database,
|
|
brk *broker.Broker,
|
|
) *Server {
|
|
globs := &globals.Globals{
|
|
Appname: "neoirc",
|
|
Version: "test",
|
|
StartTime: time.Now(),
|
|
}
|
|
|
|
svc := service.NewTestService(
|
|
database, brk, cfg, globs, log,
|
|
)
|
|
|
|
return &Server{ //nolint:exhaustruct
|
|
log: log,
|
|
cfg: cfg,
|
|
database: database,
|
|
brk: brk,
|
|
svc: svc,
|
|
conns: make(map[*Conn]struct{}),
|
|
}
|
|
}
|
|
|
|
// Start exposes the unexported start method for tests.
|
|
func (s *Server) Start(addr string) error {
|
|
return s.start(context.Background(), addr)
|
|
}
|
|
|
|
// Stop exposes the unexported stop method for tests.
|
|
func (s *Server) Stop() {
|
|
s.stop()
|
|
}
|
|
|
|
// Listener returns the server's net.Listener for tests.
|
|
func (s *Server) Listener() net.Listener {
|
|
return s.listener
|
|
}
|
|
|
|
// KillWriteWindow is how long Disconnect allows each write
|
|
// to a killed victim.
|
|
const KillWriteWindow = killWriteWindow
|
|
|
|
// NewTestConn returns a Conn for nick on tcpConn, without a
|
|
// server, database or service behind it.
|
|
func NewTestConn(
|
|
log *slog.Logger,
|
|
cfg *config.Config,
|
|
tcpConn net.Conn,
|
|
nick string,
|
|
) *Conn {
|
|
conn := newConn(
|
|
context.Background(), tcpConn, log,
|
|
nil, nil, cfg, nil,
|
|
)
|
|
conn.nick = nick
|
|
|
|
return conn
|
|
}
|