-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool_search_nodes_test.go
More file actions
46 lines (40 loc) · 1.31 KB
/
Copy pathtool_search_nodes_test.go
File metadata and controls
46 lines (40 loc) · 1.31 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
package main
import (
"path/filepath"
"testing"
)
func TestToolSearchNodes_Basic(t *testing.T) {
dir := t.TempDir()
p := filepath.Join(dir, "memory.db")
bolt := p + ".bolt"
m := NewGraphManager(p, bolt)
if _, err := m.CreateEntities([]Entity{
{Name: "A", EntityType: "type1", Observations: []string{"red"}},
{Name: "B", EntityType: "type2", Observations: []string{"blue"}},
}); err != nil {
t.Fatalf("CreateEntities: %v", err)
}
if _, err := m.CreateRelations([]Relation{{From: "A", To: "B", RelationType: "likes"}}); err != nil {
t.Fatalf("CreateRelations: %v", err)
}
g, err := m.SearchNodes("type1")
if err != nil {
t.Fatalf("SearchNodes: %v", err)
}
if len(g.Entities) != 1 || g.Entities[0].Name != "A" {
t.Fatalf("unexpected search result: %#v", g)
}
if len(g.Relations) != 0 {
t.Fatalf("expected no relations for single-entity result, got %#v", g.Relations)
}
g2, err := m.SearchNodes("type")
if err != nil {
t.Fatalf("SearchNodes 2: %v", err)
}
if len(g2.Entities) != 2 {
t.Fatalf("expected 2 entities, got %d", len(g2.Entities))
}
if len(g2.Relations) != 1 {
t.Fatalf("expected 1 relation between matched nodes, got %d", len(g2.Relations))
}
}