-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
not_eq_test.go
67 lines (56 loc) · 3.05 KB
/
not_eq_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 distil
import (
"encoding/json"
"testing"
. "github.com/onsi/gomega"
)
func TestNotEq(t *testing.T) {
// Register the test.
RegisterTestingT(t)
// Build dummy dataset.
data := []map[string]interface{}{
{"location": "Auckland", "department": "Engineering", "team": "Security", "salary": 120000, "prev_employers": 7, "start_date": "2016-01-15T12:00:00Z"},
{"location": "Auckland", "department": "Engineering", "team": "Security", "salary": 140000, "prev_employers": 6, "start_date": "2016-01-07T12:00:00Z"},
{"location": "Auckland", "department": nil, "team": nil, "salary": 125000, "prev_employers": 7, "start_date": "2016-01-17T12:00:00Z"},
{"location": "Auckland", "department": "Engineering", "team": "Security", "salary": 80000, "prev_employers": 3, "start_date": "2016-03-23T12:00:00Z"},
{"location": "Auckland", "department": "Marketing", "team": "Content", "salary": 90000, "prev_employers": 6, "start_date": "2016-01-15T12:00:00Z"},
{"location": "Auckland", "department": "Marketing", "team": "Content", "salary": 150000, "prev_employers": 2, "start_date": "2016-01-04T12:00:00Z"},
{"location": "Wellington", "department": "Engineering", "team": "Security", "salary": 120000, "prev_employers": 6, "start_date": "2016-01-23T12:00:00Z"},
{"location": "Wellington", "department": "Engineering", "team": "Security", "salary": 160000, "prev_employers": 4, "start_date": "2016-03-23T12:00:00Z"},
}
// 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: "location",
Value: "WeLLinGton",
Operator: Operator{
Code: "not_eq",
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": "Auckland", "department": "Engineering", "team": "Security", "salary": 120000, "prev_employers": 7, "start_date": "2016-01-15T12:00:00Z"},
{"location": "Auckland", "department": "Engineering", "team": "Security", "salary": 140000, "prev_employers": 6, "start_date": "2016-01-07T12:00:00Z"},
{"location": "Auckland", "department": nil, "team": nil, "salary": 125000, "prev_employers": 7, "start_date": "2016-01-17T12:00:00Z"},
{"location": "Auckland", "department": "Engineering", "team": "Security", "salary": 80000, "prev_employers": 3, "start_date": "2016-03-23T12:00:00Z"},
{"location": "Auckland", "department": "Marketing", "team": "Content", "salary": 90000, "prev_employers": 6, "start_date": "2016-01-15T12:00:00Z"},
{"location": "Auckland", "department": "Marketing", "team": "Content", "salary": 150000, "prev_employers": 2, "start_date": "2016-01-04T12:00:00Z"},
}
// Compare actual/expected result sets.
rm, _ := json.Marshal(results)
em, _ := json.Marshal(expected)
Expect(rm).To(MatchJSON(em))
}