validate_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2014 Manu Martinez-Almeida. All rights reserved.
  2. // Use of this source code is governed by a MIT style
  3. // license that can be found in the LICENSE file.
  4. package binding
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. type struct1 struct {
  10. Value float64 `binding:"required"`
  11. }
  12. type struct2 struct {
  13. RequiredValue string `binding:"required"`
  14. Value float64
  15. }
  16. type struct3 struct {
  17. Integer int
  18. String string
  19. BasicSlice []int
  20. Boolean bool
  21. RequiredInteger int `binding:"required"`
  22. RequiredString string `binding:"required"`
  23. RequiredAnotherStruct struct1 `binding:"required"`
  24. RequiredBasicSlice []int `binding:"required"`
  25. RequiredComplexSlice []struct2 `binding:"required"`
  26. RequiredBoolean bool `binding:"required"`
  27. }
  28. func createStruct() struct3 {
  29. return struct3{
  30. RequiredInteger: 2,
  31. RequiredString: "hello",
  32. RequiredAnotherStruct: struct1{1.5},
  33. RequiredBasicSlice: []int{1, 2, 3, 4},
  34. RequiredComplexSlice: []struct2{
  35. {RequiredValue: "A"},
  36. {RequiredValue: "B"},
  37. },
  38. RequiredBoolean: true,
  39. }
  40. }
  41. func TestValidateGoodObject(t *testing.T) {
  42. test := createStruct()
  43. assert.Nil(t, Validate(&test))
  44. }