feat(test): integration test setup
This commit is contained in:
parent
53b779b801
commit
5ad46b599d
5 changed files with 49 additions and 11 deletions
|
|
@ -3,6 +3,7 @@ package handlers
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
|
@ -19,9 +20,7 @@ type createNoteCommand struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateNoteHandler struct {
|
type CreateNoteHandler struct {
|
||||||
uow repositories.UnitOfWork
|
uow repositories.UnitOfWork
|
||||||
noteRepo repositories.NoteRepository
|
|
||||||
tagRepo repositories.TagRepository
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h CreateNoteHandler) Handle(ctx context.Context, params []byte) (*rpc.Response, *rpc.Error) {
|
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)
|
return nil, h.ReturnError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.tagRepo.Upsert(ctx, tags)
|
err = h.uow.Execute(ctx, func(tx *sql.Tx) error {
|
||||||
if err != nil {
|
tagRepo := repositories.NewTagRepository(tx)
|
||||||
return nil, h.ReturnError(err)
|
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 {
|
if err != nil {
|
||||||
return nil, h.ReturnError(err)
|
return nil, h.ReturnError(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type DBContext interface {
|
type DBContext interface {
|
||||||
ExecContext(ctx context.Context, args ...any) (sql.Result, error)
|
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
|
||||||
QueryContext(ctx context.Context, args ...any) (*sql.Rows, error)
|
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
|
||||||
QueryRowContext(ctx context.Context, args ...any) *sql.Row
|
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
|
||||||
}
|
}
|
||||||
|
|
||||||
type UnitOfWork struct {
|
type UnitOfWork struct {
|
||||||
|
|
|
||||||
7
test/test_integration/create_note_handler_test.go
Normal file
7
test/test_integration/create_note_handler_test.go
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
package integration_test
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
|
||||||
|
func TestCreateNoteHandlerOnSucess(t *testing.T) {
|
||||||
|
}
|
||||||
23
test/test_integration/main_test.go
Normal file
23
test/test_integration/main_test.go
Normal file
|
|
@ -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)
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue