Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
59
pkg/validator/can_id_test.go
Normal file
59
pkg/validator/can_id_test.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package validator_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"fiskerinc.com/modules/testhelper"
|
||||
"fiskerinc.com/modules/validator"
|
||||
)
|
||||
|
||||
type TestCANID struct {
|
||||
Name string `validate:"can_id"`
|
||||
Expected string
|
||||
}
|
||||
|
||||
var canIDValidatorValidTests = []TestCANID{
|
||||
{Name: "1"},
|
||||
{Name: "123"},
|
||||
{Name: "123-456"},
|
||||
}
|
||||
|
||||
func TestValidateCANID(t *testing.T) {
|
||||
var tests = []TestCANID{
|
||||
{
|
||||
Name: "",
|
||||
Expected: "Key: 'TestCANID.Name' Error:Field validation for 'Name' failed on the 'can_id' tag",
|
||||
},
|
||||
{
|
||||
Name: "-",
|
||||
Expected: "Key: 'TestCANID.Name' Error:Field validation for 'Name' failed on the 'can_id' tag",
|
||||
},
|
||||
{
|
||||
Name: "-123",
|
||||
Expected: "Key: 'TestCANID.Name' Error:Field validation for 'Name' failed on the 'can_id' tag",
|
||||
},
|
||||
{
|
||||
Name: "abc",
|
||||
Expected: "Key: 'TestCANID.Name' Error:Field validation for 'Name' failed on the 'can_id' tag",
|
||||
},
|
||||
{
|
||||
Name: "ab12",
|
||||
Expected: "Key: 'TestCANID.Name' Error:Field validation for 'Name' failed on the 'can_id' tag",
|
||||
},
|
||||
{
|
||||
Name: "123-123-123",
|
||||
Expected: "Key: 'TestCANID.Name' Error:Field validation for 'Name' failed on the 'can_id' tag",
|
||||
},
|
||||
}
|
||||
|
||||
tests = append(tests, canIDValidatorValidTests...)
|
||||
|
||||
for _, test := range tests {
|
||||
err := validator.ValidateStruct(test)
|
||||
if err == nil && test.Expected != "" {
|
||||
t.Errorf(testhelper.TestErrorTemplate, test.Name, test.Expected, err)
|
||||
} else if err != nil && err.Error() != test.Expected {
|
||||
t.Errorf(testhelper.TestErrorTemplate, test.Name, test.Expected, err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user