-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain_test.go
More file actions
64 lines (56 loc) · 1.67 KB
/
main_test.go
File metadata and controls
64 lines (56 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"os"
"path/filepath"
"sort"
"testing"
"memory-mcp-server-go/storage"
)
func TestAddObservationsDuplicateEntity(t *testing.T) {
// Setup: create a KnowledgeGraphManager with temp SQLite storage
tempDir, err := os.MkdirTemp("", "add_obs_dedup_test")
if err != nil {
t.Fatalf("Failed to create temp dir: %v", err)
}
defer os.RemoveAll(tempDir)
dbPath := filepath.Join(tempDir, "test.db")
mgr, err := NewKnowledgeGraphManager(dbPath, "sqlite", false)
if err != nil {
t.Fatalf("Failed to create manager: %v", err)
}
defer mgr.Close()
// Create the entity first
_, err = mgr.CreateEntities([]storage.Entity{{
Name: "TestEntity",
EntityType: "test",
}})
if err != nil {
t.Fatalf("Failed to create entity: %v", err)
}
// Call AddObservations with TWO entries for the same entity
results, err := mgr.AddObservations([]ObservationAddition{
{EntityName: "TestEntity", Contents: []string{"obs-a", "obs-b"}},
{EntityName: "TestEntity", Contents: []string{"obs-c", "obs-d"}},
})
if err != nil {
t.Fatalf("AddObservations failed: %v", err)
}
// Collect all added observations across results
var allAdded []string
for _, r := range results {
if r.EntityName == "TestEntity" {
allAdded = append(allAdded, r.AddedObservations...)
}
}
// All four observations must be present
sort.Strings(allAdded)
expected := []string{"obs-a", "obs-b", "obs-c", "obs-d"}
if len(allAdded) != len(expected) {
t.Fatalf("Expected %d observations added, got %d: %v", len(expected), len(allAdded), allAdded)
}
for i, exp := range expected {
if allAdded[i] != exp {
t.Errorf("Observation[%d]: expected %q, got %q", i, exp, allAdded[i])
}
}
}