Skip to content

Commit

Permalink
Remove TestDataSource wrapper for now, just return *sqlx.DB from cons…
Browse files Browse the repository at this point in the history
…tructor
  • Loading branch information
reductionista committed Nov 14, 2024
1 parent 979b69d commit 5ca1a71
Showing 1 changed file with 4 additions and 72 deletions.
76 changes: 4 additions & 72 deletions pkg/sqlutil/test_data_source.go
Original file line number Diff line number Diff line change
@@ -1,85 +1,17 @@
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")
// NewInMemoryDataSource returns a new in-memory DataSource
func NewInMemoryDataSource(t *testing.T) *sqlx.DB {
db, err := sqlx.Open("ramsql", t.Name())
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, db.Close()) })
return &TestDataSource{db: db}
return db
}

0 comments on commit 5ca1a71

Please sign in to comment.