forked from moby/moby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore_test.go
64 lines (50 loc) · 2.06 KB
/
store_test.go
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
54
55
56
57
58
59
60
61
62
63
64
package plugin // import "github.com/docker/docker/plugin"
import (
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/plugingetter"
v2 "github.com/docker/docker/plugin/v2"
)
func TestFilterByCapNeg(t *testing.T) {
p := v2.Plugin{PluginObj: types.Plugin{Name: "test:latest"}}
iType := types.PluginInterfaceType{Capability: "volumedriver", Prefix: "docker", Version: "1.0"}
i := types.PluginConfigInterface{Socket: "plugins.sock", Types: []types.PluginInterfaceType{iType}}
p.PluginObj.Config.Interface = i
_, err := p.FilterByCap("foobar")
if err == nil {
t.Fatalf("expected inadequate error, got %v", err)
}
}
func TestFilterByCapPos(t *testing.T) {
p := v2.Plugin{PluginObj: types.Plugin{Name: "test:latest"}}
iType := types.PluginInterfaceType{Capability: "volumedriver", Prefix: "docker", Version: "1.0"}
i := types.PluginConfigInterface{Socket: "plugins.sock", Types: []types.PluginInterfaceType{iType}}
p.PluginObj.Config.Interface = i
_, err := p.FilterByCap("volumedriver")
if err != nil {
t.Fatalf("expected no error, got %v", err)
}
}
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)
}
}