Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Add ability to skip tests that require Docker #1251

Merged
merged 1 commit into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controllers/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestPingWithRedis(t *testing.T) {
// Create a request
response, request := NewTestRequest("GET", "/ping", nil)
// Start up redis.
redisURI, cleanUpRedis, pauseRedis, unapuaseRedis := CreateTestRedis()
redisURI, cleanUpRedis, pauseRedis, unapuaseRedis := CreateTestRedis(t)
os.Setenv("REDIS_URI", redisURI)
// Remove redis when finished.
defer cleanUpRedis()
Expand Down
14 changes: 12 additions & 2 deletions helpers/testhelpers/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/url"
"os"
"strings"
"testing"

dockerclient "github.com/fsouza/go-dockerclient"
"github.com/garyburd/redigo/redis"
Expand Down Expand Up @@ -45,9 +46,17 @@ func connectToDockerNetwork(pool *dockertest.Pool,
return "", false
}

// skipIfNoDocker will detect if Docker is unable to run, and if not, will skip the test
func skipIfNoDocker(t *testing.T) {
if os.Getenv("SKIP_DOCKER") == "1" {
t.Skip("No support for docker")
}
}

// CreateTestRedis creates a actual redis instance with docker.
// Useful for unit tests.
func CreateTestRedis() (string, func(), func(), func()) {
func CreateTestRedis(t *testing.T) (string, func(), func(), func()) {
skipIfNoDocker(t)
pool, err := dockertest.NewPool("")
if err != nil {
log.Fatalf("Could not connect to docker: %s", err)
Expand Down Expand Up @@ -89,7 +98,8 @@ func CreateTestRedis() (string, func(), func(), func()) {

// CreateTestMailCatcher creates a actual redis instance with docker.
// Useful for unit tests.
func CreateTestMailCatcher() (string, string, string, func()) {
func CreateTestMailCatcher(t *testing.T) (string, string, string, func()) {
skipIfNoDocker(t)
pool, err := dockertest.NewPool("")
if err != nil {
log.Fatalf("Could not connect to docker: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion mailer/mailer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestSendEmail(t *testing.T) {
hostname, smtpPort, apiPort, cleanup := CreateTestMailCatcher()
hostname, smtpPort, apiPort, cleanup := CreateTestMailCatcher(t)
// Test InitSMTPMailer with valid path for templates.
settings := helpers.Settings{
BasePath: os.Getenv(helpers.BasePathEnvVar),
Expand Down