From 5ad46b599d4bc16282875e865ef05da6c83c1873 Mon Sep 17 00:00:00 2001 From: Kristian Borgwarth <10348902@pm.me> Date: Mon, 30 Mar 2026 00:35:50 +0200 Subject: [PATCH] feat(test): integration test setup --- core/handlers/create_note_handler.go | 24 ++++++++++++------- persistence/repositories/uow.go | 6 ++--- .../create_note_handler_test.go | 7 ++++++ test/test_integration/main_test.go | 23 ++++++++++++++++++ test/{ => test_unit}/frontmatter_test.go | 0 5 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 test/test_integration/create_note_handler_test.go create mode 100644 test/test_integration/main_test.go rename test/{ => test_unit}/frontmatter_test.go (100%) diff --git a/core/handlers/create_note_handler.go b/core/handlers/create_note_handler.go index 151406d..8a71ccb 100644 --- a/core/handlers/create_note_handler.go +++ b/core/handlers/create_note_handler.go @@ -3,6 +3,7 @@ package handlers import ( "bytes" "context" + "database/sql" "encoding/json" "os" @@ -19,9 +20,7 @@ type createNoteCommand struct { } type CreateNoteHandler struct { - uow repositories.UnitOfWork - noteRepo repositories.NoteRepository - tagRepo repositories.TagRepository + uow repositories.UnitOfWork } func (h CreateNoteHandler) Handle(ctx context.Context, params []byte) (*rpc.Response, *rpc.Error) { @@ -46,12 +45,21 @@ func (h CreateNoteHandler) Handle(ctx context.Context, params []byte) (*rpc.Resp return nil, h.ReturnError(err) } - err = h.tagRepo.Upsert(ctx, tags) - if err != nil { - return nil, h.ReturnError(err) - } + err = h.uow.Execute(ctx, func(tx *sql.Tx) error { + tagRepo := repositories.NewTagRepository(tx) + noteRepo := repositories.NewNoteRepository(tx) + + if err = tagRepo.Upsert(ctx, tags); err != nil { + return err + } + + if err = noteRepo.Upsert(ctx, cmd.Title, cmd.Path, frontmatter.Slugify(cmd.Title)); err != nil { + return err + } + + return nil + }) - err = h.noteRepo.Upsert(ctx, cmd.Title, cmd.Path, frontmatter.Slugify(cmd.Title)) if err != nil { return nil, h.ReturnError(err) } diff --git a/persistence/repositories/uow.go b/persistence/repositories/uow.go index f2802c8..4213763 100644 --- a/persistence/repositories/uow.go +++ b/persistence/repositories/uow.go @@ -6,9 +6,9 @@ import ( ) type DBContext interface { - ExecContext(ctx context.Context, args ...any) (sql.Result, error) - QueryContext(ctx context.Context, args ...any) (*sql.Rows, error) - QueryRowContext(ctx context.Context, args ...any) *sql.Row + ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) + QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) + QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row } type UnitOfWork struct { diff --git a/test/test_integration/create_note_handler_test.go b/test/test_integration/create_note_handler_test.go new file mode 100644 index 0000000..2e5e96b --- /dev/null +++ b/test/test_integration/create_note_handler_test.go @@ -0,0 +1,7 @@ +package integration_test + +import "testing" + + +func TestCreateNoteHandlerOnSucess(t *testing.T) { +} diff --git a/test/test_integration/main_test.go b/test/test_integration/main_test.go new file mode 100644 index 0000000..107c9af --- /dev/null +++ b/test/test_integration/main_test.go @@ -0,0 +1,23 @@ +package integration_test + +import ( + "os" + "testing" + "github.com/KristianJBorgwarth/dendrite.daemon/persistence" +) + +func TestMain(m *testing.M) { + + currentDir := os.TempDir() + "/dendrite_test_vault" + + err := persistence.InitializeIndex(currentDir) + if err != nil { + panic(err) + } + + code := m.Run() + + os.RemoveAll(currentDir) + + os.Exit(code) +} diff --git a/test/frontmatter_test.go b/test/test_unit/frontmatter_test.go similarity index 100% rename from test/frontmatter_test.go rename to test/test_unit/frontmatter_test.go