Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

go sqlgen: binlog testers should compare driver.Values #170

Merged
merged 5 commits into from
Sep 20, 2018

Conversation

changpingc
Copy link
Contributor

Currently binlog tester does not match int32 filter value against a int64 column, for example. It doesn't support custom type either. This fixes both.

We want to use Valuer to convert a filter value into driver.Value so
we run equality check on well-known driver.Value types. This means
we need to feed arbitrary filter value into Valuer, and its logic should
respect the value type that is passed in.
Copy link
Contributor

@berfarah berfarah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with the amount of tests here 😊

return f.value.Int(), nil
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
return int64(f.value.Uint()), nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ nice, thanks for catching this

@@ -88,13 +88,13 @@ func (f Valuer) Value() (driver.Value, error) {
// Coerce our value into a valid sql/driver.Value (see sql/driver.IsValue).
// This not only converts base types into their sql counterparts (like int32 -> int64) but also
// handles custom types (like `type customString string` -> string).
switch f.Kind {
switch f.value.Kind() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😬 I'm scared

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(test plan?)

return false
}

// Special case: if both driver.Value are slices, compare their byte values.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@changpingc
Copy link
Contributor Author

I will land on staging tomorrow. 🙏

@coveralls
Copy link

Pull Request Test Coverage Report for Build 1048

  • 24 of 33 (72.73%) changed or added relevant lines in 2 files are covered.
  • 6 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.07%) to 64.547%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/fields/sql.go 2 4 50.0%
sqlgen/reflect.go 22 29 75.86%
Files with Coverage Reduction New Missed Lines %
graphql/schemabuilder/reflect.go 6 71.56%
Totals Coverage Status
Change from base Build 1018: -0.07%
Covered Lines: 3299
Relevant Lines: 5111

💛 - Coveralls

Copy link
Contributor

@berfarah berfarah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 staging test went well, good to go!

@changpingc changpingc merged commit b66553a into master Sep 20, 2018
@berfarah berfarah deleted the changping/value-filter branch September 20, 2018 19:09
changpingc added a commit that referenced this pull request Oct 2, 2018
changpingc added a commit that referenced this pull request Oct 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants