From 3cdcd12fee78f61b2b89e5d74c876663b828f802 Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Sat, 3 Oct 2026 12:27:20 +0700 Subject: [PATCH] fix --- cmd/evening_detective_server/gateway_test.go | 18 +++++++++--------- internal/app/change_password_test.go | 14 ++++++++++---- internal/modules/email_sender/sender_test.go | 2 +- .../services/scenarios_service/service_test.go | 4 +++- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/cmd/evening_detective_server/gateway_test.go b/cmd/evening_detective_server/gateway_test.go index 8e7908e..e3deee7 100644 --- a/cmd/evening_detective_server/gateway_test.go +++ b/cmd/evening_detective_server/gateway_test.go @@ -103,7 +103,7 @@ func TestGatewayDownloadTeamQR(t *testing.T) { if err != nil { t.Fatal(err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() data, err := io.ReadAll(resp.Body) if err != nil { t.Fatal(err) @@ -122,7 +122,7 @@ func TestGatewayDownloadTeamQR(t *testing.T) { if err != nil { t.Fatal(err) } - defer resp2.Body.Close() + defer func() { _ = resp2.Body.Close() }() if resp2.StatusCode != http.StatusNotFound { t.Fatalf("missing game: %d", resp2.StatusCode) } @@ -198,7 +198,7 @@ func TestGatewayUploadRawZip(t *testing.T) { if err != nil { t.Fatalf("POST: %v", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, _ := io.ReadAll(resp.Body) if resp.StatusCode != http.StatusOK { @@ -220,7 +220,7 @@ func TestGatewayDownloadZipWithContentDisposition(t *testing.T) { if err != nil { t.Fatalf("GET: %v", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, _ := io.ReadAll(resp.Body) if resp.StatusCode != http.StatusOK { @@ -247,7 +247,7 @@ func TestGatewayDownloadFileNosniff(t *testing.T) { if err != nil { t.Fatalf("GET: %v", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, _ := io.ReadAll(resp.Body) if resp.StatusCode != http.StatusOK { @@ -285,7 +285,7 @@ func TestGatewayUploadArchiveOverLimit(t *testing.T) { if err != nil { t.Fatalf("POST: %v", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, _ := io.ReadAll(resp.Body) if resp.StatusCode != http.StatusRequestEntityTooLarge { @@ -309,7 +309,7 @@ func TestGatewayUploadFileOverHTTPLimit(t *testing.T) { if err != nil { t.Fatalf("POST: %v", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, _ := io.ReadAll(resp.Body) if resp.StatusCode != http.StatusRequestEntityTooLarge { @@ -332,7 +332,7 @@ func TestGatewayUploadFileExactLimit(t *testing.T) { if err != nil { t.Fatalf("POST: %v", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, _ := io.ReadAll(resp.Body) if resp.StatusCode != http.StatusOK { @@ -354,7 +354,7 @@ func TestGatewayUploadFileResourceExhausted(t *testing.T) { if err != nil { t.Fatalf("POST: %v", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, _ := io.ReadAll(resp.Body) if resp.StatusCode != http.StatusRequestEntityTooLarge { diff --git a/internal/app/change_password_test.go b/internal/app/change_password_test.go index a62249c..ab08d9e 100644 --- a/internal/app/change_password_test.go +++ b/internal/app/change_password_test.go @@ -74,16 +74,22 @@ func TestChangeUserPasswordTransports(t *testing.T) { repo := &passwordRepo{role: "admin"} svc := users_service.NewUsersService(repo, nil, nil, nil, nil, "") listener := bufconn.Listen(1024 * 1024) - defer listener.Close() + defer func() { _ = listener.Close() }() gs := grpc.NewServer(grpc.UnaryInterceptor(processor_jwt.NewAuthorizationInterceptor(nil, jwt))) proto.RegisterEveningDetectiveServerServer(gs, &server{usersService: svc}) - go gs.Serve(listener) - defer gs.Stop() + serveErr := make(chan error, 1) + go func() { serveErr <- gs.Serve(listener) }() + defer func() { + gs.Stop() + if err := <-serveErr; err != nil && !errors.Is(err, grpc.ErrServerStopped) { + t.Errorf("gRPC server: %v", err) + } + }() conn, err := grpc.NewClient("passthrough:///test", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { return listener.Dial() })) if err != nil { t.Fatal(err) } - defer conn.Close() + defer func() { _ = conn.Close() }() mux := runtime.NewServeMux() if err := proto.RegisterEveningDetectiveServerHandler(ctx, mux, conn); err != nil { t.Fatal(err) diff --git a/internal/modules/email_sender/sender_test.go b/internal/modules/email_sender/sender_test.go index 45a7c3e..820727d 100644 --- a/internal/modules/email_sender/sender_test.go +++ b/internal/modules/email_sender/sender_test.go @@ -56,7 +56,7 @@ func startSMTPTestServer(t *testing.T, hang bool, cert tls.Certificate) (addr st // handleSMTPConn обслуживает один SMTP-диалог, достаточный для net/smtp: // EHLO, AUTH PLAIN, MAIL, RCPT, DATA, QUIT. func handleSMTPConn(conn net.Conn, messages chan<- []byte) { - defer conn.Close() + defer func() { _ = conn.Close() }() r := bufio.NewReader(conn) write := func(s string) { _, _ = conn.Write([]byte(s)) } diff --git a/internal/services/scenarios_service/service_test.go b/internal/services/scenarios_service/service_test.go index 7509bdc..5a47f53 100644 --- a/internal/services/scenarios_service/service_test.go +++ b/internal/services/scenarios_service/service_test.go @@ -929,7 +929,9 @@ func TestScenarioBackgroundLifecycle(t *testing.T) { if strings.Contains(repo.byID[id].Scenario, testDomain) { t.Fatal("stored absolute URL") } - storage.Put(ctx, &file_storage.File{Name: "room.png", Data: []byte("image")}) + if err := storage.Put(ctx, &file_storage.File{Name: "room.png", Data: []byte("image")}); err != nil { + t.Fatal(err) + } data, _, err := service.DownloadArchive(ctx, id, 7, false) if err != nil { t.Fatal(err)