Skip to content

Commit

Permalink
dynamodb: Remove value if Exists set to false in Expected block
Browse files Browse the repository at this point in the history
  • Loading branch information
TANABE Ken-ichi committed Feb 3, 2014
1 parent d8fd034 commit e4727b6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions dynamodb/item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (s *ItemSuite) TestConditionalPutUpdateDeleteItem(c *gocheck.C) {
// Put with condition failed
expected := []dynamodb.Attribute{
*dynamodb.NewStringAttribute("Attr1", "expectedAttr1Val").SetExists(true),
*dynamodb.NewStringAttribute("AttrNotExists", "").SetExists(false),
}
if ok, err := s.table.ConditionalPutItem("NewHashKeyVal", "", attrs, expected); ok {
c.Errorf("Expect condition does not meet.")
Expand Down
6 changes: 4 additions & 2 deletions dynamodb/query_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ func (q *Query) AddExpected(attributes []Attribute) {
if a.Exists != "" {
value["Exists"] = a.Exists
}
//UGH!! (I miss the query operator)
value["Value"] = msi{a.Type: map[bool]interface{}{true: a.SetValues, false: a.Value}[a.SetType()]}
// If set Exists to false, we must remove Value
if value["Exists"] != "false" {
value["Value"] = msi{a.Type: map[bool]interface{}{true: a.SetValues, false: a.Value}[a.SetType()]}
}
expected[a.Name] = value
}
q.buffer["Expected"] = expected
Expand Down
4 changes: 4 additions & 0 deletions dynamodb/query_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func (s *QueryBuilderSuite) TestAddExpectedQuery(c *gocheck.C) {

expected := []dynamodb.Attribute{
*dynamodb.NewStringAttribute("domain", "expectedTest").SetExists(true),
*dynamodb.NewStringAttribute("testKey", "").SetExists(false),
}
q.AddExpected(expected)

Expand All @@ -173,6 +174,9 @@ func (s *QueryBuilderSuite) TestAddExpectedQuery(c *gocheck.C) {
"Value": {
"S": "expectedTest"
}
},
"testKey": {
"Exists": "false"
}
},
"Key": {
Expand Down

0 comments on commit e4727b6

Please sign in to comment.