Comments (7)
type AnyTime struct{}
// Match satisfies pgxmock.Argument interface
func (a AnyTime) Match(v interface{}) bool {
_, ok := v.(time.Time)
return ok
}
from pgxmock.
If it helps, the sql seems to get rewritten by argsMatches here. This seems like where the issue is coming from, but I'm not sure what the best way to fix it would be.
from pgxmock.
What is the definition of postgresql.AnyTime{}
?
from pgxmock.
OK, I found the issue. In short: pgxmock always expects WithRewrittenSQL()
for QueryRewriter
arguments. Which is way too strict, I must agree. This works for me:
func TestFail(t *testing.T) {
t.Parallel()
mock, err := NewConn(QueryMatcherOption(QueryMatcherEqual))
a := assert.New(t)
a.NoError(err)
update := `
UPDATE "user"
SET email = @email,
password = @password,
pin = @pin,
name = @name,
software_admin = @software_admin,
refresh_token = @refresh_token,
updated_utc = @updated_utc
WHERE id = @id`
mock.ExpectExec(update).WithRewrittenSQL(`
UPDATE "user"
SET email = $1,
password = $2,
pin = $3,
name = $4,
software_admin = $5,
refresh_token = $6,
updated_utc = $7
WHERE id = $8`).WithArgs(pgx.NamedArgs{
"id": "mockUser.ID",
"email": "mockUser.Email",
"password": "mockUser.Password",
"pin": "mockUser.Pin",
"name": "mockUser.Name",
"software_admin": "mockUser.SoftwareAdmin",
"refresh_token": "mockUser.RefreshToken",
"updated_utc": AnyArg(),
}).WillReturnError(errPanic)
_, err = mock.Exec(context.Background(), update, pgx.NamedArgs{
"id": "mockUser.ID",
"email": "mockUser.Email",
"password": "mockUser.Password",
"pin": "mockUser.Pin",
"name": "mockUser.Name",
"software_admin": "mockUser.SoftwareAdmin",
"refresh_token": "mockUser.RefreshToken",
"updated_utc": time.Now().UTC(),
})
a.Error(err)
a.NoError(mock.ExpectationsWereMet())
}
As you can see I specified both queries to expect: initial and rewritten. Let me try to fix it. I think it's not that complicated
from pgxmock.
I see, yeah, it almost feels backwards. If you manage to change it around, I'll be very happy!
from pgxmock.
Would you please try a fix in 167-fix-queryrewriter
branch? This should work go get -u github.com/pashagolub/pgxmock/v3@167-fix-queryrewriter
from pgxmock.
Yes, that works perfectly! I tested it with both my Execs and my Queries.
from pgxmock.
Related Issues (20)
- `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
- 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
- panic when calling rows.Values() HOT 13
- Extend support for batch operation mocking / assertions
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.