2018-02-05 21:05:59 +00:00
|
|
|
package plugin // import "github.com/docker/docker/plugin"
|
2016-10-25 23:12:56 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
2017-10-20 19:39:47 +00:00
|
|
|
"github.com/docker/docker/pkg/plugingetter"
|
2019-08-05 14:37:47 +00:00
|
|
|
v2 "github.com/docker/docker/plugin/v2"
|
2016-10-25 23:12:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestFilterByCapNeg(t *testing.T) {
|
2016-12-12 23:05:53 +00:00
|
|
|
p := v2.Plugin{PluginObj: types.Plugin{Name: "test:latest"}}
|
2017-03-20 08:27:51 +00:00
|
|
|
iType := types.PluginInterfaceType{Capability: "volumedriver", Prefix: "docker", Version: "1.0"}
|
|
|
|
i := types.PluginConfigInterface{Socket: "plugins.sock", Types: []types.PluginInterfaceType{iType}}
|
2016-11-08 02:51:47 +00:00
|
|
|
p.PluginObj.Config.Interface = i
|
2016-10-25 23:12:56 +00:00
|
|
|
|
|
|
|
_, err := p.FilterByCap("foobar")
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("expected inadequate error, got %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFilterByCapPos(t *testing.T) {
|
2016-12-12 23:05:53 +00:00
|
|
|
p := v2.Plugin{PluginObj: types.Plugin{Name: "test:latest"}}
|
2016-10-25 23:12:56 +00:00
|
|
|
|
2017-03-20 08:27:51 +00:00
|
|
|
iType := types.PluginInterfaceType{Capability: "volumedriver", Prefix: "docker", Version: "1.0"}
|
|
|
|
i := types.PluginConfigInterface{Socket: "plugins.sock", Types: []types.PluginInterfaceType{iType}}
|
2016-11-08 02:51:47 +00:00
|
|
|
p.PluginObj.Config.Interface = i
|
2016-10-25 23:12:56 +00:00
|
|
|
|
|
|
|
_, err := p.FilterByCap("volumedriver")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("expected no error, got %v", err)
|
|
|
|
}
|
|
|
|
}
|
2017-10-20 19:39:47 +00:00
|
|
|
|
|
|
|
func TestStoreGetPluginNotMatchCapRefs(t *testing.T) {
|
|
|
|
s := NewStore()
|
|
|
|
p := v2.Plugin{PluginObj: types.Plugin{Name: "test:latest"}}
|
|
|
|
|
|
|
|
iType := types.PluginInterfaceType{Capability: "whatever", Prefix: "docker", Version: "1.0"}
|
|
|
|
i := types.PluginConfigInterface{Socket: "plugins.sock", Types: []types.PluginInterfaceType{iType}}
|
|
|
|
p.PluginObj.Config.Interface = i
|
|
|
|
|
|
|
|
if err := s.Add(&p); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := s.Get("test", "volumedriver", plugingetter.Acquire); err == nil {
|
|
|
|
t.Fatal("exepcted error when getting plugin that doesn't match the passed in capability")
|
|
|
|
}
|
|
|
|
|
|
|
|
if refs := p.GetRefCount(); refs != 0 {
|
|
|
|
t.Fatalf("reference count should be 0, got: %d", refs)
|
|
|
|
}
|
|
|
|
|
|
|
|
p.PluginObj.Enabled = true
|
|
|
|
if _, err := s.Get("test", "volumedriver", plugingetter.Acquire); err == nil {
|
|
|
|
t.Fatal("exepcted error when getting plugin that doesn't match the passed in capability")
|
|
|
|
}
|
|
|
|
|
|
|
|
if refs := p.GetRefCount(); refs != 0 {
|
|
|
|
t.Fatalf("reference count should be 0, got: %d", refs)
|
|
|
|
}
|
|
|
|
}
|