Skip to content

Commit

Permalink
Change dockerIs* to accept *testing.T for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
cbednarski committed Nov 11, 2015
1 parent 4b071f6 commit fdd21d3
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions client/driver/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package driver
import (
"fmt"
"io/ioutil"
"log"
"path/filepath"
"reflect"
"testing"
Expand All @@ -22,23 +21,23 @@ func testDockerDriverContext(task string) *DriverContext {
}

// dockerIsConnected checks to see if a docker daemon is available (local or remote)
func dockerIsConnected() bool {
func dockerIsConnected(t *testing.T) bool {
client, err := docker.NewClientFromEnv()
if err != nil {
return false
}

env, err := client.Version()
if err != nil {
log.Printf("[TEST] Failed")
t.Logf("Failed to connect to docker daemon: %s", err)
return false
}

log.Printf("[TEST] Successfully connected to docker daemon running version %s", env.Get("Version"))
t.Logf("Successfully connected to docker daemon running version %s", env.Get("Version"))
return true
}

func dockerIsRemote() bool {
func dockerIsRemote(t *testing.T) bool {
client, err := docker.NewClientFromEnv()
if err != nil {
return false
Expand Down Expand Up @@ -77,17 +76,17 @@ func TestDockerDriver_Fingerprint(t *testing.T) {
if err != nil {
t.Fatalf("err: %v", err)
}
if apply != dockerIsConnected() {
t.Fatalf("Fingerprinter should detect Docker when it is installed")
if apply != dockerIsConnected(t) {
t.Fatalf("Fingerprinter should detect when docker is available")
}
if node.Attributes["driver.docker"] != "1" {
t.Log("Docker not found. The remainder of the docker tests will be skipped.")
t.Log("Docker daemon not available. The remainder of the docker tests will be skipped.")
}
t.Logf("Found docker version %s", node.Attributes["driver.docker.version"])
}

func TestDockerDriver_StartOpen_Wait(t *testing.T) {
if !dockerIsConnected() {
if !dockerIsConnected(t) {
t.SkipNow()
}

Expand Down Expand Up @@ -124,7 +123,7 @@ func TestDockerDriver_StartOpen_Wait(t *testing.T) {
}

func TestDockerDriver_Start_Wait(t *testing.T) {
if !dockerIsConnected() {
if !dockerIsConnected(t) {
t.SkipNow()
}

Expand Down Expand Up @@ -172,7 +171,7 @@ func TestDockerDriver_Start_Wait(t *testing.T) {
}

func TestDockerDriver_Start_Wait_AllocDir(t *testing.T) {
if !dockerIsConnected() || dockerIsRemote() {
if !dockerIsConnected(t) || dockerIsRemote(t) {
t.SkipNow()
}

Expand Down Expand Up @@ -227,7 +226,7 @@ func TestDockerDriver_Start_Wait_AllocDir(t *testing.T) {
}

func TestDockerDriver_Start_Kill_Wait(t *testing.T) {
if !dockerIsConnected() {
if !dockerIsConnected(t) {
t.SkipNow()
}

Expand Down Expand Up @@ -294,7 +293,7 @@ func taskTemplate() *structs.Task {
}

func TestDocker_StartN(t *testing.T) {
if !dockerIsConnected() {
if !dockerIsConnected(t) {
t.SkipNow()
}

Expand Down Expand Up @@ -345,7 +344,7 @@ func TestDocker_StartN(t *testing.T) {
}

func TestDocker_StartNVersions(t *testing.T) {
if !dockerIsConnected() {
if !dockerIsConnected(t) {
t.SkipNow()
}

Expand Down Expand Up @@ -399,7 +398,7 @@ func TestDocker_StartNVersions(t *testing.T) {
}

func TestDockerHostNet(t *testing.T) {
if !dockerIsConnected() {
if !dockerIsConnected(t) {
t.SkipNow()
}

Expand Down

0 comments on commit fdd21d3

Please sign in to comment.