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