53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package validator_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/fiskerinc/cloud-services/pkg/testhelper"
|
|
"github.com/fiskerinc/cloud-services/pkg/validator"
|
|
)
|
|
|
|
func TestValidateVinCheckDigit(t *testing.T) {
|
|
// these should pass vin regex validation
|
|
//otherwise that error would be received here and the test run would fail because of expected tag name mismatch
|
|
tests := []TestCar{
|
|
{
|
|
VIN: "WVWBN7AN1DE546002",
|
|
//Expected: "Key: 'Error:Field' Error:Field validation for 'VIN' failed on the 'vincheck' tag",
|
|
Expected: "Key: '' Error:Field validation for '' failed on the 'vincheck' tag",
|
|
},
|
|
{
|
|
VIN: "WVWBC7AN1DE546002",
|
|
//Expected: "Key: 'Error:Field' Error:Field validation for 'VIN' failed on the 'vincheck' tag",
|
|
Expected: "Key: '' Error:Field validation for '' failed on the 'vincheck' tag",
|
|
},
|
|
}
|
|
|
|
tests = append(tests, vinValidatorValidTests...)
|
|
|
|
for _, test := range tests {
|
|
err := validator.ValidateField(test.VIN, "vincheck")
|
|
if err == nil && test.Expected != "" {
|
|
t.Errorf(testhelper.TestErrorTemplate, test.VIN, test.Expected, err)
|
|
} else if err != nil && err.Error() != test.Expected {
|
|
t.Errorf(testhelper.TestErrorTemplate, test.VIN, test.Expected, err.Error())
|
|
}
|
|
fmt.Println(test, err)
|
|
}
|
|
}
|
|
|
|
var vwGer2013Valid = "WVWBN7AN6DE546002"
|
|
var vwGer2013Invalid1 = "WVWBN7AN1DE546002"
|
|
var vwGer2013Invalid2 = "WVWBN7AN6DE54600"
|
|
var miniGer2009Valid = "WMWMS335X9TY38985"
|
|
var bugatFra1998Valid = "VF9SP3V31JM795073"
|
|
var dodgeUsa1998Valid = "1B3ES42C4WD736523"
|
|
|
|
// TEMP
|
|
var fskUsa2021Valid = "1F1BN7AN7MA000001"
|
|
|
|
// TEMP
|
|
|
|
//var unkJap2013Valid = "JS1GR7MA7D2101136"
|
|
//var audiGer2012Valid = "WAUFFAFM3CA000000" |