56 lines
994 B
Go
56 lines
994 B
Go
package card
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestValidate(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
number string
|
|
wantErr error
|
|
}{
|
|
{
|
|
name: "empty card number",
|
|
number: "",
|
|
wantErr: ErrCardRequired,
|
|
},
|
|
{
|
|
name: "card number is too short",
|
|
number: "123456789",
|
|
wantErr: ErrCardLength,
|
|
},
|
|
{
|
|
name: "card number is too long",
|
|
number: "12345678901234567",
|
|
wantErr: ErrCardLength,
|
|
},
|
|
{
|
|
name: "card number contains letters",
|
|
number: "603799ABC4567890",
|
|
wantErr: ErrCardNumeric,
|
|
},
|
|
{
|
|
name: "card number contains spaces",
|
|
number: "6037 912 3456 78",
|
|
wantErr: ErrCardNumeric,
|
|
},
|
|
{
|
|
name: "valid card number structure",
|
|
number: "6037991234567890",
|
|
wantErr: nil,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := Validate(tt.number)
|
|
|
|
if !errors.Is(err, tt.wantErr) {
|
|
t.Errorf("Validate() error = %v, want %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|