gnomock
go-sqlmock
gnomock | go-sqlmock | |
---|---|---|
5 | 19 | |
1,305 | 5,837 | |
- | 0.9% | |
3.4 | 5.4 | |
4 days ago | 28 days ago | |
Go | Go | |
MIT License | GNU General Public License v3.0 or later |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
gnomock
-
How to unit test your database interactions with Docker
https://github.com/orlangure/gnomock does this pretty well, but I liked your solution too, it is neat.
-
Writing tests for APIs
gnomock https://github.com/orlangure/gnomock - like testcontainers
- Python/Django to Golang questions
-
Beginner-friendly resources to learn integration tests for MongoDb based server.
Try gnomock (https://github.com/orlangure/gnomock). It creates a mongodb container with a random port which you can use from your go tests. See project readme for an example (it uses postgres but it is very similar to mongodb).
-
How to mock DB for unit tests?
You could check out Gnomock (https://github.com/orlangure/gnomock). It offers a different approach than what you asked, but maybe it'll suit your use case. It allows to easily setup a real DB like postgres in a docker container and then delete ot when tests are done.
go-sqlmock
- How do you unit-test code that reaches out to the db, without introducing interfaces everywhere?
-
Creating an API using Go and sqlc
For that, I used the lib go-sqlmock. So, for example, the following snippet is part of the person/service_test.go file:
-
Using SQLC in project how do I mock database Calls with it for unit testing?
It's not the right call IMO to skip mocking the database connection to achieve 100% test coverage. How your app will behave in failure scenarios that are impossible to imitate during integration tests is part of the software contract. If your choice is to panic, or return an error, document that by testing that behavior. If another dev, or future you inadvertently breaks the contract, the test suite will fail. That's what you want. For unit tests against your database you should be using either go-sqlmock if testing against database/sql or pgxmock if testing against pgx. That being said, the points raised elsewhere in this thread regarding unit tests potentially hiding edge cases in terms of how an actual database will interact with your application that are not reflective of your understanding when writing mocks are 100% valid. You should do both. Unit test your app and write integration tests as well. On my team, we run integration tests using docker-compose.
- What is the coolest Go open source projects you have seen?
- How to mock database calls
-
Can you set expectations for SQL transaction using Testify?
I use Sqlmock for that purpose
- Mocking database queries - ask for opinion
- SQL mock driver for Golang to test database interactions
- Can't get a specifc SQL query with pgx to work
-
[HELP] how to test this piece of code?
There is a good lib for db tests https://github.com/DATA-DOG/go-sqlmock
What are some alternatives?
ginkgo - A Modern Testing Framework for Go
gomock - GoMock is a mocking framework for the Go programming language.
dockertest - Write better integration tests! Dockertest helps you boot up ephermal docker images for your Go tests with minimal work.
go-txdb - Immutable transaction isolated sql driver for golang
twint-docker - Docker for Twint
mockery - A mock code autogenerator for Go
GoAws - AWS (SQS/SNS) Clone for Development testing
gock - HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽
assert - :exclamation:Basic Assertion Library used along side native go testing, with building blocks for custom assertions
minimock - Powerful mock generation tool for Go programming language
is - Professional lightweight testing mini-framework for Go.
gotests - Automatically generate Go test boilerplate from your source code.