Documentation ¶
Index ¶
- type Argument
- type Iter
- type Query
- type Rows
- type Session
- func (m Session) Close()
- func (m *Session) ExpectExec() *Session
- func (m *Session) ExpectIter() *Session
- func (m *Session) ExpectQuery(queryRegex string) *Session
- func (m *Session) ExpectScan() *Session
- func (m Session) Query(query string, args ...interface{}) (q *Query)
- func (m *Session) WithArgs(args ...interface{}) *Session
- func (m *Session) WithError(args ...interface{}) *Session
- func (m *Session) WithResult(r Rows) *Session
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Argument ¶
type Argument interface {
Match(interface{}) error
}
Argument interface allows to match any argument in specific way
type Iter ¶
type Iter struct {
// contains filtered or unexported fields
}
Iter represents an expectation with defined rows data to iterate
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query represents query mock
type Rows ¶
type Rows interface {
AddRow(...interface{}) Rows
}
Rows interface manages the collection of the data rows
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents the mock of the expectations of the query, iterators and scan actions
func New ¶
New creates empty Session mock to be filled with expection scanarios
func TestSomeCassandraQuery(t *testing.T) { testSession := gocqlmock.New(t) // expecting single query testSession.ExpectQuery("SELECT .+ FROM users"). ExpectScan(). WithResult( gocqlmock.NewRows(). AddRow(234) ) router := Server(testSession) w := httptest.NewRecorder() req, _ := http.NewRequest("GET", "/user/234", nil) router.ServeHTTP(w, req) }
func TestSomeCassandraQueryWithListResult(t *testing.T) { testSession := gocqlmock.New(t) // expecting single query testSession.ExpectQuery("SELECT .+ FROM groups"). ExpectIter(). WithResult( gocqlmock.NewRows(). AddRow(2, "Group 2", 1.2). AddRow(5, "Group 5", 4.6) ) router := Server(testSession) w := httptest.NewRecorder() req, _ := http.NewRequest("GET", "/groups", nil) router.ServeHTTP(w, req) }
func (*Session) ExpectExec ¶
ExpectExec Query(...).Exec() to be triggered
func (*Session) ExpectIter ¶
ExpectIter Query(...).Iter().Scan(...) to be triggered, which will assign values from the rows mock to the arguments passed through Scan(...)
func (*Session) ExpectQuery ¶
ExpectQuery Query(...) to be triggered, which will match the given query string as a regular expression
func (*Session) ExpectScan ¶
ExpectScan Query(...).Scan(...) to be triggered, which will assign values from the rows mock to the arguments passed through Scan(...)
func (*Session) WithArgs ¶
WithArgs expectation should be called with given arguments. Works with Query expectations and Exec expectation
testSession.ExpectQuery("SELECT .+ FROM tb WHERE id").
WithArgs(1). ExpectExec()
testSession.ExpectQuery("UPDATE").
ExpectExec(). WithArgs(1)
func (*Session) WithResult ¶
WithResult assignes rows mock to the expectation wich was created through ExpectScan or ExpectIter