-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert sqlutilmocks.DataSource -> sqlutil.TestDataSource using ramsq…
…l driver
- Loading branch information
1 parent
1bf0a29
commit 979b69d
Showing
4 changed files
with
104 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package sqlutil | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"testing" | ||
|
||
"github.com/jmoiron/sqlx" | ||
_ "github.com/proullon/ramsql/driver" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var _ DataSource = &TestDataSource{} | ||
|
||
// TestDataSource is a simple in-memory DataSource type which can be used for some types of unit testing. | ||
type TestDataSource struct { | ||
db *sqlx.DB | ||
} | ||
|
||
// BindNamed provides a mock function with given fields: _a0, _a1 | ||
func (ds *TestDataSource) BindNamed(_a0 string, _a1 interface{}) (string, []interface{}, error) { | ||
return ds.db.BindNamed(_a0, _a1) | ||
} | ||
|
||
// DriverName provides a mock function with given fields: | ||
func (ds *TestDataSource) DriverName() string { | ||
return ds.db.DriverName() | ||
} | ||
|
||
// ExecContext provides a mock function with given fields: ctx, query, args | ||
func (ds *TestDataSource) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) { | ||
return ds.db.ExecContext(ctx, query, args...) | ||
} | ||
|
||
// GetContext provides a mock function with given fields: ctx, dest, query, args | ||
func (ds *TestDataSource) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error { | ||
return ds.db.GetContext(ctx, dest, query, args...) | ||
} | ||
|
||
// NamedExecContext provides a mock function with given fields: ctx, query, arg | ||
func (ds *TestDataSource) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error) { | ||
return ds.db.NamedExecContext(ctx, query, arg) | ||
} | ||
|
||
// PrepareContext provides a mock function with given fields: ctx, query | ||
func (ds *TestDataSource) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) { | ||
return nil, nil | ||
} | ||
|
||
func (ds *TestDataSource) PrepareNamedContext(ctx context.Context, query string) (*sqlx.NamedStmt, error) { | ||
return ds.db.PrepareNamedContext(ctx, query) | ||
} | ||
|
||
// QueryContext provides a mock function with given fields: ctx, query, args | ||
func (ds *TestDataSource) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) { | ||
return ds.db.QueryContext(ctx, query, args...) | ||
} | ||
|
||
// QueryRowxContext provides a mock function with given fields: ctx, query, args | ||
func (ds *TestDataSource) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row { | ||
return ds.db.QueryRowxContext(ctx, query, args...) | ||
} | ||
|
||
// QueryxContext provides a mock function with given fields: ctx, query, args | ||
func (ds *TestDataSource) QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error) { | ||
return ds.db.QueryxContext(ctx, query, args...) | ||
} | ||
|
||
// Rebind provides a mock function with given fields: _a0 | ||
func (ds *TestDataSource) Rebind(_a0 string) string { | ||
return ds.db.Rebind(_a0) | ||
} | ||
|
||
// SelectContext provides a mock function with given fields: ctx, dest, query, args | ||
func (ds *TestDataSource) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error { | ||
return ds.SelectContext(ctx, dest, query, args...) | ||
} | ||
|
||
// NewTestDataSource creates a new instance of DataSource. | ||
func NewTestDataSource(t *testing.T) *TestDataSource { | ||
db, err := sqlx.Open("ramsql", "testdb") | ||
require.NoError(t, err) | ||
t.Cleanup(func() { require.NoError(t, db.Close()) }) | ||
return &TestDataSource{db: db} | ||
} |