Skip to content

Commit 3602fd8

Browse files
committed
Updating to null works now
Also some minor cleanups
1 parent 021294d commit 3602fd8

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type Mongo struct {
2525

2626
//Watch defines one watch that redkeep will do for you
2727
type Watch struct {
28+
//TODO validate collections to be in this scheme: database.collection
2829
TrackCollection string `json:"trackCollection" validate:"required,gt=0"`
2930
TrackFields []string `json:"trackFields" validate:"required,min=1,dive,min=1"`
3031
TargetCollection string `json:"targetCollection" validate:"required,min=1"`

tail.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,6 @@ func handleUpdate(
120120
command map[string]interface{},
121121
selector map[string]interface{},
122122
) {
123-
// update all w.TrackFields (that are in command)
124-
// in w.TargetCollection
125-
// WHERE w.TriggerReference
126-
//
127-
//selector
128123
session := s.Copy()
129124
defer session.Close()
130125
p := strings.Index(w.TargetCollection, ".")
@@ -135,7 +130,7 @@ func handleUpdate(
135130
normalizingFields := bson.M{}
136131
for _, field := range w.TrackFields {
137132
value := GetValue("$set."+field, command)
138-
if value != nil {
133+
if HasKey("$set."+field, command) {
139134
normalizingFields[w.TargetNormalizedField+"."+field] = value
140135
}
141136
}
@@ -165,7 +160,6 @@ func HasKey(key string, ds interface{}) bool {
165160
}
166161

167162
if _, ok := data[key]; ok {
168-
log.Printf("Key found: [%s]\n", key)
169163
return true
170164
}
171165

tail_test.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,32 @@ import (
1414
)
1515

1616
var _ = Describe("Tail", func() {
17-
Context("Test getValue", func() {
17+
Context("Test HasKey", func() {
18+
It("validate functionality", func() {
19+
toTest := map[string]interface{}{
20+
"fish": map[string]interface{}{
21+
"dog": "cat",
22+
},
23+
"tree": nil,
24+
"yellow": map[string]interface{}{
25+
"red": nil,
26+
},
27+
}
28+
actual := HasKey("blub", toTest)
29+
Expect(actual).To(Equal(false))
30+
31+
actual = HasKey("fish.dog", toTest)
32+
Expect(actual).To(Equal(true))
33+
34+
actual = HasKey("yellow.red", toTest)
35+
Expect(actual).To(Equal(true))
36+
37+
actual = HasKey("tree", toTest)
38+
Expect(actual).To(Equal(true))
39+
})
40+
})
41+
42+
Context("test GetValue", func() {
1843
It("will find the first value", func() {
1944
testReference := mgo.DBRef{
2045
Collection: "diff",

0 commit comments

Comments
 (0)