-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinsert_test.go
98 lines (84 loc) · 3.28 KB
/
insert_test.go
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package util
import (
"fmt"
"testing"
"github.com/bmeg/grip/gdbi"
multierror "github.com/hashicorp/go-multierror"
)
func TestBatchInsertValidation(t *testing.T) {
elems := []*gdbi.GraphElement{
{Graph: "graph", Vertex: &gdbi.Vertex{ID: "v1", Label: "test"}},
{Graph: "graph", Vertex: &gdbi.Vertex{ID: "v2", Label: "test"}},
{Graph: "graph", Vertex: &gdbi.Vertex{ID: "v3", Label: "test"}},
{Graph: "graph", Vertex: &gdbi.Vertex{ID: "v4", Label: "test"}},
{Graph: "graph", Vertex: &gdbi.Vertex{ID: "v5", Label: "test"}},
{Graph: "graph", Vertex: &gdbi.Vertex{ID: "v6", Label: "test"}},
{Graph: "graph", Vertex: &gdbi.Vertex{ID: "v7", Label: "test"}},
{Graph: "graph", Edge: &gdbi.Edge{ID: "e1", Label: "test", From: "v1", To: "v2"}},
{Graph: "graph", Edge: &gdbi.Edge{ID: "e2", Label: "test", From: "v2", To: "v1"}},
{Graph: "graph", Edge: &gdbi.Edge{ID: "e3", Label: "test", From: "v3", To: "v1"}},
{Graph: "graph", Edge: &gdbi.Edge{ID: "e4", Label: "test", From: "v4", To: "v3"}},
{Graph: "graph", Edge: &gdbi.Edge{ID: "e5", Label: "test", From: "v5", To: "v3"}},
{Graph: "graph", Edge: &gdbi.Edge{ID: "e6", Label: "test", From: "v6", To: "v1"}},
{Graph: "graph", Edge: &gdbi.Edge{ID: "e7", Label: "test", From: "v7", To: "v2"}},
{Graph: "graph", Edge: &gdbi.Edge{ID: "e8", Label: "test", From: "v1", To: "v7"}},
}
vAdd := func([]*gdbi.Vertex) error {
return nil
}
eAdd := func([]*gdbi.Edge) error {
return nil
}
i := make(chan *gdbi.GraphElement)
go func() {
for _, e := range elems {
i <- e
}
close(i)
}()
err := StreamBatch(i, 5, "graph", vAdd, eAdd)
if err != nil {
t.Error(err)
}
}
func TestBatchGraphValidation(t *testing.T) {
elems := []*gdbi.GraphElement{
{Graph: "graph1", Vertex: &gdbi.Vertex{ID: "v1", Label: "test"}},
{Graph: "graph", Vertex: &gdbi.Vertex{Label: "test"}},
{Graph: "graph", Vertex: &gdbi.Vertex{ID: "v3"}},
{Graph: "graph", Vertex: &gdbi.Vertex{ID: "v4", Label: "test"}},
{Graph: "graph", Vertex: &gdbi.Vertex{ID: "v5", Label: "test"}},
{Graph: "graph", Vertex: &gdbi.Vertex{ID: "v6", Label: "test"}},
{Graph: "graph", Vertex: &gdbi.Vertex{ID: "v7", Label: "test"}},
{Graph: "graph1", Edge: &gdbi.Edge{ID: "e1", Label: "test", From: "v1", To: "v2"}},
{Graph: "graph3", Edge: &gdbi.Edge{ID: "e2", Label: "test", From: "v2", To: "v1"}},
{Graph: "graph", Edge: &gdbi.Edge{ID: "e3", Label: "test", From: "v3", To: "v1"}},
{Graph: "graph", Edge: &gdbi.Edge{ID: "e4", Label: "test", To: "v3"}},
{Graph: "graph", Edge: &gdbi.Edge{ID: "e5", Label: "test", From: "v5"}},
{Graph: "graph", Edge: &gdbi.Edge{ID: "e6", Label: "test", From: "v6", To: "v1"}},
{Graph: "graph", Edge: &gdbi.Edge{ID: "e7", Label: "test", From: "v7", To: "v2"}},
{Graph: "graph", Edge: &gdbi.Edge{ID: "e8", Label: "test", From: "v1", To: "v7"}},
}
vAdd := func([]*gdbi.Vertex) error {
return nil
}
eAdd := func(e []*gdbi.Edge) error {
return fmt.Errorf("edgeAdd test error")
}
i := make(chan *gdbi.GraphElement)
go func() {
for _, e := range elems {
i <- e
}
close(i)
}()
err := StreamBatch(i, 5, "graph", vAdd, eAdd)
if merr, ok := err.(*multierror.Error); ok {
if len(merr.Errors) != 8 {
t.Log(merr.Error())
t.Errorf("incorrect number of errors returned")
}
} else {
t.Errorf("expected err of type *multierror.Error")
}
}