how to mock DBs

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

InfluxDB - Purpose built for real-time analytics at any scale.
InfluxDB Platform is powered by columnar analytics, optimized for cost-efficient storage, and built with open data standards.
www.influxdata.com
featured
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured
  • dockertest

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

    This one looks cool!, I'll need to take a look to the documentation just to see if it satisfies our needs. I have been using an alternative library that seems to be more stable: https://github.com/ory/dockertest. I like it a lot and it has some good and complete documentation with examples included. Do you have any previous experience with this one or any other benchmark against testcontainers?

  • InfluxDB

    Purpose built for real-time analytics at any scale. InfluxDB Platform is powered by columnar analytics, optimized for cost-efficient storage, and built with open data standards.

    InfluxDB logo
  • gomock

    Discontinued GoMock is a mocking framework for the Go programming language. (by golang)

    In all other layers, my repositories are mocked using https://github.com/golang/mock

  • Testify

    A toolkit with common assertions and mocks that plays nicely with the standard library

    I usually use the testify (https://github.com/stretchr/testify) It can help you to mock your external components. For unit tests I see one way and it is not to allow external interaction (DBs, APIs, etc) while tests are going. Keep your project structure like the clean architecture (https://betterprogramming.pub/the-clean-architecture-beginners-guide-e4b7058c1165) and then, as a result, you will have opportunity to replace components and configure their behavior.

  • go

    The Go programming language

    Another approach if you want to stay at the DB level is to implement the Io/fs interface (https://pkg.go.dev/io/fs). It is currently only read-only but you can extend it with a write mode in your project (see https://github.com/golang/go/issues/45757).

  • postgres

    Docker Official Image packaging for Postgres (by docker-library)

    The docker file I used is basically this one except as I mention I hack out the VOLUME line, which makes it transient.

  • testcontainers-node

    Testcontainers is a NodeJS library that supports tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.

    I have used only testcontainers. I used it for the first time while working with Java, and then with NodeJS. When I came to know that a Golang version is available, I ended up using it since I'm now familiar with the framework irrespective of the language.

  • redismock

    Redis client Mock

    I used also other lib to mock different components like redis cache.

  • SaaSHub

    SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives

    SaaSHub logo
  • moq

    Interface mocking tool for go generate (by matryer)

    Just replaced mockery generated mocks with https://github.com/matryer/moq Alot cleaner imo at least for me

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

  • Testcontainers-Go: Effortless Container-Based Testing for Go Developers

    1 project | news.ycombinator.com | 14 Aug 2024
  • I Write Tests in Go

    1 project | news.ycombinator.com | 10 Apr 2024
  • Using test helpers in Go

    1 project | dev.to | 16 Feb 2024
  • 🚀 Effortless Integration Tests with Testcontainers in Golang 🧪

    2 projects | dev.to | 4 Sep 2023
  • Direction of mockery: absorb different styles of mocks into this project · vektra mockery · Discussion #671

    1 project | /r/golang | 11 Jul 2023

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