Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit f238cd3

Browse files
author
ali lotfi
committed
add nodwell to roaming and add test with nodwell=true
1 parent c402435 commit f238cd3

3 files changed

Lines changed: 29 additions & 6 deletions

File tree

geofence.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ func (gf *Geofence) Nearby(key string, lat, lon, meters float64) GeofenceQueryBu
2222
}
2323

2424
// Roam geofence
25-
func (gf *Geofence) Roam(key, target, pattern string, meters int) GeofenceQueryBuilder {
26-
return newGeofenceRoamQueryBuilder(gf.client, key, target, pattern, meters)
25+
func (gf *Geofence) Roam(key, target, pattern string, meters int,nodewell bool) GeofenceQueryBuilder {
26+
return newGeofenceRoamQueryBuilder(gf.client, key, target, pattern, meters,nodewell)
2727
}

geofence_query_builder.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type GeofenceQueryBuilder struct {
2020
detectActions []DetectAction
2121
notifyCommands []NotifyCommand
2222
searchOpts searchOpts
23+
isNodwell bool
2324
}
2425

2526
func newGeofenceQueryBuilder(client tile38Client, cmd, key string, area cmd) GeofenceQueryBuilder {
@@ -31,7 +32,7 @@ func newGeofenceQueryBuilder(client tile38Client, cmd, key string, area cmd) Geo
3132
}
3233
}
3334

34-
func newGeofenceRoamQueryBuilder(client tile38Client, key, target, pattern string, meters int) GeofenceQueryBuilder {
35+
func newGeofenceRoamQueryBuilder(client tile38Client, key, target, pattern string, meters int,nodwell bool) GeofenceQueryBuilder {
3536
return GeofenceQueryBuilder{
3637
client: client,
3738
cmd: "NEARBY",
@@ -40,13 +41,19 @@ func newGeofenceRoamQueryBuilder(client tile38Client, key, target, pattern strin
4041
target: target,
4142
pattern: pattern,
4243
meters: meters,
44+
isNodwell: nodwell,
4345
}
4446
}
4547

48+
4649
func (query GeofenceQueryBuilder) toCmd() cmd {
4750
args := []string{query.key}
4851
args = append(args, query.searchOpts.Args()...)
4952
args = append(args, "FENCE")
53+
if query.isNodwell {
54+
args = append(args, "NODWELL")
55+
}
56+
5057
if len(query.detectActions) > 0 {
5158
actions := make([]string, len(query.detectActions))
5259
for i := range query.detectActions {

query_test.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ func TestChannels(t *testing.T) {
1414
Expected string
1515
}{
1616
{
17-
Cmd: channels.SetChan("foo", geofence.Roam("cat", "dog", "*", 50).Actions(Enter, Exit)).toCmd(),
17+
Cmd: channels.SetChan("foo", geofence.Roam("cat", "dog", "*", 50,false).Actions(Enter, Exit)).toCmd(),
1818
Expected: "SETCHAN foo NEARBY cat FENCE DETECT enter,exit ROAM dog * 50",
1919
},
20+
{
21+
Cmd: channels.SetChan("foo", geofence.Roam("cat", "dog", "*", 50,true).Actions(Enter, Exit)).toCmd(),
22+
Expected: "SETCHAN foo NEARBY cat FENCE NODWELL DETECT enter,exit ROAM dog * 50",
23+
},
24+
2025
}
2126

2227
for _, test := range tests {
@@ -32,9 +37,13 @@ func TestHooks(t *testing.T) {
3237
Expected string
3338
}{
3439
{
35-
Cmd: hooks.SetHook("foo", "localhost:1337", geofence.Roam("cat", "dog", "*", 50).Actions(Enter, Exit)).toCmd(),
40+
Cmd: hooks.SetHook("foo", "localhost:1337", geofence.Roam("cat", "dog", "*", 50,false).Actions(Enter, Exit)).toCmd(),
3641
Expected: "SETHOOK foo localhost:1337 NEARBY cat FENCE DETECT enter,exit ROAM dog * 50",
3742
},
43+
{
44+
Cmd: hooks.SetHook("foo", "localhost:1337", geofence.Roam("cat", "dog", "*", 50,true).Actions(Enter, Exit)).toCmd(),
45+
Expected: "SETHOOK foo localhost:1337 NEARBY cat FENCE NODWELL DETECT enter,exit ROAM dog * 50",
46+
},
3847
}
3948

4049
for _, test := range tests {
@@ -107,12 +116,19 @@ func TestGeofence(t *testing.T) {
107116
Expected: "NEARBY fleet CLIP CURSOR 5 FENCE DETECT enter,exit,cross COMMANDS set,del HASHES 5 POINT 10 20 30",
108117
},
109118
{
110-
Cmd: geofence.Roam("agent", "target", "*", 100).
119+
Cmd: geofence.Roam("agent", "target", "*", 100,false).
111120
Distance().
112121
Wherein("price", 20, 30).
113122
WhereEval("foo", "arg1", "arg2").toCmd(),
114123
Expected: "NEARBY agent WHEREIN price 2 20 30 WHEREEVAL foo 2 arg1 arg2 DISTANCE FENCE ROAM target * 100",
115124
},
125+
{
126+
Cmd: geofence.Roam("agent", "target", "*", 100,true).
127+
Distance().
128+
Wherein("price", 20, 30).
129+
WhereEval("foo", "arg1", "arg2").toCmd(),
130+
Expected: "NEARBY agent WHEREIN price 2 20 30 WHEREEVAL foo 2 arg1 arg2 DISTANCE FENCE NODWELL ROAM target * 100",
131+
},
116132
{
117133
Cmd: geofence.Within("foo").
118134
Bounds(10, 20, 30, 40).

0 commit comments

Comments
 (0)