diff --git a/validation.go b/validation.go index d6ebf30..ea70fd4 100644 --- a/validation.go +++ b/validation.go @@ -134,6 +134,14 @@ func GreaterThan(param int, comparativeVal int, paramName string) Checker { } } +func StringNotEmpty(obtained, paramName string) Checker { + return func() (isNotEmpty bool, errMsg string) { + isNotEmpty = obtained != "" + errMsg = fmt.Sprintf("Parameter is an empty string: %s", paramName) + return + } +} + func validationFactory(numErrors int) *Validation { return &Validation{make([]string, numErrors)} } diff --git a/validation_test.go b/validation_test.go index 650cd99..211a115 100644 --- a/validation_test.go +++ b/validation_test.go @@ -155,3 +155,15 @@ func TestGreaterThan(t *testing.T) { t.FailNow() } } + +func TestStringNotEmpty(t *testing.T) { + + err := BeginValidation().Validate( + StringNotEmpty("", "tmpA"), + ).Check() + + if err == nil { + t.Errorf("Expected an error.") + t.FailNow() + } +}