-
Notifications
You must be signed in to change notification settings - Fork 0
/
location_set_test.go
79 lines (61 loc) · 1.65 KB
/
location_set_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
package proximity
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
var (
set *LocationSet
lat = 123.0
lng = -123.0
radius = 5000.0
lowerBound = -1.0
upperBound = 1.0
locationName = "Test Location"
)
func init() {
set = &LocationSet{
Name: key,
IntervalFinder: func(lat, lng, radius float64) []Int64arr {
return []Int64arr{
Int64arr{int64(lowerBound), int64(upperBound)},
}
},
}
}
func TestSuccessfulAdd(t *testing.T) {
client := &testClient{}
client.On("ZAdd", key, encode(lat, lng), locationName).Return(1, nil)
set.client = client
err := set.Add(locationName, lat, lng)
client.AssertExpectations(t)
assert.Nil(t, err)
}
func TestUnsuccessfulAdd(t *testing.T) {
err := errors.New("Some Redis Error")
client := &testClient{}
client.On("ZAdd", key, encode(lat, lng), locationName).Return(0, err)
set.client = client
err = set.Add(locationName, lat, lng)
client.AssertExpectations(t)
assert.NotNil(t, err)
}
func TestSuccessfulNear(t *testing.T) {
client := &testClient{}
client.On("ZRangeByScore", set.Name, lowerBound, upperBound).Return([]string{"Some Value"}, nil)
set.client = client
results, err := set.Near(lat, lng, radius)
client.AssertExpectations(t)
assert.Nil(t, err)
assert.Equal(t, "Some Value", results[0])
}
func TestUnsuccessfulNear(t *testing.T) {
err := errors.New("Some Redis Error")
client := &testClient{}
client.On("ZRangeByScore", set.Name, lowerBound, upperBound).Return([]string{}, err)
set.client = client
results, err := set.Near(lat, lng, radius)
client.AssertExpectations(t)
assert.NotNil(t, err)
assert.Equal(t, 0, len(results))
}