store_test.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package plugin // import "github.com/docker/docker/plugin"
  2. import (
  3. "testing"
  4. "github.com/docker/docker/api/types"
  5. "github.com/docker/docker/pkg/plugingetter"
  6. v2 "github.com/docker/docker/plugin/v2"
  7. )
  8. func TestFilterByCapNeg(t *testing.T) {
  9. p := v2.Plugin{PluginObj: types.Plugin{Name: "test:latest"}}
  10. iType := types.PluginInterfaceType{Capability: "volumedriver", Prefix: "docker", Version: "1.0"}
  11. i := types.PluginConfigInterface{Socket: "plugins.sock", Types: []types.PluginInterfaceType{iType}}
  12. p.PluginObj.Config.Interface = i
  13. _, err := p.FilterByCap("foobar")
  14. if err == nil {
  15. t.Fatalf("expected inadequate error, got %v", err)
  16. }
  17. }
  18. func TestFilterByCapPos(t *testing.T) {
  19. p := v2.Plugin{PluginObj: types.Plugin{Name: "test:latest"}}
  20. iType := types.PluginInterfaceType{Capability: "volumedriver", Prefix: "docker", Version: "1.0"}
  21. i := types.PluginConfigInterface{Socket: "plugins.sock", Types: []types.PluginInterfaceType{iType}}
  22. p.PluginObj.Config.Interface = i
  23. _, err := p.FilterByCap("volumedriver")
  24. if err != nil {
  25. t.Fatalf("expected no error, got %v", err)
  26. }
  27. }
  28. func TestStoreGetPluginNotMatchCapRefs(t *testing.T) {
  29. s := NewStore()
  30. p := v2.Plugin{PluginObj: types.Plugin{Name: "test:latest"}}
  31. iType := types.PluginInterfaceType{Capability: "whatever", Prefix: "docker", Version: "1.0"}
  32. i := types.PluginConfigInterface{Socket: "plugins.sock", Types: []types.PluginInterfaceType{iType}}
  33. p.PluginObj.Config.Interface = i
  34. if err := s.Add(&p); err != nil {
  35. t.Fatal(err)
  36. }
  37. if _, err := s.Get("test", "volumedriver", plugingetter.Acquire); err == nil {
  38. t.Fatal("exepcted error when getting plugin that doesn't match the passed in capability")
  39. }
  40. if refs := p.GetRefCount(); refs != 0 {
  41. t.Fatalf("reference count should be 0, got: %d", refs)
  42. }
  43. p.PluginObj.Enabled = true
  44. if _, err := s.Get("test", "volumedriver", plugingetter.Acquire); err == nil {
  45. t.Fatal("exepcted error when getting plugin that doesn't match the passed in capability")
  46. }
  47. if refs := p.GetRefCount(); refs != 0 {
  48. t.Fatalf("reference count should be 0, got: %d", refs)
  49. }
  50. }