Skip to content

Commit

Permalink
conditions: Updated the type coerciion performed on the value receive…
Browse files Browse the repository at this point in the history
…d in the StringPairsEqualCondition to respect JSON

Signed-off-by: Eric Douglas <eric@bridg.com>
  • Loading branch information
ericalandouglas authored and arekkas committed Mar 18, 2017
1 parent 41c6b8e commit ef4a3e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
28 changes: 15 additions & 13 deletions condition_string_pairs_equal.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@ type StringPairsEqualCondition struct{}
// Fulfills returns true if the given value is an array of string arrays and
// each string array has exactly two values which are equal
func (c *StringPairsEqualCondition) Fulfills(value interface{}, _ *Request) bool {
pairs, PairsOk := value.([][]interface{})
pairs, PairsOk := value.([]interface{})
if !PairsOk {
return false
}

for _, v := range pairs {
pair, PairOk := v.([]interface{})
if !PairOk || (len(pair) != 2) {
return false
}

if PairsOk {
for _, pair := range pairs {
if (len(pair) != 2) {
return false
}
a, AOk := pair[0].(string)
b, BOk := pair[1].(string)
a, AOk := pair[0].(string)
b, BOk := pair[1].(string)

if !AOk || !BOk || (a != b) {
return false
}
if !AOk || !BOk || (a != b) {
return false
}
return true
}

return false
return true
}

// GetName returns the condition's name.
Expand Down
17 changes: 8 additions & 9 deletions condition_string_pairs_equal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ func TestStringPairsEqualMatch(t *testing.T) {
pass bool
}{
{pairs: "junk", pass: false},
{pairs: [][]interface{}{{}}, pass: false},
{pairs: [][]interface{}{{"1"}}, pass: false},
{pairs: [][]interface{}{{"1", "1", "2"}}, pass: false},
{pairs: [][]interface{}{{"1", "2"}}, pass: false},
{pairs: [][]interface{}{{"1", "1"},{"2", "3"}}, pass: false},
{pairs: []interface{}{}, pass: false},
{pairs: [][]interface{}{}, pass: true},
{pairs: [][]interface{}{{"1", "1"}}, pass: true},
{pairs: [][]interface{}{{"1", "1"},{"2", "2"}}, pass: true},
{pairs: []interface{}{[]interface{}{}}, pass: false},
{pairs: []interface{}{[]interface{}{"1"}}, pass: false},
{pairs: []interface{}{[]interface{}{"1", "1", "2"}}, pass: false},
{pairs: []interface{}{[]interface{}{"1", "2"}}, pass: false},
{pairs: []interface{}{[]interface{}{"1", "1"},[]interface{}{"2", "3"}}, pass: false},
{pairs: []interface{}{}, pass: true},
{pairs: []interface{}{[]interface{}{"1", "1"}}, pass: true},
{pairs: []interface{}{[]interface{}{"1", "1"},[]interface{}{"2", "2"}}, pass: true},
} {
condition := &StringPairsEqualCondition{}

Expand Down

0 comments on commit ef4a3e7

Please sign in to comment.