Skip to content

Commit 4d3b1e3

Browse files
committed
add module test with core imports
1 parent 32f40ab commit 4d3b1e3

File tree

2 files changed

+113
-180
lines changed

2 files changed

+113
-180
lines changed

test/mock_module.go

Lines changed: 53 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,160 +1,137 @@
11
package test
22

33
import (
4-
"memex/pkg/types"
4+
"memex/internal/memex/core"
55
)
66

7-
// mockModule implements types.Module for testing
8-
type mockModule struct {
7+
// MockModule implements core.Module for testing
8+
type MockModule struct {
99
id string
1010
name string
1111
description string
12-
commands []types.Command
12+
commands []core.Command
1313
initCalled bool
1414
lastCommand string
1515
lastArgs []string
1616
}
1717

18-
func (m *mockModule) ID() string {
18+
func NewMockModule() *MockModule {
19+
return &MockModule{
20+
id: "mock",
21+
name: "Mock Module",
22+
description: "A mock module for testing",
23+
commands: make([]core.Command, 0),
24+
}
25+
}
26+
27+
func (m *MockModule) ID() string {
1928
return m.id
2029
}
2130

22-
func (m *mockModule) Name() string {
31+
func (m *MockModule) Name() string {
2332
return m.name
2433
}
2534

26-
func (m *mockModule) Description() string {
35+
func (m *MockModule) Description() string {
2736
return m.description
2837
}
2938

30-
func (m *mockModule) Init(repo types.Repository) error {
39+
func (m *MockModule) Init(repo core.Repository) error {
3140
m.initCalled = true
3241
return nil
3342
}
3443

35-
func (m *mockModule) Commands() []types.Command {
44+
func (m *MockModule) Commands() []core.Command {
3645
return m.commands
3746
}
3847

39-
func (m *mockModule) HandleCommand(cmd string, args []string) error {
48+
func (m *MockModule) HandleCommand(cmd string, args []string) error {
4049
m.lastCommand = cmd
4150
m.lastArgs = args
4251
return nil
4352
}
4453

45-
// mockShutdownModule extends mockModule with shutdown capability
46-
type mockShutdownModule struct {
47-
mockModule
48-
shutdownCalled bool
49-
}
50-
51-
func (m *mockShutdownModule) Shutdown() error {
52-
m.shutdownCalled = true
53-
return nil
54-
}
55-
56-
// mockRepository implements types.ModuleRepository for testing
57-
type mockRepository struct {
58-
modules map[string]types.Module
59-
loader types.ModuleLoader
60-
discovery types.ModuleDiscovery
54+
// MockRepository implements core.Repository for testing
55+
type MockRepository struct {
56+
modules map[string]core.Module
57+
nodes map[string]*core.Node
58+
links map[string][]*core.Link
6159
}
6260

63-
func newMockRepository() *mockRepository {
64-
return &mockRepository{
65-
modules: make(map[string]types.Module),
66-
loader: &mockModuleLoader{},
67-
discovery: &mockModuleDiscovery{},
61+
func NewMockRepository() *MockRepository {
62+
return &MockRepository{
63+
modules: make(map[string]core.Module),
64+
nodes: make(map[string]*core.Node),
65+
links: make(map[string][]*core.Link),
6866
}
6967
}
7068

71-
func (r *mockRepository) GetLoader() types.ModuleLoader {
72-
return r.loader
73-
}
74-
75-
func (r *mockRepository) GetDiscovery() types.ModuleDiscovery {
76-
return r.discovery
77-
}
78-
79-
// mockModuleLoader implements types.ModuleLoader for testing
80-
type mockModuleLoader struct{}
81-
82-
func (l *mockModuleLoader) AddPath(path string) {}
83-
func (l *mockModuleLoader) AddDevPath(moduleID, path string) {}
84-
func (l *mockModuleLoader) LoadModule(id string, mod types.Module) error { return nil }
85-
func (l *mockModuleLoader) UnloadModule(id string) error { return nil }
86-
func (l *mockModuleLoader) UnloadAll() error { return nil }
87-
func (l *mockModuleLoader) IsDevModule(moduleID string) bool { return false }
88-
func (l *mockModuleLoader) GetDevPath(moduleID string) (string, bool) { return "", false }
89-
90-
// mockModuleDiscovery implements types.ModuleDiscovery for testing
91-
type mockModuleDiscovery struct{}
92-
93-
func (d *mockModuleDiscovery) DiscoverModules() error { return nil }
94-
func (d *mockModuleDiscovery) ValidateModule(mod types.Module) error { return nil }
95-
96-
func (r *mockRepository) AddNode(content []byte, nodeType string, meta map[string]interface{}) (string, error) {
69+
func (r *MockRepository) AddNode(content []byte, nodeType string, meta map[string]interface{}) (string, error) {
9770
return "test-id", nil
9871
}
9972

100-
func (r *mockRepository) AddNodeWithID(id string, content []byte, nodeType string, meta map[string]interface{}) error {
73+
func (r *MockRepository) AddNodeWithID(id string, content []byte, nodeType string, meta map[string]interface{}) error {
10174
return nil
10275
}
10376

104-
func (r *mockRepository) GetNode(id string) (*types.Node, error) {
105-
return nil, nil
77+
func (r *MockRepository) GetNode(id string) (*core.Node, error) {
78+
return r.nodes[id], nil
10679
}
10780

108-
func (r *mockRepository) DeleteNode(id string) error {
81+
func (r *MockRepository) DeleteNode(id string) error {
10982
return nil
11083
}
11184

112-
func (r *mockRepository) ListNodes() ([]string, error) {
113-
return nil, nil
85+
func (r *MockRepository) ListNodes() ([]string, error) {
86+
ids := make([]string, 0, len(r.nodes))
87+
for id := range r.nodes {
88+
ids = append(ids, id)
89+
}
90+
return ids, nil
11491
}
11592

116-
func (r *mockRepository) GetContent(id string) ([]byte, error) {
93+
func (r *MockRepository) GetContent(id string) ([]byte, error) {
11794
return nil, nil
11895
}
11996

120-
func (r *mockRepository) AddLink(source, target, linkType string, meta map[string]interface{}) error {
97+
func (r *MockRepository) AddLink(source, target, linkType string, meta map[string]interface{}) error {
12198
return nil
12299
}
123100

124-
func (r *mockRepository) GetLinks(nodeID string) ([]*types.Link, error) {
125-
return nil, nil
101+
func (r *MockRepository) GetLinks(nodeID string) ([]*core.Link, error) {
102+
return r.links[nodeID], nil
126103
}
127104

128-
func (r *mockRepository) DeleteLink(source, target, linkType string) error {
105+
func (r *MockRepository) DeleteLink(source, target, linkType string) error {
129106
return nil
130107
}
131108

132-
func (r *mockRepository) ListModules() []types.Module {
133-
modules := make([]types.Module, 0, len(r.modules))
109+
func (r *MockRepository) ListModules() []core.Module {
110+
modules := make([]core.Module, 0, len(r.modules))
134111
for _, mod := range r.modules {
135112
modules = append(modules, mod)
136113
}
137114
return modules
138115
}
139116

140-
func (r *mockRepository) GetModule(id string) (types.Module, bool) {
117+
func (r *MockRepository) GetModule(id string) (core.Module, bool) {
141118
mod, exists := r.modules[id]
142119
return mod, exists
143120
}
144121

145-
func (r *mockRepository) RegisterModule(module types.Module) error {
146-
r.modules[module.ID()] = module
122+
func (r *MockRepository) RegisterModule(m core.Module) error {
123+
r.modules[m.ID()] = m
147124
return nil
148125
}
149126

150-
func (r *mockRepository) QueryNodesByModule(moduleID string) ([]*types.Node, error) {
127+
func (r *MockRepository) QueryNodesByModule(moduleID string) ([]*core.Node, error) {
151128
return nil, nil
152129
}
153130

154-
func (r *mockRepository) QueryLinksByModule(moduleID string) ([]*types.Link, error) {
131+
func (r *MockRepository) QueryLinksByModule(moduleID string) ([]*core.Link, error) {
155132
return nil, nil
156133
}
157134

158-
func (r *mockRepository) Close() error {
135+
func (r *MockRepository) Close() error {
159136
return nil
160137
}

0 commit comments

Comments
 (0)