github.com/artisanhe/tools@v1.0.1-0.20210607022958-19a8fef2eb04/validate/validatetpl/bank_card_test.go (about)

     1  package validatetpl
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestValidateBankCard(t *testing.T) {
     8  	type args struct {
     9  		v    interface{}
    10  		ok   bool
    11  		name string
    12  	}
    13  
    14  	testCases := []args{
    15  		{
    16  			name: "err",
    17  			v:    "31qadads",
    18  			ok:   false,
    19  		},
    20  		{
    21  			name: "length err",
    22  			v:    "12345678900",
    23  			ok:   false,
    24  		},
    25  		{
    26  			name: "length min",
    27  			v:    "123456789121",
    28  			ok:   true,
    29  		},
    30  		{
    31  			name: "length max",
    32  			v:    "1234567891234567891",
    33  			ok:   true,
    34  		},
    35  		{
    36  			name: "exec length max",
    37  			v:    "12345678912345678912",
    38  			ok:   false,
    39  		},
    40  	}
    41  
    42  	for _, tc := range testCases {
    43  		if ok, _ := ValidateBankCard(tc.v); ok != tc.ok {
    44  			t.Errorf("ValidateBankCard input:%s name:%s got:%v want:%v", tc.v, tc.name, ok, tc.ok)
    45  		}
    46  	}
    47  }