gocraft/dbr

Unit tests

Closed this issue · 1 comments

Hi,

I do not get an approach for it. I have this function:

func PlanById(ctx TransactionalCtx, id uint64) (*Plan, error) {
    var plan Plan
    err := ctx.GetTx().
        Select("*").
        From("plans").
        Where("id = ?", id).
        LoadStruct(&plan)

    if err != nil {
        return nil, ConvertError(err, "plan", ErrorField{"id", id})
    }

    return &plan, nil
}

How can I now "mock" (I know there is no mocking in Go) the transaction so that I can just test LoadStruct? Is it possible at all?

Solved: I just found this package: https://github.com/DATA-DOG/go-sqlmock