Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #53 from monzo/allow-proxy-comparison
Browse files Browse the repository at this point in the history
🆎 Support proxy types in mock implementation for comparison
  • Loading branch information
suhailpatel committed Oct 18, 2019
2 parents 6abbd36 + 96a5cfb commit 0c9a9f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions relation.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gocassa

import (
"fmt"
"reflect"
"strings"
"time"
)
Expand Down Expand Up @@ -67,6 +69,11 @@ func convertToPrimitive(i interface{}) interface{} {
// since []byte are not `==` comparable in go, but strings are
return string(v)
default:
// If the underlying type is a string, we want to represent this value
// as a string for comparison across proxy types.
if reflect.ValueOf(i).Kind() == reflect.String {
return fmt.Sprintf("%v", i)
}
return i
}
}
Expand Down
5 changes: 4 additions & 1 deletion relation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ func TestAnyEquals(t *testing.T) {
testTime1, _ := time.ParseInLocation(time.RFC3339, "2013-08-05T09:00:00+01:00", loc1)
testTime2, _ := time.ParseInLocation(time.RFC3339, "2013-08-05T08:00:00Z", loc2)

type name string

testCases := []struct {
term interface{}
relations []interface{}
Expand All @@ -19,12 +21,13 @@ func TestAnyEquals(t *testing.T) {
{testTime1, makeInterfaceArray(testTime2)},
{1950, makeInterfaceArray(1950)},
{[]byte{0x00, 0xFF, 0x01, 0x99, 0xEA}, makeInterfaceArray("\x00\xFF\x01\x99\xEA")},
{name("Bingo 🐕"), makeInterfaceArray("Bingo 🐕")},
}

for _, tc := range testCases {
equality := anyEquals(tc.term, tc.relations)
if !equality {
t.Fatal("not equal")
t.Fatalf("not equal (testcase: %v)", tc)
}
}
}
Expand Down

0 comments on commit 0c9a9f0

Please sign in to comment.