DATA-DOG / go-sqlmock

Sql mock driver for golang to test database interactions
Other
6.14k stars 407 forks source link

Invalidate memory scanned into sql.RawBytes #177

Closed dackroyd closed 5 years ago

dackroyd commented 5 years ago

The intention of sql.RawBytes is for it to hold memory owned by the database. When used, it's content is only valid until the Next, Scan or Close is called on the Rows

To ensure that we meet this behaviour, when []byte is used in a column, it's value is copied to a buffer that we keep track of for later invalidation. By doing this, incorrect use of sql.RawBytes values is exposed in tests that use go-sqlmock. Without this, when a real database is used and it's driver does share memory, then those issues would not be exposed until runtime (and in non-obvious ways)

dackroyd commented 5 years ago

Resolves #176

codecov-io commented 5 years ago

Codecov Report

Merging #177 into master will increase coverage by 0.22%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #177      +/-   ##
==========================================
+ Coverage   90.64%   90.87%   +0.22%     
==========================================
  Files          15       15              
  Lines         727      745      +18     
==========================================
+ Hits          659      677      +18     
  Misses         49       49              
  Partials       19       19
Impacted Files Coverage Δ
rows.go 89.13% <100%> (+2.64%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 6c8a572...d5879ee. Read the comment docs.

l3pp4rd commented 5 years ago

looks good @dackroyd is there anything more you wanted to add, or shall we merge it?

dackroyd commented 5 years ago

Nothing more that I wanted to add @l3pp4rd, good to go unless anything else needs to be tidied up / changed! 👍

l3pp4rd commented 5 years ago

it looks good, thanks!

l3pp4rd commented 5 years ago

will tag it a day later, will check if users find something incompatible or concerning while using