10 func Setup(t *testing.T) (string, func()) {
11 tmpdir, err := ioutil.TempDir("", "docker-test")
17 specsPaths = []string{tmpdir}
19 return tmpdir, func() {
25 func TestFileSpecPlugin(t *testing.T) {
26 tmpdir, unregister := Setup(t)
35 // TODO Windows: Factor out the unix:// variants.
36 {filepath.Join(tmpdir, "echo.spec"), "echo", "unix://var/lib/docker/plugins/echo.sock", false},
37 {filepath.Join(tmpdir, "echo", "echo.spec"), "echo", "unix://var/lib/docker/plugins/echo.sock", false},
38 {filepath.Join(tmpdir, "foo.spec"), "foo", "tcp://localhost:8080", false},
39 {filepath.Join(tmpdir, "foo", "foo.spec"), "foo", "tcp://localhost:8080", false},
40 {filepath.Join(tmpdir, "bar.spec"), "bar", "localhost:8080", true}, // unknown transport
43 for _, c := range cases {
44 if err := os.MkdirAll(filepath.Dir(c.path), 0755); err != nil {
47 if err := ioutil.WriteFile(c.path, []byte(c.addr), 0644); err != nil {
51 r := newLocalRegistry()
52 p, err := r.Plugin(c.name)
53 if c.fail && err == nil {
62 t.Fatalf("Expected plugin `%s`, got %s\n", c.name, p.name)
66 t.Fatalf("Expected plugin addr `%s`, got %s\n", c.addr, p.Addr)
69 if !p.TLSConfig.InsecureSkipVerify {
70 t.Fatalf("Expected TLS verification to be skipped")
75 func TestFileJSONSpecPlugin(t *testing.T) {
76 tmpdir, unregister := Setup(t)
79 p := filepath.Join(tmpdir, "example.json")
81 "Name": "plugin-example",
82 "Addr": "https://example.com/docker/plugin",
84 "CAFile": "/usr/shared/docker/certs/example-ca.pem",
85 "CertFile": "/usr/shared/docker/certs/example-cert.pem",
86 "KeyFile": "/usr/shared/docker/certs/example-key.pem"
90 if err := ioutil.WriteFile(p, []byte(spec), 0644); err != nil {
94 r := newLocalRegistry()
95 plugin, err := r.Plugin("example")
100 if expected, actual := "example", plugin.name; expected != actual {
101 t.Fatalf("Expected plugin %q, got %s\n", expected, actual)
104 if plugin.Addr != "https://example.com/docker/plugin" {
105 t.Fatalf("Expected plugin addr `https://example.com/docker/plugin`, got %s\n", plugin.Addr)
108 if plugin.TLSConfig.CAFile != "/usr/shared/docker/certs/example-ca.pem" {
109 t.Fatalf("Expected plugin CA `/usr/shared/docker/certs/example-ca.pem`, got %s\n", plugin.TLSConfig.CAFile)
112 if plugin.TLSConfig.CertFile != "/usr/shared/docker/certs/example-cert.pem" {
113 t.Fatalf("Expected plugin Certificate `/usr/shared/docker/certs/example-cert.pem`, got %s\n", plugin.TLSConfig.CertFile)
116 if plugin.TLSConfig.KeyFile != "/usr/shared/docker/certs/example-key.pem" {
117 t.Fatalf("Expected plugin Key `/usr/shared/docker/certs/example-key.pem`, got %s\n", plugin.TLSConfig.KeyFile)
121 func TestFileJSONSpecPluginWithoutTLSConfig(t *testing.T) {
122 tmpdir, unregister := Setup(t)
125 p := filepath.Join(tmpdir, "example.json")
127 "Name": "plugin-example",
128 "Addr": "https://example.com/docker/plugin"
131 if err := ioutil.WriteFile(p, []byte(spec), 0644); err != nil {
135 r := newLocalRegistry()
136 plugin, err := r.Plugin("example")
141 if expected, actual := "example", plugin.name; expected != actual {
142 t.Fatalf("Expected plugin %q, got %s\n", expected, actual)
145 if plugin.Addr != "https://example.com/docker/plugin" {
146 t.Fatalf("Expected plugin addr `https://example.com/docker/plugin`, got %s\n", plugin.Addr)
149 if plugin.TLSConfig != nil {
150 t.Fatalf("Expected plugin TLSConfig nil, got %v\n", plugin.TLSConfig)