github.com/afbjorklund/moby@v20.10.5+incompatible/plugin/store_test.go (about)

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