check / check (push) Waiting to run
Takes .golangci.yml, .dockerignore, .gitignore, .editorconfig, the workflow and REPO_POLICIES.md from sneak/prompts dd4027b, keeping this repository's own entries after the shared content. Lint (golangci-lint v2.14.0) and test become Dockerfile phases that script/lint and script/test build alone and uncached; the image build depends on both, and script/cibuild bootstraps, runs script/check, then builds the image. The agent guidance file moves to AGENTS.md. The Go code is fixed for what the new configuration finds; reads that iterate rows now also report an iteration error. Model: opus-5-5
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package server_test
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"testing"
|
|
|
|
"git.eeqj.de/sneak/routewatch/internal/config"
|
|
"git.eeqj.de/sneak/routewatch/internal/logger"
|
|
"git.eeqj.de/sneak/routewatch/internal/metrics"
|
|
"git.eeqj.de/sneak/routewatch/internal/server"
|
|
"git.eeqj.de/sneak/routewatch/internal/streamer"
|
|
)
|
|
|
|
// TestStartFailsWhenPortIsHeld holds a port with a listener of its own and
|
|
// checks that Start on that port returns an error. Before the fix Start
|
|
// listened in a goroutine, only logged the failure and returned nil, so the
|
|
// daemon kept running without its web server.
|
|
func TestStartFailsWhenPortIsHeld(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var listenConfig net.ListenConfig
|
|
|
|
held, err := listenConfig.Listen(t.Context(), "tcp", ":0")
|
|
if err != nil {
|
|
t.Fatalf("failed to open the test listener: %v", err)
|
|
}
|
|
defer func() { _ = held.Close() }()
|
|
|
|
addr, ok := held.Addr().(*net.TCPAddr)
|
|
if !ok {
|
|
t.Fatalf("test listener address %v is not a TCP address", held.Addr())
|
|
}
|
|
|
|
port := addr.Port
|
|
log := logger.New()
|
|
s := server.New(nil, streamer.New(log, metrics.New()), log,
|
|
&config.Config{Port: port})
|
|
|
|
defer func() { _ = s.Stop(context.Background()) }()
|
|
|
|
err = s.Start(t.Context())
|
|
if err == nil {
|
|
t.Fatalf("Start returned nil while port %d was held by another listener",
|
|
port)
|
|
}
|
|
}
|