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

Commit

Permalink
Merge pull request #1251 from govau/skipdocker
Browse files Browse the repository at this point in the history
Add ability to skip tests that require Docker
  • Loading branch information
jcscottiii authored Oct 10, 2017
2 parents 44c50d2 + 7989cc9 commit 99e85ed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
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

0 comments on commit 99e85ed

Please sign in to comment.