Browse code

Windows CI: test-unit on pkg\plugins

Signed-off-by: John Howard <jhoward@microsoft.com>

John Howard authored on 2016/02/11 11:32:27
Showing 2 changed files
... ...
@@ -1,16 +1,13 @@
1 1
 package plugins
2 2
 
3 3
 import (
4
-	"fmt"
5 4
 	"io/ioutil"
6
-	"net"
7 5
 	"os"
8 6
 	"path/filepath"
9
-	"reflect"
10 7
 	"testing"
11 8
 )
12 9
 
13
-func setup(t *testing.T) (string, func()) {
10
+func Setup(t *testing.T) (string, func()) {
14 11
 	tmpdir, err := ioutil.TempDir("", "docker-test")
15 12
 	if err != nil {
16 13
 		t.Fatal(err)
... ...
@@ -25,56 +22,8 @@ func setup(t *testing.T) (string, func()) {
25 25
 	}
26 26
 }
27 27
 
28
-func TestLocalSocket(t *testing.T) {
29
-	tmpdir, unregister := setup(t)
30
-	defer unregister()
31
-
32
-	cases := []string{
33
-		filepath.Join(tmpdir, "echo.sock"),
34
-		filepath.Join(tmpdir, "echo", "echo.sock"),
35
-	}
36
-
37
-	for _, c := range cases {
38
-		if err := os.MkdirAll(filepath.Dir(c), 0755); err != nil {
39
-			t.Fatal(err)
40
-		}
41
-
42
-		l, err := net.Listen("unix", c)
43
-		if err != nil {
44
-			t.Fatal(err)
45
-		}
46
-
47
-		r := newLocalRegistry()
48
-		p, err := r.Plugin("echo")
49
-		if err != nil {
50
-			t.Fatal(err)
51
-		}
52
-
53
-		pp, err := r.Plugin("echo")
54
-		if err != nil {
55
-			t.Fatal(err)
56
-		}
57
-		if !reflect.DeepEqual(p, pp) {
58
-			t.Fatalf("Expected %v, was %v\n", p, pp)
59
-		}
60
-
61
-		if p.Name != "echo" {
62
-			t.Fatalf("Expected plugin `echo`, got %s\n", p.Name)
63
-		}
64
-
65
-		addr := fmt.Sprintf("unix://%s", c)
66
-		if p.Addr != addr {
67
-			t.Fatalf("Expected plugin addr `%s`, got %s\n", addr, p.Addr)
68
-		}
69
-		if p.TLSConfig.InsecureSkipVerify != true {
70
-			t.Fatalf("Expected TLS verification to be skipped")
71
-		}
72
-		l.Close()
73
-	}
74
-}
75
-
76 28
 func TestFileSpecPlugin(t *testing.T) {
77
-	tmpdir, unregister := setup(t)
29
+	tmpdir, unregister := Setup(t)
78 30
 	defer unregister()
79 31
 
80 32
 	cases := []struct {
... ...
@@ -83,6 +32,7 @@ func TestFileSpecPlugin(t *testing.T) {
83 83
 		addr string
84 84
 		fail bool
85 85
 	}{
86
+		// TODO Windows: Factor out the unix:// varients.
86 87
 		{filepath.Join(tmpdir, "echo.spec"), "echo", "unix://var/lib/docker/plugins/echo.sock", false},
87 88
 		{filepath.Join(tmpdir, "echo", "echo.spec"), "echo", "unix://var/lib/docker/plugins/echo.sock", false},
88 89
 		{filepath.Join(tmpdir, "foo.spec"), "foo", "tcp://localhost:8080", false},
... ...
@@ -123,7 +73,7 @@ func TestFileSpecPlugin(t *testing.T) {
123 123
 }
124 124
 
125 125
 func TestFileJSONSpecPlugin(t *testing.T) {
126
-	tmpdir, unregister := setup(t)
126
+	tmpdir, unregister := Setup(t)
127 127
 	defer unregister()
128 128
 
129 129
 	p := filepath.Join(tmpdir, "example.json")
130 130
new file mode 100644
... ...
@@ -0,0 +1,61 @@
0
+// +build !windows
1
+
2
+package plugins
3
+
4
+import (
5
+	"fmt"
6
+	"net"
7
+	"os"
8
+	"path/filepath"
9
+	"reflect"
10
+	"testing"
11
+)
12
+
13
+func TestLocalSocket(t *testing.T) {
14
+	// TODO Windows: Enable a similar version for Windows named pipes
15
+	tmpdir, unregister := Setup(t)
16
+	defer unregister()
17
+
18
+	cases := []string{
19
+		filepath.Join(tmpdir, "echo.sock"),
20
+		filepath.Join(tmpdir, "echo", "echo.sock"),
21
+	}
22
+
23
+	for _, c := range cases {
24
+		if err := os.MkdirAll(filepath.Dir(c), 0755); err != nil {
25
+			t.Fatal(err)
26
+		}
27
+
28
+		l, err := net.Listen("unix", c)
29
+		if err != nil {
30
+			t.Fatal(err)
31
+		}
32
+
33
+		r := newLocalRegistry()
34
+		p, err := r.Plugin("echo")
35
+		if err != nil {
36
+			t.Fatal(err)
37
+		}
38
+
39
+		pp, err := r.Plugin("echo")
40
+		if err != nil {
41
+			t.Fatal(err)
42
+		}
43
+		if !reflect.DeepEqual(p, pp) {
44
+			t.Fatalf("Expected %v, was %v\n", p, pp)
45
+		}
46
+
47
+		if p.Name != "echo" {
48
+			t.Fatalf("Expected plugin `echo`, got %s\n", p.Name)
49
+		}
50
+
51
+		addr := fmt.Sprintf("unix://%s", c)
52
+		if p.Addr != addr {
53
+			t.Fatalf("Expected plugin addr `%s`, got %s\n", addr, p.Addr)
54
+		}
55
+		if p.TLSConfig.InsecureSkipVerify != true {
56
+			t.Fatalf("Expected TLS verification to be skipped")
57
+		}
58
+		l.Close()
59
+	}
60
+}