You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
My code executes in INSERT INTO with multiple parameters
score: &SomeStruct{
Id: "t2_123",
Value1: 555,
Value2: 0,
Timestamp: now.UnixMilli(),
},
session.Query(`INSERT INTO table1 (id, value1, value2, timestamp) VALUES (?, ?, ?, ?)`,
someStruct.Id, someStruct.Value1, someStruct.Value2, someStruct.Timestamp).Exec()```
When setting up my mocks, I want to ensure that all parameters are correct:
--- FAIL: TestExecuteQuery/Exact_Match (0.00s)
main.go:14: Unexpected call to *main.MockSession.Query([INSERT INTO table1 (id, value1, value2, timestamp) VALUES (?, ?, ?, ?) t2_123 555 0 1675461224262]) at /src/main.go:14 because:
expected call at /src/main_test.go:51 doesn't match the argument at index 2.
Got: [555 0 1675461224262] ([]interface {})
Want: is equal to 555 (int)
controller.go:137: missing call(s) to *main.MockSession.Query(is equal to INSERT INTO table1 (id, value1, value2, timestamp) VALUES (?, ?, ?, ?) (string), is equal to t2_123 (string), is equal to 555 (int), is equal to 0 (int), is equal to 2023-02-03 21:53:44.26297212 +0000 UTC m=+0.002619383 (time.Time)) /src/main_test.go:51
controller.go:137: missing call(s) to *main.MockQuery.Exec() /src/main_test.go:52
controller.go:137: aborting test due to missing call(s)
It seems like that the varags are matched a a slice instead of individually:
Got: [555 0 1675461224262] ([]interface {})
Want: is equal to 555 (int)
Next I tried matching the remaining varargs as `[]interface{}`:
Which seems to be equal and correct, but I'm not familiar enough with go / gomock to determine if this comparison is possible.
I've put a small reproducible example together: https://github.com/Step2Web/gomock_varargs_issue
**Expected behaviour**
I would like to setup my mocks to match all parameters exactly as they were provided to the varags:
Actual behaviour
Setting up a Mock with exact parameters for a method with
interface{}
varags, doesn't match.I'm writing unit tests for gocql and to allow
mockgen
to generate mocks, I'm using the gockle library which wraps all CQL code behind interfaces.The generated mock for
Query
looks like this:My code executes in
INSERT INTO
with multiple parameterssessionMock.EXPECT().Query(
INSERT INTO table1 (id, value1, value2, timestamp) VALUES (?, ?, ?, ?)
, "t2_123", 555, 0, now).Return(queryMock).Times(1)query.EXPECT().Exec().Times(1)--- FAIL: TestExecuteQuery/Exact_Match (0.00s)
main.go:14: Unexpected call to *main.MockSession.Query([INSERT INTO table1 (id, value1, value2, timestamp) VALUES (?, ?, ?, ?) t2_123 555 0 1675461224262]) at /src/main.go:14 because:
expected call at /src/main_test.go:51 doesn't match the argument at index 2.
Got: [555 0 1675461224262] ([]interface {})
Want: is equal to 555 (int)
controller.go:137: missing call(s) to *main.MockSession.Query(is equal to INSERT INTO table1 (id, value1, value2, timestamp) VALUES (?, ?, ?, ?) (string), is equal to t2_123 (string), is equal to 555 (int), is equal to 0 (int), is equal to 2023-02-03 21:53:44.26297212 +0000 UTC m=+0.002619383 (time.Time)) /src/main_test.go:51
controller.go:137: missing call(s) to *main.MockQuery.Exec() /src/main_test.go:52
controller.go:137: aborting test due to missing call(s)
Got: [555 0 1675461224262] ([]interface {})
Want: is equal to 555 (int)
sessionMock.EXPECT().Query(
INSERT INTO table1 (id, value1, value2, timestamp) VALUES (?, ?, ?, ?)
, []interface{}{"t2_123", 555, 0, now}).Return(queryMock).Times(1)query.EXPECT().Exec().Times(1)Got: [t2_123 555 0 2023-02-03 21:59:40.214 +0000 UTC] ([]interface {})
Want: is equal to [t2_123 555 0 2023-02-03 21:59:40.214 +0000 UTC] ([]interface {})
sessionMock.EXPECT().Query(
INSERT INTO table1 (id, value1, value2, timestamp) VALUES (?, ?, ?, ?)
, "t2_123", 555, 0, time.UnixMilli(now)).Return(queryMock).Times(1)The text was updated successfully, but these errors were encountered: