list_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package list
  2. import (
  3. "pmail/dto"
  4. "pmail/utils/context"
  5. "reflect"
  6. "testing"
  7. )
  8. func Test_genSQL(t *testing.T) {
  9. type args struct {
  10. ctx *context.Context
  11. count bool
  12. tagInfo dto.SearchTag
  13. keyword string
  14. pop3List bool
  15. offset int
  16. limit int
  17. }
  18. tests := []struct {
  19. name string
  20. args args
  21. want string
  22. want1 []any
  23. }{
  24. {
  25. name: "Group搜索",
  26. args: args{
  27. ctx: &context.Context{
  28. UserID: 1,
  29. },
  30. count: false,
  31. tagInfo: dto.SearchTag{-1, -1, 2},
  32. keyword: "",
  33. pop3List: false,
  34. offset: 0,
  35. limit: 0,
  36. },
  37. want: "select e.*,ue.is_read from email e left join user_email ue on e.id=ue.email_id where ue.user_id = ? and ue.status != 3 and ue.group_id=? order by e.id desc limit 0,10 ",
  38. want1: []any{1, 2},
  39. },
  40. }
  41. for _, tt := range tests {
  42. t.Run(tt.name, func(t *testing.T) {
  43. got, got1 := genSQL(tt.args.ctx, tt.args.count, tt.args.tagInfo, tt.args.keyword, tt.args.pop3List, tt.args.offset, tt.args.limit)
  44. if got != tt.want {
  45. t.Errorf("genSQL() got = \n%v, want \n%v", got, tt.want)
  46. }
  47. if !reflect.DeepEqual(got1, tt.want1) {
  48. t.Errorf("genSQL() got1 = \n%v, want \n%v", got1, tt.want1)
  49. }
  50. })
  51. }
  52. }