feat(test): integration testing
This commit is contained in:
parent
5ad46b599d
commit
462749bbb9
4 changed files with 46 additions and 5 deletions
|
|
@ -20,7 +20,11 @@ type createNoteCommand struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateNoteHandler struct {
|
type CreateNoteHandler struct {
|
||||||
uow repositories.UnitOfWork
|
uow *repositories.UnitOfWork
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCreateNoteHandler(uow *repositories.UnitOfWork) *CreateNoteHandler {
|
||||||
|
return &CreateNoteHandler{uow: uow}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,28 @@
|
||||||
package integration_test
|
package integration_test
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/KristianJBorgwarth/dendrite.daemon/core/handlers"
|
||||||
|
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories"
|
||||||
|
"github.com/KristianJBorgwarth/dendrite.daemon/test"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
func TestCreateNoteHandlerOnSucess(t *testing.T) {
|
func TestCreateNoteHandlerOnSucess(t *testing.T) {
|
||||||
|
|
||||||
|
// Arrange
|
||||||
|
db, err := sql.Open("sqlite", test.NewTestVars().DbPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to open database: %v", err)
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
uow := repositories.NewUnitOfWork(db)
|
||||||
|
|
||||||
|
handler := handlers.NewCreateNoteHandler(uow)
|
||||||
|
|
||||||
|
// Act
|
||||||
|
|
||||||
|
// Assert
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,21 +3,23 @@ package integration_test
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/KristianJBorgwarth/dendrite.daemon/persistence"
|
"github.com/KristianJBorgwarth/dendrite.daemon/persistence"
|
||||||
|
"github.com/KristianJBorgwarth/dendrite.daemon/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
|
||||||
currentDir := os.TempDir() + "/dendrite_test_vault"
|
dbPath := test.NewTestVars().DbPath
|
||||||
|
|
||||||
err := persistence.InitializeIndex(currentDir)
|
err := persistence.InitializeIndex(dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
code := m.Run()
|
code := m.Run()
|
||||||
|
|
||||||
os.RemoveAll(currentDir)
|
os.RemoveAll(dbPath)
|
||||||
|
|
||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
test/test_vars.go
Normal file
14
test/test_vars.go
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
package test
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
|
type TestVars struct {
|
||||||
|
DbPath string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTestVars() *TestVars {
|
||||||
|
return &TestVars{
|
||||||
|
DbPath: os.TempDir() + "/dendrite_test_vault",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Add table
Reference in a new issue