refactor: fix linter warnings

This commit is contained in:
Thibault VINCENT
2026-05-02 13:43:18 +02:00
parent 26c207edea
commit 92388df185
5 changed files with 28 additions and 22 deletions
+2 -1
View File
@@ -16,5 +16,6 @@ func inodeOf(info fs.FileInfo) (uint64, bool) {
if !ok {
return 0, false
}
return uint64(st.Dev)<<32 | uint64(st.Ino), true
// Conversions kept for cross-platform: on Darwin/BSD st.Dev is int32.
return uint64(st.Dev)<<32 | uint64(st.Ino), true //nolint:unconvert
}
+1 -1
View File
@@ -80,7 +80,7 @@ func TestTimedEmitsError(t *testing.T) {
l := New(&buf, slog.LevelDebug, FormatText)
want := errors.New("boom")
got := Timed(context.Background(), l, "x", func(ctx context.Context) error { return want })
if got != want {
if !errors.Is(got, want) {
t.Fatalf("err propagation broken")
}
if !strings.Contains(buf.String(), "boom") {
+2 -1
View File
@@ -55,9 +55,10 @@ func RunPprof(ctx context.Context, srv *http.Server, logger *slog.Logger) {
}()
select {
case <-ctx.Done():
// Fresh context: parent ctx is already canceled here.
shutdownCtx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
_ = srv.Shutdown(shutdownCtx)
_ = srv.Shutdown(shutdownCtx) //nolint:contextcheck
logger.Info("pprof stopped")
case err := <-errCh:
if err != nil {
+2 -1
View File
@@ -194,9 +194,10 @@ func Run(ctx context.Context, srv *http.Server, logger *slog.Logger) error {
}()
select {
case <-ctx.Done():
// Fresh context: parent ctx is already canceled here.
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
_ = srv.Shutdown(shutdownCtx)
_ = srv.Shutdown(shutdownCtx) //nolint:contextcheck
logger.Info("http server stopped")
return ctx.Err()
case err := <-errCh:
+21 -18
View File
@@ -21,30 +21,33 @@ func TestEndpoints(t *testing.T) {
ts := httptest.NewServer(srv.Handler)
defer ts.Close()
resp, _ := http.Get(ts.URL + "/healthz")
if resp.StatusCode != 200 {
t.Fatalf("healthz: %d", resp.StatusCode)
get := func(path string) int {
resp, err := http.Get(ts.URL + path)
if err != nil {
t.Fatalf("get %s: %v", path, err)
}
defer func() { _ = resp.Body.Close() }()
return resp.StatusCode
}
resp, _ = http.Get(ts.URL + "/readyz")
if resp.StatusCode != 503 {
t.Fatalf("readyz before mark: %d", resp.StatusCode)
if got := get("/healthz"); got != 200 {
t.Fatalf("healthz: %d", got)
}
if got := get("/readyz"); got != 503 {
t.Fatalf("readyz before mark: %d", got)
}
r.Mark()
resp, _ = http.Get(ts.URL + "/readyz")
if resp.StatusCode != 200 {
t.Fatalf("readyz after mark: %d", resp.StatusCode)
if got := get("/readyz"); got != 200 {
t.Fatalf("readyz after mark: %d", got)
}
resp, _ = http.Get(ts.URL + "/metrics")
if resp.StatusCode != 200 {
t.Fatalf("metrics: %d", resp.StatusCode)
if got := get("/metrics"); got != 200 {
t.Fatalf("metrics: %d", got)
}
resp, _ = http.Get(ts.URL + "/")
if resp.StatusCode != 200 {
t.Fatalf("root: %d", resp.StatusCode)
if got := get("/"); got != 200 {
t.Fatalf("root: %d", got)
}
resp, _ = http.Get(ts.URL + "/nope")
if resp.StatusCode != 404 {
t.Fatalf("not-found: %d", resp.StatusCode)
if got := get("/nope"); got != 404 {
t.Fatalf("not-found: %d", got)
}
}