sqlhelptest

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

package sqlhelptest contains helper functions for testing database functions.

Index

Constants

This section is empty.

Variables

View Source
var Driver = "postgres"

Driver that will be emulated for the mock db.

Functions

func InitMockDB

func InitMockDB(t *testing.T) (*sqlx.DB, sqlmock.Sqlmock)

InitMockDB returns a sqlx.DB and sqlmock.Sqlmock for testing. On cleanup, it will check if all expectations were met. Your t.Run may look like this:

t.Run("Test", func(t *testing.T) {
  db, mock := InitMockDB(t)
  expectFn(mock)
  // test your function
})

With the expectFn being a function that sets up the expectations for the mock (of type ExpectFunc), add it to your tests struct like so:

tests := []struct {
  name     string
  fields   fields
  args     args
  expectFn sqlhelptest.ExpectFunc
  want     int64
  wantErr  bool
} //...

func InitSqliteDB

func InitSqliteDB(t *testing.T) *sqlx.DB

Types

type ExpectFunc

type ExpectFunc func(mock sqlmock.Sqlmock)

ExpectFunc is a function that sets up the expectations for the mock.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL