-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
is_true_test.go
61 lines (50 loc) · 1.34 KB
/
is_true_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
package distil
import (
"encoding/json"
"testing"
. "github.com/onsi/gomega"
)
func TestIsTrue(t *testing.T) {
// Register the test.
RegisterTestingT(t)
// Build dummy dataset.
data := []map[string]interface{}{
{"location": "Auckland", "active": false},
{"location": "Wellington", "active": false},
{"location": "Nelson", "active": true},
{"location": "Chirstchurch", "active": false},
{"location": "Queenstown", "active": true},
{"location": "Invercargill", "active": false},
}
// Init distil dataset with our dummy data.
dataset := NewDataset(data...)
// Build a distil query.
query := &Query{}
// Append the appropriate filters.
query.Filters = append(query.Filters, Filter{
Field: "active",
Value: true,
Operator: Operator{
Code: "is_true",
Type: "string",
},
})
// Run the query.
results, err := dataset.Run(query)
if err != nil {
t.Fatalf("Unexpected error running query: %s", err.Error())
}
// Handle empty result set.
if results == nil {
t.Fatalf("Unexpectedly got an empty resultset running query")
}
// Build expected result set.
expected := []map[string]interface{}{
{"location": "Nelson", "active": true},
{"location": "Queenstown", "active": true},
}
// Compare actual/expected result sets.
rm, _ := json.Marshal(results)
em, _ := json.Marshal(expected)
Expect(rm).To(MatchJSON(em))
}