Skip to content

Sweep: Extend support for batch operation mocking / assertions #149

@acline443

Description

@acline443

Details

I may be misusing the library, so correct me if I am wrong. But I would like to write unit tests for functions that queue batches and then send the batch at the end. I would like to assert on the Updates/Insertions that are executed.

It seems to me like this is not currently supported as the SendBatch method does basically nothing:

func (c *pgxmock) SendBatch(context.Context, *pgx.Batch) pgx.BatchResults {
	return nil
}

Best assertion I can do is assert that the queued batch length is greater than 0.

Checklist
  • pgxmock.go
  • Add a new type ExpectedBatch with fields for the expected SQL statements and their arguments, and methods to set the expected results or errors.
    • Modify the SendBatch method to return mock batch results based on the queued expectations.
    • Add a new method ExpectBatch to the pgxmock type to queue an expected batch operation. This method should return an ExpectedBatch instance.
    • Update the ExpectationsWereMet method to also check if all expected batch operations were met.
  • pgxmock_test.go
  • Add unit tests for the new ExpectBatch method and the modified SendBatch method. These tests should cover various scenarios, including successful batch operations, batch operations that result in errors, and batch operations that do not meet the expectations.

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions