-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool_open_nodes_test.go
More file actions
42 lines (37 loc) · 1.37 KB
/
tool_open_nodes_test.go
File metadata and controls
42 lines (37 loc) · 1.37 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
package main
import (
"path/filepath"
"testing"
)
func TestToolOpenNodes_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: "t", Observations: []string{"o1"}}, {Name: "B", EntityType: "t"}, {Name: "C", EntityType: "t"}}); err != nil {
t.Fatalf("CreateEntities: %v", err)
}
if _, err := m.CreateRelations([]Relation{{From: "A", To: "B", RelationType: "likes"}, {From: "B", To: "C", RelationType: "likes"}}); err != nil {
t.Fatalf("CreateRelations: %v", err)
}
g, err := m.OpenNodes([]string{"A", "B"})
if err != nil {
t.Fatalf("OpenNodes AB: %v", err)
}
if len(g.Entities) != 2 {
t.Fatalf("want 2 entities, got %d", len(g.Entities))
}
if len(g.Relations) != 1 || g.Relations[0].From != "A" || g.Relations[0].To != "B" {
t.Fatalf("unexpected relations among opened nodes: %#v", g.Relations)
}
g2, err := m.OpenNodes([]string{"C"})
if err != nil {
t.Fatalf("OpenNodes C: %v", err)
}
if len(g2.Entities) != 1 || g2.Entities[0].Name != "C" {
t.Fatalf("unexpected entities for C: %#v", g2.Entities)
}
if len(g2.Relations) != 0 {
t.Fatalf("expected no relations for single node C, got %#v", g2.Relations)
}
}