github.com/technosophos/deis@v1.7.1-0.20150915173815-f9005256004b/builder/docker/docker_test.go (about)

     1  package docker
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/Masterminds/cookoo"
     9  	docli "github.com/fsouza/go-dockerclient"
    10  )
    11  
    12  func TestCleanup(t *testing.T) {
    13  	reg, router, cxt := cookoo.Cookoo()
    14  
    15  	tf, err := ioutil.TempFile("/tmp", "junkdockersock")
    16  	if err != nil {
    17  		t.Error("Could not create temp file for testing: " + err.Error())
    18  	}
    19  	DockSock = tf.Name()
    20  	tf.Close()
    21  
    22  	reg.Route("test", "Test route").
    23  		Does(Cleanup, "res")
    24  
    25  	if err := router.HandleRequest("test", cxt, true); err != nil {
    26  		t.Error(err)
    27  	}
    28  
    29  	// From the TempFile docs: "It is the caller's responsibility to remove the temp
    30  	// file." So we can reasonably assume that if the file's gone, it's because
    31  	// it was deleted by Cleanup.
    32  	if _, err := os.Stat(DockSock); err == nil {
    33  		t.Errorf("Expected file %s to be deleted, but got a stat.", DockSock)
    34  	}
    35  }
    36  
    37  func TestCreateClient(t *testing.T) {
    38  	reg, router, cxt := cookoo.Cookoo()
    39  
    40  	reg.Route("test", "Test route").
    41  		Does(CreateClient, "res").Using("url").WithDefault("http://example.com:4321")
    42  
    43  	if err := router.HandleRequest("test", cxt, true); err != nil {
    44  		t.Error(err)
    45  	}
    46  
    47  	if cli := cxt.Get("res", nil); cli == nil {
    48  		t.Error("Expected a client")
    49  	} else if _, ok := cli.(*docli.Client); !ok {
    50  		t.Error("Expected client to be a *docker.Cli")
    51  	}
    52  
    53  }