github.com/System-Glitch/goyave/v2@v2.10.3-0.20200819142921-51011e75d504/validation/placeholder_test.go (about) 1 package validation 2 3 import ( 4 "testing" 5 6 "github.com/System-Glitch/goyave/v2/config" 7 "github.com/System-Glitch/goyave/v2/lang" 8 "github.com/stretchr/testify/suite" 9 ) 10 11 type PlaceholderTestSuite struct { 12 suite.Suite 13 } 14 15 func (suite *PlaceholderTestSuite) SetupSuite() { 16 lang.LoadDefault() 17 if err := config.LoadFrom("../config.test.json"); err != nil { 18 suite.FailNow(err.Error()) 19 } 20 config.Set("app.defaultLanguage", "en-US") 21 } 22 23 func (suite *PlaceholderTestSuite) TestPlaceholders() { 24 suite.Equal("fieldName", placeholders[":field"]("fieldName", "required", []string{}, "en-US")) 25 suite.Equal("email address", placeholders[":field"]("email", "required", []string{}, "en-US")) 26 suite.Equal("5", placeholders[":min"]("field", "min", []string{"5"}, "en-US")) 27 suite.Equal("5", placeholders[":max"]("field", "max", []string{"5"}, "en-US")) 28 suite.Equal("10", placeholders[":max"]("field", "between", []string{"5", "10"}, "en-US")) 29 30 suite.Equal("email address", placeholders[":other"]("field", "greater_than", []string{"email"}, "en-US")) 31 suite.Equal("otherField", placeholders[":other"]("field", "greater_than", []string{"otherField"}, "en-US")) 32 33 suite.Equal("a, b, c", placeholders[":values"]("field", "in", []string{"a", "b", "c"}, "en-US")) 34 suite.Equal("", placeholders[":version"]("field", "uuid", []string{}, "en-US")) 35 suite.Equal("v5", placeholders[":version"]("field", "uuid", []string{"5"}, "en-US")) 36 37 suite.Equal("email address", placeholders[":date"]("field", "date", []string{"email"}, "en-US")) 38 suite.Equal("2019-11-02T17:00:00", placeholders[":date"]("field", "date", []string{"2019-11-02T17:00:00"}, "en-US")) 39 suite.Equal("2019-11-03T17:00:00", placeholders[":max_date"]("field", "date", []string{"2019-11-02T17:00:00", "2019-11-03T17:00:00"}, "en-US")) 40 } 41 42 func (suite *PlaceholderTestSuite) TestProcessPlaceholders() { 43 suite.Equal("The email address is required.", processPlaceholders("email", "required", []string{}, "The :field is required.", "en-US")) 44 suite.Equal("The image must be a file with one of the following extensions: ppm.", processPlaceholders("image", "extension", []string{"ppm"}, "The :field must be a file with one of the following extensions: :values.", "en-US")) 45 suite.Equal("The image must be a file with one of the following extensions: ppm, png.", processPlaceholders("image", "extension", []string{"ppm", "png"}, "The :field must be a file with one of the following extensions: :values.", "en-US")) 46 suite.Equal("The image must have exactly 2 file(s).", processPlaceholders("image", "count", []string{"2"}, "The :field must have exactly :value file(s).", "en-US")) 47 } 48 49 func TestPlaceholderTestSuite(t *testing.T) { 50 suite.Run(t, new(PlaceholderTestSuite)) 51 }