Setup test logging

This commit is contained in:
2024-12-19 23:42:19 +01:00
parent cf2e1809a4
commit f0b6aa0d6e
20 changed files with 33 additions and 9 deletions

View File

@@ -5,6 +5,8 @@ import (
"os"
"testing"
"time"
_ "novamd/internal/testenv"
)
func TestDefaultConfig(t *testing.T) {

View File

@@ -6,6 +6,7 @@ import (
"time"
"novamd/internal/auth"
_ "novamd/internal/testenv"
)
func TestNewJWTService(t *testing.T) {

View File

@@ -141,7 +141,6 @@ func (m *Middleware) RequireWorkspaceAccess(next http.Handler) http.Handler {
"handler", "RequireWorkspaceAccess",
"clientIP", r.RemoteAddr,
"userId", ctx.UserID,
"workspaceId", ctx.Workspace.ID,
)
// If no workspace in context, allow the request

View File

@@ -11,6 +11,7 @@ import (
"novamd/internal/auth"
"novamd/internal/context"
"novamd/internal/models"
_ "novamd/internal/testenv"
)
// Mock SessionManager

View File

@@ -8,6 +8,7 @@ import (
"novamd/internal/auth"
"novamd/internal/models"
_ "novamd/internal/testenv"
)
// Mock SessionStore

View File

@@ -7,6 +7,7 @@ import (
"testing"
"novamd/internal/context"
_ "novamd/internal/testenv"
)
func TestGetRequestContext(t *testing.T) {

View File

@@ -9,6 +9,7 @@ import (
"novamd/internal/context"
"novamd/internal/models"
_ "novamd/internal/testenv"
)
// MockDB implements the minimal database interface needed for testing

View File

@@ -5,6 +5,8 @@ import (
"novamd/internal/db"
_ "novamd/internal/testenv"
_ "github.com/mattn/go-sqlite3"
)

View File

@@ -7,6 +7,7 @@ import (
"novamd/internal/db"
"novamd/internal/models"
_ "novamd/internal/testenv"
"github.com/google/uuid"
)

View File

@@ -9,6 +9,7 @@ import (
"novamd/internal/db"
"novamd/internal/models"
_ "novamd/internal/testenv"
"github.com/google/uuid"
)

View File

@@ -6,6 +6,7 @@ import (
"novamd/internal/db"
"novamd/internal/models"
_ "novamd/internal/testenv"
)
func TestUserOperations(t *testing.T) {

View File

@@ -1,12 +1,12 @@
package db_test
import (
"database/sql"
"strings"
"testing"
"novamd/internal/db"
"novamd/internal/models"
_ "novamd/internal/testenv"
)
func TestWorkspaceOperations(t *testing.T) {
@@ -385,8 +385,8 @@ func TestWorkspaceOperations(t *testing.T) {
// Verify workspace is gone
_, err = database.GetWorkspaceByID(workspace.ID)
if err != sql.ErrNoRows {
t.Errorf("expected sql.ErrNoRows, got %v", err)
if !strings.Contains(err.Error(), "workspace not found") {
t.Errorf("expected workspace not found, got %v", err)
}
})
}

View File

@@ -199,13 +199,8 @@ func (h *Handler) Logout(authManager auth.SessionManager, cookieService auth.Coo
// @Router /auth/refresh [post]
func (h *Handler) RefreshToken(authManager auth.SessionManager, cookieService auth.CookieManager) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx, ok := context.GetRequestContext(w, r)
if !ok {
return
}
log := getAuthLogger().With(
"handler", "RefreshToken",
"userID", ctx.UserID,
"clientIP", r.RemoteAddr,
)

View File

@@ -21,6 +21,8 @@ import (
"novamd/internal/models"
"novamd/internal/secrets"
"novamd/internal/storage"
_ "novamd/internal/testenv"
)
// testHarness encapsulates all the dependencies needed for testing

View File

@@ -6,6 +6,7 @@ import (
"testing"
"novamd/internal/secrets"
_ "novamd/internal/testenv"
)
func TestValidateKey(t *testing.T) {

View File

@@ -5,6 +5,8 @@ import (
"novamd/internal/storage"
"path/filepath"
"testing"
_ "novamd/internal/testenv"
)
// TestFileNode ensures FileNode structs are created correctly

View File

@@ -5,6 +5,8 @@ import (
"io/fs"
"path/filepath"
"time"
_ "novamd/internal/testenv"
)
type mockDirEntry struct {

View File

@@ -6,6 +6,7 @@ import (
"novamd/internal/git"
"novamd/internal/storage"
_ "novamd/internal/testenv"
)
// MockGitClient implements git.Client interface for testing

View File

@@ -7,6 +7,7 @@ import (
"testing"
"novamd/internal/storage"
_ "novamd/internal/testenv"
)
func TestValidatePath(t *testing.T) {

View File

@@ -0,0 +1,9 @@
// Package testenv provides a setup for testing the application.
package testenv
import "novamd/internal/logging"
func init() {
// Initialize the logger
logging.Setup(logging.ERROR)
}