Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Sherlock | 41,431 | 4 days ago | 2 | February 25, 2019 | 137 | mit | Python | |||
🔎 Hunt down social media accounts by username across social networks | ||||||||||
Kind | 11,594 | 280 | 3 days ago | 163 | September 22, 2022 | 130 | apache-2.0 | Go | ||
Kubernetes IN Docker - local clusters for testing Kubernetes | ||||||||||
Gitignore.io | 7,606 | a month ago | 7 | mit | Swift | |||||
Create useful .gitignore files for your project | ||||||||||
Testcontainers Java | 7,117 | 431 | 396 | 2 days ago | 79 | June 29, 2022 | 555 | mit | Java | |
Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container. | ||||||||||
Frameworkbenchmarks | 6,978 | a day ago | 121 | other | Java | |||||
Source for the TechEmpower Framework Benchmarks project | ||||||||||
Terratest | 6,875 | 116 | 3 days ago | 364 | September 08, 2022 | 225 | apache-2.0 | Go | ||
Terratest is a Go library that makes it easier to write automated tests for your infrastructure code. | ||||||||||
Goss | 5,166 | 21 hours ago | 50 | apache-2.0 | Go | |||||
Quick and Easy server testing/validation | ||||||||||
Node Express Mongoose Demo | 5,070 | 1 | 19 days ago | 1 | January 18, 2016 | 3 | mit | JavaScript | ||
A simple demo app using node and mongodb for beginners (with docker) | ||||||||||
Boulder | 4,630 | 1 | a day ago | 76 | April 24, 2021 | 187 | mpl-2.0 | Go | ||
An ACME-based certificate authority, written in Go. | ||||||||||
Maildev | 3,985 | 54 | 26 | 3 months ago | 44 | May 18, 2022 | 111 | other | SCSS | |
:mailbox: SMTP Server + Web Interface for viewing and testing emails during development. |
Use Docker to run your Go language integration tests against third party services on Microsoft Windows, Mac OSX and Linux! Dockertest uses Docker to spin up images on Windows and Mac OSX as well. Dockertest is based on docker.go from camlistore.
IMPORTANT
We strongly encourage you to move to dockertest v3 for new and existing projects. It has a much cleaner API, less dependencies and is less prone to errors. V3 will be eventually merged into master.
Dockertest currently supports these backends:
Table of Contents
When developing applications, it is often necessary to use services that talk to a database system. Unit Testing these services can be cumbersome because mocking database/DBAL is strenuous. Making slight changes to the schema implies rewriting at least some, if not all of the mocks. The same goes for API changes in the DBAL. To avoid this, it is smarter to test these specific services against a real database that is destroyed after testing. Docker is the perfect system for running unit tests as you can spin up containers in a few seconds and kill them when the test completes. The Dockertest library provides easy to use commands for spinning up Docker containers and using them for your tests.
Using Dockertest is straightforward and simple. Check the releases tab for available releases.
To install dockertest, run
go get gopkg.in/ory-am/dockertest.vX
where X
is your desired version. For example:
go get gopkg.in/ory-am/dockertest.v2
Note:
When using the Docker Toolbox (Windows / OSX), make sure that the VM is started by running docker-machine start default
.
package main
import (
"gopkg.in/ory-am/dockertest.v2"
"gopkg.in/mgo.v2"
"time"
)
func main() {
var db *mgo.Session
c, err := dockertest.ConnectToMongoDB(15, time.Millisecond*500, func(url string) bool {
// This callback function checks if the image's process is responsive.
// Sometimes, docker images are booted but the process (in this case MongoDB) is still doing maintenance
// before being fully responsive which might cause issues like "TCP Connection reset by peer".
var err error
db, err = mgo.Dial(url)
if err != nil {
return false
}
// Sometimes, dialing the database is not enough because the port is already open but the process is not responsive.
// Most database conenctors implement a ping function which can be used to test if the process is responsive.
// Alternatively, you could execute a query to see if an error occurs or not.
return db.Ping() == nil
})
if err != nil {
log.Fatalf("Could not connect to database: %s", err)
}
// Close db connection and kill the container when we leave this function body.
defer db.Close()
defer c.KillRemove()
// The image is now responsive.
}
You can start PostgreSQL and MySQL in a similar fashion.
There are some cases where it's useful to test how your application/code handles remote resources failing / shutting down. For example, what if your database goes offline? Does your application handle it gracefully?
This can be tested by stopping and starting an existing container:
var hosts []string
c, err := ConnectToZooKeeper(15, time.Millisecond*500, func(url string) bool {
conn, _, err := zk.Connect([]string{url}, time.Second)
if err != nil {
return false
}
defer conn.Close()
hosts = []string{url}
return true
})
defer c.KillRemove()
conn, _, _ := zk.Connect(hosts, time.Second)
conn.Create("/test", []byte("hello"), 0, zk.WorldACL(zk.PermAll))
c.Stop()
_, _, err = zk.Get("/test") // err == zk.ErrNoServer
c.Start()
data, _, _ = zk.Get("/test") // data == []byte("hello")
It is also possible to start a custom container (in this example, a RabbitMQ container):
c, ip, port, err := dockertest.SetupCustomContainer("rabbitmq", 5672, 10*time.Second)
if err != nil {
log.Fatalf("Could not setup container: %s", err
}
defer c.KillRemove()
err = dockertest.ConnectToCustomContainer(fmt.Sprintf("%v:%v", ip, port), 15, time.Millisecond*500, func(url string) bool {
amqp, err := amqp.Dial(fmt.Sprintf("amqp://%v", url))
if err != nil {
return false
}
defer amqp.Close()
return true
})
...
It is a good idea to start up the container only once when running tests.
import (
"fmt"
"testing"
"log"
"os"
"database/sql"
_ "github.com/lib/pq"
"gopkg.in/ory-am/dockertest.v2"
)
var db *sql.DB
func TestMain(m *testing.M) {
c, err := dockertest.ConnectToPostgreSQL(15, time.Second, func(url string) bool {
// Check if postgres is responsive...
var err error
db, err = sql.Open("postgres", url)
if err != nil {
return false
}
return db.Ping() == nil
})
if err != nil {
log.Fatalf("Could not connect to database: %s", err)
}
// Execute tasks like setting up schemata.
// Run tests
result := m.Run()
// Close database connection.
db.Close()
// Clean up image.
c.KillRemove()
// Exit tests.
os.Exit(result)
}
func TestFunction(t *testing.T) {
// db.Exec(...
}
You can run the Docker integration on Travis easily:
# Sudo is required for docker
sudo: required
# Enable docker
services:
- docker
# In Travis, we need to bind to 127.0.0.1 in order to get a working connection. This environment variable
# tells dockertest to do that.
env:
- DOCKERTEST_BIND_LOCALHOST=true
You can specify a container version by setting environment variables or globals. For more information, check vars.go.
With v2, we removed all Open*
methods to reduce duplicate code, unnecessary dependencies and make maintenance easier.
If you relied on these, run go get gopkg.in/ory-am/dockertest.v1
and replace
import "github.com/ory-am/dockertest"
with import "gopkg.in/ory-am/dockertest.v1"
.
Try cleaning up the images with docker-cleanup-volumes.
First of all, consider upgrading! If that's not an option, there are some steps you need to take:
dockertest.UseDockerMachine = "1"
or set the environment variable DOCKERTEST_LEGACY_DOCKER_MACHINE=1
docker.BindDockerToLocalhost = ""
or alternatively DOCKER_BIND_LOCALHOST=
Sometimes container clean up fails. Check out this stackoverflow question on how to fix this.
I am using postgres (or mysql) driver, how do I use customized database instead of default one? You can alleviate this helper function to do that, see testcase or example below:
func TestMain(m *testing.M) {
if c, err := dockertest.ConnectToPostgreSQL(15, time.Second, func(url string) bool {
customizedDB := "cherry" // here I am connecting cherry database
newURL, err := SetUpPostgreDatabase(customizedDB, url)
// or use SetUpMysqlDatabase for mysql driver
if err != nil {
log.Fatal(err)
}
db, err := sql.Open("postgres", newURL)
if err != nil {
return false
}
return db.Ping() == nil
}); err != nil {
log.Fatal(err)
}