Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: (feature/dynamodb/expression) re-add IsSet methods #1329

Merged
merged 2 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changelog/8e261b4b5633485cad821d38e2677e46.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "8e261b4b-5633-485c-ad82-1d38e2677e46",
"type": "feature",
"description": "Add IsSet helper for ConditionBuilder and KeyConditionBuilder ([#1329](https://github.com/aws/aws-sdk-go-v2/pull/1329))",
"modules": [
"feature/dynamodb/expression"
]
}
14 changes: 14 additions & 0 deletions feature/dynamodb/expression/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ type ConditionBuilder struct {
mode conditionMode
}

// IsSet returns true if the ConditionBuilder is set and returns false
// otherwise. A zero value of a ConditionBuilder returns false.
//
// Example:
//
// var condition expression.ConditionBuilder
// condition.IsSet() // returns false
//
// condition := expression.Equal(expression.Name("foo"), expression.Value(5))
// condition.IsSet() // returns true
func (cb ConditionBuilder) IsSet() bool {
return cb.mode != unsetCond
}

// Equal returns a ConditionBuilder representing the equality clause of the two
// argument OperandBuilders. The resulting ConditionBuilder can be used as a
// part of other Condition Expressions or as an argument to the WithCondition()
Expand Down
27 changes: 27 additions & 0 deletions feature/dynamodb/expression/condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,33 @@ const (
invalidConditionOperand = "BuildOperand error"
)

//IsSet
func TestIsSet(t *testing.T) {
cases := []struct {
name string
input ConditionBuilder
expected bool
}{
{
name: "set",
input: Equal(Name("foo"), Value("bar")),
expected: true,
},
{
name: "unset",
input: ConditionBuilder{},
expected: false,
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
if actual := c.input.IsSet(); actual != c.expected {
t.Errorf("expected %t, got %t", c.expected, actual)
}
})
}
}

//Compare
func TestCompare(t *testing.T) {
cases := []struct {
Expand Down
14 changes: 14 additions & 0 deletions feature/dynamodb/expression/key_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ func KeyEqual(keyBuilder KeyBuilder, valueBuilder ValueBuilder) KeyConditionBuil
}
}

// IsSet returns true if the KeyConditionBuilder is set and returns
// false otherwise. A zero value of a KeyConditionBuilder returns false.
//
// Example:
//
// var keyCondition expression.KeyConditionBuilder
// keyCondition.IsSet() // returns false
//
// keyCondition := expression.KeyEqual(expression.Key("foo"), expression.Value(5))
// keyCondition.IsSet() // returns true
func (kcb KeyConditionBuilder) IsSet() bool {
return kcb.mode != unsetKeyCond
}

// Equal returns a KeyConditionBuilder representing the equality clause of
// the two argument OperandBuilders. The resulting KeyConditionBuilder can be
// used as a part of other Key Condition Expressions or as an argument to the
Expand Down
27 changes: 27 additions & 0 deletions feature/dynamodb/expression/key_condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,33 @@ const (
invalidKeyConditionFormat = "buildKeyCondition error: invalid key condition constructed"
)

//IsSet
func TestKeyIsSet(t *testing.T) {
cases := []struct {
name string
input KeyConditionBuilder
expected bool
}{
{
name: "set",
input: KeyEqual(Key("foo"), Value("bar")),
expected: true,
},
{
name: "unset",
input: KeyConditionBuilder{},
expected: false,
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
if actual := c.input.IsSet(); actual != c.expected {
t.Errorf("expected %t, got %t", c.expected, actual)
}
})
}
}

func TestKeyCompare(t *testing.T) {
cases := []struct {
name string
Expand Down