query_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package search
  2. import (
  3. "fmt"
  4. "testing"
  5. "time"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. type ApplicationQuery struct {
  9. Id string `search:"type:icontains;column:id;table:receipt" form:"id"`
  10. Domain string `search:"type:icontains;column:domain;table:receipt" form:"domain"`
  11. Version string `search:"type:exact;column:version;table:receipt" form:"version"`
  12. Status []int `search:"type:in;column:status;table:receipt" form:"status"`
  13. Start time.Time `search:"type:gte;column:created_at;table:receipt" form:"start"`
  14. End time.Time `search:"type:lte;column:created_at;table:receipt" form:"end"`
  15. TestJoin `search:"type:left;on:id:receipt_id;table:receipt_goods;join:receipts"`
  16. NotNeed string `search:"-"`
  17. ApplicationOrder
  18. }
  19. type ApplicationOrder struct {
  20. IdOrder string `search:"type:order;column:id;table:receipt" form:"id_order"`
  21. }
  22. type TestJoin struct {
  23. PaymentAccount string `search:"type:icontains;column:payment_account;table:receipts" form:"payment_account"`
  24. }
  25. func TestResolveSearchQuery(t *testing.T) {
  26. // Only pass t into top-level Convey calls
  27. Convey("Given some integer with a starting value", t, func() {
  28. d := ApplicationQuery{
  29. Id: "aaa",
  30. Domain: "bbb",
  31. Version: "ccc",
  32. Status: []int{1, 2},
  33. Start: time.Now().Add(-8 * time.Hour),
  34. End: time.Now(),
  35. ApplicationOrder: ApplicationOrder{IdOrder: "desc"},
  36. TestJoin: TestJoin{PaymentAccount: "1212"},
  37. }
  38. condition := &GormCondition{
  39. GormPublic: GormPublic{},
  40. Join: make([]*GormJoin, 0),
  41. }
  42. ResolveSearchQuery("mysql", d, condition)
  43. fmt.Println(condition)
  44. })
  45. }