|
1 | 1 | package test |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "memex/pkg/types" |
| 4 | + "memex/internal/memex/core" |
5 | 5 | ) |
6 | 6 |
|
7 | | -// mockModule implements types.Module for testing |
8 | | -type mockModule struct { |
| 7 | +// MockModule implements core.Module for testing |
| 8 | +type MockModule struct { |
9 | 9 | id string |
10 | 10 | name string |
11 | 11 | description string |
12 | | - commands []types.Command |
| 12 | + commands []core.Command |
13 | 13 | initCalled bool |
14 | 14 | lastCommand string |
15 | 15 | lastArgs []string |
16 | 16 | } |
17 | 17 |
|
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 { |
19 | 28 | return m.id |
20 | 29 | } |
21 | 30 |
|
22 | | -func (m *mockModule) Name() string { |
| 31 | +func (m *MockModule) Name() string { |
23 | 32 | return m.name |
24 | 33 | } |
25 | 34 |
|
26 | | -func (m *mockModule) Description() string { |
| 35 | +func (m *MockModule) Description() string { |
27 | 36 | return m.description |
28 | 37 | } |
29 | 38 |
|
30 | | -func (m *mockModule) Init(repo types.Repository) error { |
| 39 | +func (m *MockModule) Init(repo core.Repository) error { |
31 | 40 | m.initCalled = true |
32 | 41 | return nil |
33 | 42 | } |
34 | 43 |
|
35 | | -func (m *mockModule) Commands() []types.Command { |
| 44 | +func (m *MockModule) Commands() []core.Command { |
36 | 45 | return m.commands |
37 | 46 | } |
38 | 47 |
|
39 | | -func (m *mockModule) HandleCommand(cmd string, args []string) error { |
| 48 | +func (m *MockModule) HandleCommand(cmd string, args []string) error { |
40 | 49 | m.lastCommand = cmd |
41 | 50 | m.lastArgs = args |
42 | 51 | return nil |
43 | 52 | } |
44 | 53 |
|
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 |
61 | 59 | } |
62 | 60 |
|
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), |
68 | 66 | } |
69 | 67 | } |
70 | 68 |
|
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) { |
97 | 70 | return "test-id", nil |
98 | 71 | } |
99 | 72 |
|
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 { |
101 | 74 | return nil |
102 | 75 | } |
103 | 76 |
|
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 |
106 | 79 | } |
107 | 80 |
|
108 | | -func (r *mockRepository) DeleteNode(id string) error { |
| 81 | +func (r *MockRepository) DeleteNode(id string) error { |
109 | 82 | return nil |
110 | 83 | } |
111 | 84 |
|
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 |
114 | 91 | } |
115 | 92 |
|
116 | | -func (r *mockRepository) GetContent(id string) ([]byte, error) { |
| 93 | +func (r *MockRepository) GetContent(id string) ([]byte, error) { |
117 | 94 | return nil, nil |
118 | 95 | } |
119 | 96 |
|
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 { |
121 | 98 | return nil |
122 | 99 | } |
123 | 100 |
|
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 |
126 | 103 | } |
127 | 104 |
|
128 | | -func (r *mockRepository) DeleteLink(source, target, linkType string) error { |
| 105 | +func (r *MockRepository) DeleteLink(source, target, linkType string) error { |
129 | 106 | return nil |
130 | 107 | } |
131 | 108 |
|
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)) |
134 | 111 | for _, mod := range r.modules { |
135 | 112 | modules = append(modules, mod) |
136 | 113 | } |
137 | 114 | return modules |
138 | 115 | } |
139 | 116 |
|
140 | | -func (r *mockRepository) GetModule(id string) (types.Module, bool) { |
| 117 | +func (r *MockRepository) GetModule(id string) (core.Module, bool) { |
141 | 118 | mod, exists := r.modules[id] |
142 | 119 | return mod, exists |
143 | 120 | } |
144 | 121 |
|
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 |
147 | 124 | return nil |
148 | 125 | } |
149 | 126 |
|
150 | | -func (r *mockRepository) QueryNodesByModule(moduleID string) ([]*types.Node, error) { |
| 127 | +func (r *MockRepository) QueryNodesByModule(moduleID string) ([]*core.Node, error) { |
151 | 128 | return nil, nil |
152 | 129 | } |
153 | 130 |
|
154 | | -func (r *mockRepository) QueryLinksByModule(moduleID string) ([]*types.Link, error) { |
| 131 | +func (r *MockRepository) QueryLinksByModule(moduleID string) ([]*core.Link, error) { |
155 | 132 | return nil, nil |
156 | 133 | } |
157 | 134 |
|
158 | | -func (r *mockRepository) Close() error { |
| 135 | +func (r *MockRepository) Close() error { |
159 | 136 | return nil |
160 | 137 | } |
0 commit comments