willfaught / gockle Goto Github PK
View Code? Open in Web Editor NEWA simpler and mockable gocql
Home Page: https://go.dev/pkg/github.com/willfaught/gockle
License: Apache License 2.0
A simpler and mockable gocql
Home Page: https://go.dev/pkg/github.com/willfaught/gockle
License: Apache License 2.0
I used this briefly and made a change in my local copy that I thought was more flexible with mocking:
func flattenStatementAndArgs(statement string, arguments []interface{}) []interface{} {
params := make([]interface{}, 0)
params = append(params, statement)
params = append(params, arguments...)
return params
}
// Exec implements Session.
func (m SessionMock) Exec(statement string, arguments ...interface{}) error {
return m.Called(flattenStatementAndArgs(statement, arguments)...).Error(0)
}
The main motivation for this this is so that sql arguments could be mock.Any() objects for things like timestamps for modified/created fields.
gocql API gives an option to get total number of query results through iterator.NumRows(). Is there a way to get that through gockle API on iterator?
Hello,
I try to mock ScanMap (https://github.com/willfaught/gockle/blob/master/session.go#L51) and the given example (https://github.com/willfaught/gockle/blob/master/examples_test.go#L54) seems not correct, because it returns (map[string]interface{}, error)
.
If I add this block at the end of examples_test.go
func TestScanMap(t *testing.T) {
m := make(map[string]interface{})
err := mySession.ScanMap("select * from users", m)
if err != nil {
t.Fatal(err)
}
}
I have this panic:
panic: interface conversion: map[string]interface {} is not error: missing method Error [recovered]
panic: interface conversion: map[string]interface {} is not error: missing method Error
goroutine 5 [running]:
panic(0x77dc00, 0xc820017c00)
/home/me/go-1.6.1/src/runtime/panic.go:464 +0x3e6
testing.tRunner.func1(0xc820090090)
/home/me/go-1.6.1/src/testing/testing.go:467 +0x192
panic(0x77dc00, 0xc820017c00)
/home/me/go-1.6.1/src/runtime/panic.go:426 +0x4e9
github.com/willfaught/gockle.SessionMock.ScanMap(0xc820011180, 0x3, 0x4, 0x0, 0x1, 0x82d7b0, 0x13, 0xc82000b890, 0x0, 0x0, ...)
/home/me/go/src/github.com/willfaught/gockle/session.go:132 +0x29a
github.com/willfaught/gockle.TestScanMap(0xc820090090)
/home/me/go/src/github.com/willfaught/gockle/examples_test.go:61 +0x9a
testing.tRunner(0xc820090090, 0x9ade90)
/home/me/go-1.6.1/src/testing/testing.go:473 +0x98
created by testing.RunTests
/home/me/go-1.6.1/src/testing/testing.go:582 +0x892
Could you plz provide me a valid example?
Thx in adv
I created a "gockle-lite" for our testing that is very similar, but also mocks queries. I also made the change I suggested in a previous issue for flattening args. The flattening args should probably get removed to use the new Slice
type in go-mock.
It's a pretty large change to the gockle API, but I thought I would share anyways. I made a README to go along with it as well.
Dear willfaught,
I think this framework is very useful who use gocql and wanna to mock the dao level.If you write a n example for readers it will be perfect.Thanks! Waiting you to save my life.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.