test: reduce amount of logs print on `go test -v`

Andrey Nering created

Change summary

internal/agent/agent_test.go | 6 ++++++
internal/db/connect.go       | 5 +++++
2 files changed, 11 insertions(+)

Detailed changes

internal/agent/agent_test.go 🔗

@@ -2,6 +2,7 @@ package agent
 
 import (
 	"fmt"
+	"log/slog"
 	"os"
 	"path/filepath"
 	"runtime"
@@ -19,6 +20,11 @@ import (
 	_ "github.com/joho/godotenv/autoload"
 )
 
+func TestMain(m *testing.M) {
+	slog.SetLogLoggerLevel(slog.LevelError)
+	m.Run()
+}
+
 var modelPairs = []modelPair{
 	{"anthropic-sonnet", anthropicBuilder("claude-sonnet-4-6"), anthropicBuilder("claude-haiku-4-5-20251001")},
 	{"openai-gpt-5", openaiBuilder("gpt-5"), openaiBuilder("gpt-4o")},

internal/db/connect.go 🔗

@@ -6,6 +6,7 @@ import (
 	"fmt"
 	"log/slog"
 	"path/filepath"
+	"testing"
 
 	"github.com/pressly/goose/v3"
 )
@@ -39,6 +40,10 @@ func Connect(ctx context.Context, dataDir string) (*sql.DB, error) {
 
 	goose.SetBaseFS(FS)
 
+	if testing.Testing() {
+		goose.SetLogger(goose.NopLogger())
+	}
+
 	if err := goose.SetDialect("sqlite3"); err != nil {
 		slog.Error("Failed to set dialect", "error", err)
 		return nil, fmt.Errorf("failed to set dialect: %w", err)