Coder Social home page Coder Social logo

gockle's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gockle's Issues

Ask for examples

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.

How to mock ScanMap

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

API closer to gocql

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.

conduce-gockle.zip

Possible Change

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.