Initial cloud-services repo - gateway service + pkg modules

This commit is contained in:
Chris Rai
2026-01-30 23:14:52 -05:00
commit fbb820d7b3
1037 changed files with 171318 additions and 0 deletions

View 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())
}
}
}