Skip to content

Commit fa3c441

Browse files
committed
ci: fix workflow indentation and Codecov v5; lint: errcheck fixes; tests: add config URI builder tests
1 parent 6f58b4e commit fa3c441

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

cmd/worker/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ func main() {
6969
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
7070
defer stop()
7171

72-
w.Start(ctx)
72+
if err := w.Start(ctx); err != nil && err != context.Canceled {
73+
slog.Error("Worker stopped with error", "error", err)
74+
}
7375
slog.Info("Worker stopped gracefully")
7476
}

internal/api/dashboard.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ func (h *Handler) StreamTasks(c *gin.Context) {
4949
}
5050

5151
// SSE format: "event: stats\ndata: <json>\n\n"
52-
fmt.Fprintf(c.Writer, "event: stats\ndata: %s\n\n", string(data))
52+
if _, err := fmt.Fprintf(c.Writer, "event: stats\ndata: %s\n\n", string(data)); err != nil {
53+
slog.Error("Failed to write SSE data", "error", err)
54+
continue
55+
}
5356
flusher.Flush()
5457
}
5558
}

internal/config/config_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package config
2+
3+
import "testing"
4+
5+
func TestDatabase_ToDbConnectionUri(t *testing.T) {
6+
d := Database{
7+
Username: "user",
8+
Password: "pass",
9+
Host: "localhost",
10+
Port: "5432",
11+
Database: "tasks",
12+
SSLMode: "disable",
13+
PoolMaxConns: 5,
14+
}
15+
16+
got := d.ToDbConnectionUri()
17+
want := "postgres://user:pass@localhost:5432/tasks?sslmode=disable&pool_max_conns=5"
18+
if got != want {
19+
t.Fatalf("ToDbConnectionUri() = %q, want %q", got, want)
20+
}
21+
}
22+
23+
func TestDatabase_ToMigrationUri(t *testing.T) {
24+
d := Database{
25+
Username: "user",
26+
Password: "pass",
27+
Host: "localhost",
28+
Port: "5432",
29+
Database: "tasks",
30+
SSLMode: "require",
31+
}
32+
33+
got := d.ToMigrationUri()
34+
want := "pgx5://user:pass@localhost:5432/tasks?sslmode=require"
35+
if got != want {
36+
t.Fatalf("ToMigrationUri() = %q, want %q", got, want)
37+
}
38+
}

0 commit comments

Comments
 (0)