Mocking database queries - ask for opinion

This page summarizes the projects mentioned and recommended in the original post on /r/golang

Stream - Scalable APIs for Chat, Feeds, Moderation, & Video.
Stream helps developers build engaging apps that scale to millions with performant and flexible Chat, Feeds, Moderation, and Video APIs and SDKs powered by a global edge network and enterprise-grade infrastructure.
getstream.io
featured
InfluxDB – Built for High-Performance Time Series Workloads
InfluxDB 3 OSS is now GA. Transform, enrich, and act on time series data directly in the database. Automate critical tasks and eliminate the need to move data externally. Download now.
www.influxdata.com
featured
  1. go-sqlmock

    Sql mock driver for golang to test database interactions

    I use https://github.com/DATA-DOG/go-sqlmock for unit testing my data layer code. Most of the times, these tests help me to find errors whenever I do a refactor on the data layer, so I consider it a good safety net

  2. Stream

    Stream - Scalable APIs for Chat, Feeds, Moderation, & Video. Stream helps developers build engaging apps that scale to millions with performant and flexible Chat, Feeds, Moderation, and Video APIs and SDKs powered by a global edge network and enterprise-grade infrastructure.

    Stream logo
  3. dockertest

    Write better integration tests! Dockertest helps you boot up ephermal docker images for your Go tests with minimal work.

    I use github.com/ory/dockertest to setup the database in a Docker container when the tests run, so a simple go test . works perfectly no extra steps needed (besides having Docker running in the background, most CI/CD envs should have it already).

  4. go-sdk

    Official Keploy Go SDK 🔵 (by keploy)

    The same idea was used to generate and mock sql queries in keploy - https://github.com/keploy/go-sdk/tree/main/integrations/ksql

  5. bats-core

    Bash Automated Testing System

    We even use bats to run full integration tests with other systems at the end.

  6. pkgsite

    [mirror] Home of the pkg.go.dev website

    Let's look at some real codebase for an example on how to write database tests without mocking. The source code for the Go package discovery site(https://pkg.go.dev/) is available at[1] That site uses postgres as its primary database[2]. The database package has a method called GetLatestInfo[3] that fetches the latest versions of a module. That method is called from the frontend http handlers[4] via an interface[5] When it comes to testing that frontend handler, you would expect the tests to use a mock implementation of that interface method. But that's not what they do, instead they use a real postgres database in the test[6].

  7. InfluxDB

    InfluxDB – Built for High-Performance Time Series Workloads. InfluxDB 3 OSS is now GA. Transform, enrich, and act on time series data directly in the database. Automate critical tasks and eliminate the need to move data externally. Download now.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Gokiburi: Automatic Test Runs for Go Projects

    5 projects | /r/golang | 7 May 2023
  • Do you prefer go-convey over golang's t.Run?

    2 projects | /r/golang | 23 Apr 2021
  • fluentassert - a prototype of yet another assertion library

    7 projects | /r/golang | 28 Mar 2021
  • Systems Correctness Practices at Amazon Web Services

    8 projects | news.ycombinator.com | 30 May 2025
  • Take it easy with Graphite and Docker 🐳

    2 projects | dev.to | 28 May 2025

Did you know that Go is
the 4th most popular programming language
based on number of references?