-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuilder_test.go
67 lines (60 loc) · 1.48 KB
/
builder_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
package store4_test
import (
. "github.com/jimsmart/store4"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Builder", func() {
Context("A new unused builder", func() {
b := &Builder{}
Describe("Build", func() {
s := b.Build()
It("should return an empty quad store", func() {
Expect(s.Size()).To(BeZero())
})
})
})
Describe("Building some graphs", func() {
b := &Builder{}
b.Graph("g1")
b.Subject("s1").
Add("p1", "o1").
Add("p2", "o2")
b.Graph("g2").Subject("s2").Add("p3", "o3")
b.DefaultGraph().
Subject("s3").
Add("p4", "o4")
store := b.Build()
It("should return a store containing the correct quads", func() {
resultsList := iterResults(store)
Expect(resultsList).To(ConsistOf([]*Quad{
{"s1", "p1", "o1", "g1"},
{"s1", "p2", "o2", "g1"},
{"s2", "p3", "o3", "g2"},
{"s3", "p4", "o4", ""},
}))
})
})
Describe("Error conditions", func() {
Context("Add", func() {
It("should panic if the subject is missing", func() {
b := &Builder{}
b.Graph("g1")
// b.Subject("s1")
Expect(func() { b.Add("p1", "o1") }).To(Panic())
})
It("should panic if the predicate is missing", func() {
b := &Builder{}
b.Graph("g1")
b.Subject("s1")
Expect(func() { b.Add("", "o1") }).To(Panic())
})
It("should panic if the object is missing", func() {
b := &Builder{}
b.Graph("g1")
b.Subject("s1")
Expect(func() { b.Add("p1", nil) }).To(Panic())
})
})
})
})