github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/plugin/manager_test.go (about)

     1  package plugin
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/docker/docker/api/types"
     7  )
     8  
     9  func TestValidatePrivileges(t *testing.T) {
    10  	testData := map[string]struct {
    11  		requiredPrivileges types.PluginPrivileges
    12  		privileges         types.PluginPrivileges
    13  		result             bool
    14  	}{
    15  		"diff-len": {
    16  			requiredPrivileges: []types.PluginPrivilege{
    17  				{Name: "Privilege1", Description: "Description", Value: []string{"abc", "def", "ghi"}},
    18  			},
    19  			privileges: []types.PluginPrivilege{
    20  				{Name: "Privilege1", Description: "Description", Value: []string{"abc", "def", "ghi"}},
    21  				{Name: "Privilege2", Description: "Description", Value: []string{"123", "456", "789"}},
    22  			},
    23  			result: false,
    24  		},
    25  		"diff-value": {
    26  			requiredPrivileges: []types.PluginPrivilege{
    27  				{Name: "Privilege1", Description: "Description", Value: []string{"abc", "def", "GHI"}},
    28  				{Name: "Privilege2", Description: "Description", Value: []string{"123", "456", "***"}},
    29  			},
    30  			privileges: []types.PluginPrivilege{
    31  				{Name: "Privilege1", Description: "Description", Value: []string{"abc", "def", "ghi"}},
    32  				{Name: "Privilege2", Description: "Description", Value: []string{"123", "456", "789"}},
    33  			},
    34  			result: false,
    35  		},
    36  		"diff-order-but-same-value": {
    37  			requiredPrivileges: []types.PluginPrivilege{
    38  				{Name: "Privilege1", Description: "Description", Value: []string{"abc", "def", "GHI"}},
    39  				{Name: "Privilege2", Description: "Description", Value: []string{"123", "456", "789"}},
    40  			},
    41  			privileges: []types.PluginPrivilege{
    42  				{Name: "Privilege2", Description: "Description", Value: []string{"123", "456", "789"}},
    43  				{Name: "Privilege1", Description: "Description", Value: []string{"GHI", "abc", "def"}},
    44  			},
    45  			result: true,
    46  		},
    47  	}
    48  
    49  	for key, data := range testData {
    50  		err := validatePrivileges(data.requiredPrivileges, data.privileges)
    51  		if (err == nil) != data.result {
    52  			t.Fatalf("Test item %s expected result to be %t, got %t", key, data.result, (err == nil))
    53  		}
    54  	}
    55  }