github.com/lzy4123/fabric@v2.1.1+incompatible/core/chaincode/persistence/label_test.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package persistence
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/stretchr/testify/assert"
    13  	"github.com/stretchr/testify/require"
    14  )
    15  
    16  func TestLabels(t *testing.T) {
    17  	tests := []struct {
    18  		label   string
    19  		success bool
    20  	}{
    21  		{label: "", success: false},
    22  		{label: ".", success: false},
    23  		{label: "0", success: true},
    24  		{label: ":", success: false},
    25  		{label: "_", success: false},
    26  		{label: "a", success: true},
    27  		{label: "a#", success: false},
    28  		{label: "a$", success: false},
    29  		{label: "a%", success: false},
    30  		{label: "a++b", success: true},
    31  		{label: "a+b", success: true},
    32  		{label: "a+bb", success: true},
    33  		{label: "a-", success: true},
    34  		{label: "a--b", success: true},
    35  		{label: "a-b", success: true},
    36  		{label: "a-bb", success: true},
    37  		{label: "a.b", success: true},
    38  		{label: "a::b", success: false},
    39  		{label: "a:b", success: false},
    40  		{label: "a__b", success: true},
    41  		{label: "a_b", success: true},
    42  		{label: "a a", success: false},
    43  		{label: "a_bb", success: true},
    44  		{label: "aa", success: true},
    45  		{label: "v1.0.0", success: true},
    46  	}
    47  
    48  	for _, tt := range tests {
    49  		t.Run(tt.label, func(t *testing.T) {
    50  			err := ValidateLabel(tt.label)
    51  			if tt.success {
    52  				assert.NoError(t, err)
    53  			} else {
    54  				require.Error(t, err)
    55  				assert.Contains(t, err.Error(), tt.label)
    56  			}
    57  		})
    58  	}
    59  }