Skip to content

Commit

Permalink
Convert sqlutilmocks.DataSource -> sqlutil.TestDataSource using ramsq…
Browse files Browse the repository at this point in the history
…l driver
  • Loading branch information
reductionista committed Nov 8, 2024
1 parent 82733ac commit 4ccf9e8
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 86 deletions.
86 changes: 0 additions & 86 deletions pkg/sqlutil/mocks/data_source.go

This file was deleted.

87 changes: 87 additions & 0 deletions pkg/sqlutil/test_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package sqlutil

import (
"context"
"database/sql"
"testing"

"github.com/jmoiron/sqlx"
_ "github.com/proullon/ramsql/driver"

Check failure on line 9 in pkg/sqlutil/test_data_source.go

View workflow job for this annotation

GitHub Actions / build-test

no required module provides package github.com/proullon/ramsql/driver; to add it:
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
)

var _ sqlutil.DataSource = &TestDataSource{}

// TestDataSource is a simple in-memory DataSource type which can be used for some types of unit testing.
type TestDataSource struct {
db *sql.DB
}

// BindNamed provides a mock function with given fields: _a0, _a1
func (ds *TestDataSource) BindNamed(_a0 string, _a1 interface{}) (string, []interface{}, error) {
return "", nil, nil
}

// DriverName provides a mock function with given fields:
func (ds *TestDataSource) DriverName() string {
return ""
}

// 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 nil, nil
}

// 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 nil
}

// 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 nil, nil
}

// 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 (_m *TestDataSource) PrepareNamedContext(ctx context.Context, query string) (*sqlx.NamedStmt, error) {
return nil, nil
}

// 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 nil, nil
}

// 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 nil
}

// 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 nil, nil
}

// Rebind provides a mock function with given fields: _a0
func (ds *TestDataSource) Rebind(_a0 string) string {
return ""
}

// 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 nil
}

// NewTestDataSource creates a new instance of DataSource.
func NewTestDataSource(t *testing.T) *TestDataSource {
db, err := sql.Open("ramsql", "testdb")
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, db.Close()) })
return &TestDataSource{db: db}
}

0 comments on commit 4ccf9e8

Please sign in to comment.