52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package validator_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/fiskerinc/cloud-services/pkg/testhelper"
|
|
"github.com/fiskerinc/cloud-services/pkg/validator"
|
|
)
|
|
|
|
type TestFleet struct {
|
|
Name string `validate:"fleet"`
|
|
Expected string
|
|
}
|
|
|
|
var fleetValidatorValidTests = []TestFleet{
|
|
{Name: "t"},
|
|
{Name: "test"},
|
|
{Name: "Test"},
|
|
{Name: "TEST"},
|
|
{Name: "test1"},
|
|
{Name: "1test"},
|
|
{Name: "test-test"},
|
|
}
|
|
|
|
func TestValidateFleetName(t *testing.T) {
|
|
var tests = []TestFleet{
|
|
{
|
|
Name: "",
|
|
Expected: "Key: 'TestFleet.Name' Error:Field validation for 'Name' failed on the 'fleet' tag",
|
|
},
|
|
{
|
|
Name: "$test",
|
|
Expected: "Key: 'TestFleet.Name' Error:Field validation for 'Name' failed on the 'fleet' tag",
|
|
},
|
|
{
|
|
Name: "test test",
|
|
Expected: "Key: 'TestFleet.Name' Error:Field validation for 'Name' failed on the 'fleet' tag",
|
|
},
|
|
}
|
|
|
|
tests = append(tests, fleetValidatorValidTests...)
|
|
|
|
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())
|
|
}
|
|
}
|
|
}
|