Comments (7)
Wait I think I'm doing something wrong, let me look at this more.
from pgxmock.
Did you look at fixing this, as I think this is still an issue. Or can you confirm what you were doing wrong?
from pgxmock.
@aaranmcguire show us your code and we will try to investigate together
from pgxmock.
Thanks @pashagolub. I think I understand the issue again. It's wanting the exact type when doing the add row. So AddRow( nil)
will work correctly, Providing a pointer of the same type to AddRow()
will also allow the test to pass.
This again is unlike go-sqlmock making it more work to switch over. Do you have any thoughts on how to make it easier to swap over so types are more easily converted like PGX does?
from pgxmock.
I don't think I understand your last statement? Can you please provide code samples with pgx
showing the issue?
from pgxmock.
With DATA-DOG/go-sqlmock you're able to AddRow()
and it won't mind the type conversion when running Scan()
. See below of what I would expect to work.
mock.ExpectQuery("SELECT .+ FROM test WHERE .+").
WithArgs(1).
WillReturnRows(db.NewRows(
[]string{"id", "value"}).
AddRow(uint64(1), "hello"),
)
rows := mock.QueryRow(context.Background(), "SELECT id, value FROM test WHERE id = $1", 1)
var id uint64
var value *string
err = rows.Scan(&id, &value)
if err != nil {
t.Error(err)
}
In your mock software you require the exact match, so you have to modify it to:
+ mockedValue := "hello"
mock.ExpectQuery("SELECT .+ FROM test WHERE .+").
WithArgs(1).
WillReturnRows(db.NewRows(
[]string{"id", "value"}).
- AddRow(uint64(1), "hello"),
+ AddRow(uint64(1), &mockedValue),
)
rows := mock.QueryRow(context.Background(), "SELECT id, value FROM test WHERE id = $1", 1)
Which makes it harder to migrate from go-sqlmock, and doesn't seem to match exactly what pgx does as it coverts using this function: https://github.com/jackc/pgx/blob/master/values.go#L27
go-sqlmock also converts during AddRow
into something the database would give too, so that on Scan it sees what a database may give: https://github.com/DATA-DOG/go-sqlmock/blob/master/rows.go#L173-L176
While I could update all the code to give the exact types, it's a bit of a pain, and makes it harder for others to convert over to pgx.
from pgxmock.
Thanks for the detailed explanation. I'll try to take a look.
Of course, PRs are more than welcome!
from pgxmock.
Related Issues (20)
- replace deprecated `golint` with `revive`
- Matching query using WithArgs behavior. HOT 3
- `ExpectedCopyFrom.String()` outputs table name instead of columns names
- Link does not exist HOT 1
- ExpectCopyFrom not working as expected HOT 6
- pgxmock.AddRows makes []bytes conversion panic HOT 6
- Rows does not correctly works for QueryRow HOT 3
- Support for pgxpool Stat() in PgxPoolIface
- Add missing methods to PgxPoolIface HOT 2
- Deallocate is not part of a connection pool HOT 8
- Sweep: implement `func (c *pgxmock) ExpectReset() *ExpectedReset` HOT 2
- Sweep: Extend support for batch operation mocking / assertions HOT 1
- [question] Is there a method that doesn't alter the original connection pool ? HOT 1
- Staticcheck Linting Error: undefined 'max' in expectations.go HOT 1
- Request WithNamedArgs or something similar HOT 4
- Issues with new NamedArgs mocks HOT 7
- modification to support golang 1.19
- Scanning a single row without using rows.Next() HOT 2
- pgxmock.ExpectBegin is not documented HOT 6
- When you close row, the test will panic HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pgxmock.