cond_test.go 916 B

1234567891011121314151617181920212223242526272829303132
  1. package http_test
  2. import (
  3. "errors"
  4. "fmt"
  5. "testing"
  6. "go-common/app/service/main/antispam/http"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestValid(t *testing.T) {
  10. cases := []struct {
  11. cond *http.Condition
  12. expectedErr error
  13. }{
  14. {&http.Condition{Search: " ", Order: ""}, nil},
  15. {&http.Condition{Search: "foo", Order: ""}, nil},
  16. {&http.Condition{Search: "bar", Order: "xxx"}, errors.New("Order by should be 'ASC' or 'DESC' but got(XXX)")},
  17. {&http.Condition{Search: "bar", Order: "asc"}, nil},
  18. {&http.Condition{Search: "bar", Order: "ASC"}, nil},
  19. {&http.Condition{Search: "bar", Order: "DESC"}, nil},
  20. }
  21. for _, c := range cases {
  22. t.Run(fmt.Sprintf("Search(%q) Order(%q)", c.cond.Search, c.cond.Order), func(t *testing.T) {
  23. assert := assert.New(t)
  24. err := c.cond.Valid()
  25. assert.Equal(c.expectedErr, err, fmt.Sprintf("cond.Valid() = %v, want %v", err, c.expectedErr))
  26. })
  27. }
  28. }