diff --git a/apps/db-adapter/internal/memgraph/mock/driver.go b/apps/db-adapter/internal/memgraph/mock/driver.go new file mode 100644 index 0000000..e705681 --- /dev/null +++ b/apps/db-adapter/internal/memgraph/mock/driver.go @@ -0,0 +1,59 @@ +package mock + +import ( + "context" + "net/url" + + "github.com/neo4j/neo4j-go-driver/v5/neo4j" + "github.com/stretchr/testify/mock" +) + +type DriverWithContext struct { + mock.Mock +} + +var _ neo4j.DriverWithContext = &DriverWithContext{} + +func (m *DriverWithContext) ExecuteQueryBookmarkManager() neo4j.BookmarkManager { + args := m.Called() + return args.Get(0).(neo4j.BookmarkManager) +} + +func (m *DriverWithContext) Target() url.URL { + args := m.Called() + return args.Get(0).(url.URL) +} + +func (m *DriverWithContext) NewSession(ctx context.Context, config neo4j.SessionConfig) neo4j.SessionWithContext { + args := m.Called(ctx, config) + return args.Get(0).(neo4j.SessionWithContext) +} + +func (m *DriverWithContext) VerifyConnectivity(ctx context.Context) error { + args := m.Called(ctx) + return args.Error(0) +} + +func (m *DriverWithContext) VerifyAuthentication(ctx context.Context, auth *neo4j.AuthToken) error { + args := m.Called(ctx, auth) + return args.Error(0) +} + +func (m *DriverWithContext) Close(ctx context.Context) error { + args := m.Called(ctx) + return args.Error(0) +} + +func (m *DriverWithContext) IsEncrypted() bool { + args := m.Called() + return args.Bool(0) +} + +func (m *DriverWithContext) GetServerInfo(ctx context.Context) (neo4j.ServerInfo, error) { + args := m.Called(ctx) + if args.Get(0) != nil { + return args.Get(0).(neo4j.ServerInfo), args.Error(1) + } + + return nil, args.Error(1) +} diff --git a/apps/db-adapter/internal/memgraph/mock/session.go b/apps/db-adapter/internal/memgraph/mock/session.go new file mode 100644 index 0000000..f3ddc61 --- /dev/null +++ b/apps/db-adapter/internal/memgraph/mock/session.go @@ -0,0 +1,115 @@ +package mock + +import ( + "context" + + "github.com/neo4j/neo4j-go-driver/v5/neo4j" + "github.com/stretchr/testify/mock" +) + +type SessionWithContext struct { + neo4j.SessionWithContext + mock.Mock +} + +var _ neo4j.SessionWithContext = &SessionWithContext{} + +func (m *SessionWithContext) LastBookmarks() neo4j.Bookmarks { + args := m.Called() + if args.Get(0) != nil { + return args.Get(0).(neo4j.Bookmarks) + } + + return nil +} + +func (m *SessionWithContext) lastBookmark() string { + args := m.Called() + if args.Get(0) != nil { + return args.String(0) + } + + return "" +} + +func (m *SessionWithContext) BeginTransaction(ctx context.Context, configurers ...func(*neo4j.TransactionConfig)) (neo4j.ExplicitTransaction, error) { + args := m.Called(ctx, configurers) + if args.Get(0) != nil { + return args.Get(0).(neo4j.ExplicitTransaction), args.Error(1) + } + + return nil, args.Error(1) +} + +func (m *SessionWithContext) ExecuteRead(ctx context.Context, work neo4j.ManagedTransactionWork, configurers ...func(*neo4j.TransactionConfig)) (any, error) { + args := m.Called(ctx, work, configurers) + if args.Get(0) != nil { + return args.Get(0), args.Error(1) + } + + return nil, args.Error(1) +} + +func (m *SessionWithContext) ExecuteWrite(ctx context.Context, work neo4j.ManagedTransactionWork, configurers ...func(*neo4j.TransactionConfig)) (any, error) { + args := m.Called(ctx, work, configurers) + if args.Get(0) != nil { + return args.Get(0), args.Error(1) + } + + return nil, args.Error(1) +} + +func (m *SessionWithContext) Run(ctx context.Context, cypher string, params map[string]any, configurers ...func(*neo4j.TransactionConfig)) (neo4j.ResultWithContext, error) { + args := m.Called(ctx, cypher, params, configurers) + if args.Get(0) != nil { + return args.Get(0).(neo4j.ResultWithContext), args.Error(1) + } + + return nil, args.Error(1) +} + +func (m *SessionWithContext) Close(ctx context.Context) error { + args := m.Called(ctx) + return args.Error(0) +} + +func (m *SessionWithContext) executeQueryRead(ctx context.Context, work neo4j.ManagedTransactionWork, configurers ...func(*neo4j.TransactionConfig)) (any, error) { + args := m.Called(ctx, work, configurers) + if args.Get(0) != nil { + return args.Get(0), args.Error(1) + } + + return nil, args.Error(1) +} + +func (m *SessionWithContext) executeQueryWrite(ctx context.Context, work neo4j.ManagedTransactionWork, configurers ...func(*neo4j.TransactionConfig)) (any, error) { + args := m.Called(ctx, work, configurers) + if args.Get(0) != nil { + return args.Get(0), args.Error(1) + } + + return nil, args.Error(1) +} + +func (m *SessionWithContext) legacy() neo4j.Session { + args := m.Called() + if args.Get(0) != nil { + return args.Get(0).(neo4j.Session) + } + + return nil +} + +func (m *SessionWithContext) getServerInfo(ctx context.Context) (neo4j.ServerInfo, error) { + args := m.Called(ctx) + if args.Get(0) != nil { + return args.Get(0).(neo4j.ServerInfo), args.Error(1) + } + + return nil, args.Error(1) +} + +func (m *SessionWithContext) verifyAuthentication(ctx context.Context) error { + args := m.Called(ctx) + return args.Error(0) +} diff --git a/apps/db-adapter/pkg/api/pointers.go b/apps/db-adapter/pkg/api/pointers.go new file mode 100644 index 0000000..27867e2 --- /dev/null +++ b/apps/db-adapter/pkg/api/pointers.go @@ -0,0 +1,41 @@ +package api + +func BoolPtr(b bool) *bool { + return &b +} + +func Float32Ptr(f float32) *float32 { + return &f +} + +func Float64Ptr(f float64) *float64 { + return &f +} + +func Int16Ptr(i int16) *int16 { + return &i +} + +func Int32Ptr(i int32) *int32 { + return &i +} + +func Int64Ptr(i int64) *int64 { + return &i +} + +func Int8Ptr(i int8) *int8 { + return &i +} + +func IntPtr(i int) *int { + return &i +} + +func StringPtr(s string) *string { + return &s +} + +func UintPtr(i uint) *uint { + return &i +}