From bfe9b50e828ad56312e486cbf4165ff1ac3a9bae Mon Sep 17 00:00:00 2001 From: Katherine Cox Date: Tue, 12 Aug 2014 17:14:47 -0500 Subject: [PATCH] Added a checker for empty strings w/ corresponding test. --- validation.go | 8 ++++++++ validation_test.go | 12 ++++++++++++ 2 files changed, 20 insertions(+) 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() + } +}