jackc / jackc/pgx

Mock pgx rows

Open
#696 6 comments 2 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
14.3k
Forks
1.1k
Avg merge
6d 9h
Merged PRs (30d)
11

Description

We used sqlmock package to mock sql rows. we currently replaced database/sql with pgx package. We tried to replace sqlmock for pgx.rows. But we are not able to find any suitable code to replace this. Here is our sample code with sqlmock

func testMethod *sql.Rows {
db, mock, _ := sqlmock.New()
mockRows := sqlmock.NewRows([]string{"test"}).AddRow("1")
mock.ExpectQuery("select").WillReturnRows(mockRows)
rows, _ := db.Query("select")
defer db.Close()
return rows
}

Is any workaround for this??

Contributor guide

Open the contributing guide

Research direction

Start with the sample sqlmock-based test and compare it with the pgx rows and query APIs. Determine whether pgx has an existing way to mock rows or whether this requires a new testing facility; completion should identify a supported workaround or a documented implementation path.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
databases, testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.