-
Notifications
You must be signed in to change notification settings - Fork 7
/
query_test.go
69 lines (58 loc) · 1.43 KB
/
query_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
package fabric_test
import (
"reflect"
"testing"
"github.com/spy16/fabric"
)
func TestQuery_IsAny(suite *testing.T) {
suite.Parallel()
suite.Run("WhenTrue", func(t *testing.T) {
query := fabric.Query{}
if !query.IsAny() {
t.Errorf("expecting IsAny() to be true, got false")
}
})
suite.Run("WhenFalse", func(t *testing.T) {
query := fabric.Query{
Source: fabric.Clause{
Type: "==",
Value: "Bob",
},
}
if query.IsAny() {
t.Errorf("expecting IsAny() to be false, got true")
}
})
}
func TestQuery_Map(suite *testing.T) {
suite.Parallel()
suite.Run("WhenSourceIsAny", func(t *testing.T) {
query := fabric.Query{
Predicate: fabric.Clause{"like", "knows"},
Target: fabric.Clause{"like", "Bob"},
Weight: fabric.Clause{"gt", "10"},
}
src, present := query.Map()["source"]
if present {
t.Errorf("expecting source to be not present but found '%s'", src)
}
})
suite.Run("AllPresent", func(t *testing.T) {
query := fabric.Query{
Source: fabric.Clause{"~", "John"},
Predicate: fabric.Clause{"~", "knows"},
Target: fabric.Clause{"!", "Bob"},
Weight: fabric.Clause{">", "10"},
}
expected := map[string]fabric.Clause{
"source": query.Source,
"predicate": query.Predicate,
"target": query.Target,
"weight": query.Weight,
}
m := query.Map()
if !reflect.DeepEqual(expected, m) {
t.Errorf("not expected: %v != %v", expected, m)
}
})
}