github.com/renegr87/renegr87@v2.1.1+incompatible/core/common/privdata/util_test.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package privdata
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/hyperledger/fabric-protos-go/peer"
    13  	"github.com/stretchr/testify/assert"
    14  )
    15  
    16  func TestGetPolicy(t *testing.T) {
    17  	accessPolicy, err := getPolicy(getAccessPolicy([]string{"signer0", "signer1"}), &mockDeserializer{})
    18  	assert.NotNil(t, accessPolicy)
    19  	assert.Nil(t, err)
    20  }
    21  
    22  func TestGetPolicyFailed(t *testing.T) {
    23  	// nil policy config
    24  	_, err := getPolicy(nil, &mockDeserializer{})
    25  	assert.EqualError(t, err, "collection policy config is nil")
    26  
    27  	// nil collectionPolicyConfig.GetSignaturePolicy()
    28  	_, err = getPolicy(&peer.CollectionPolicyConfig{}, &mockDeserializer{})
    29  	assert.EqualError(t, err, "collection config access policy is nil")
    30  
    31  	// faulty policy config: index out of range
    32  	_, err = getPolicy(getBadAccessPolicy([]string{"signer0", "signer1"}, 3), &mockDeserializer{})
    33  	assert.EqualError(t, err, "failed constructing policy object out of collection policy config: identity index out of range, requested 3, but identities length is 2")
    34  }