utils_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package dao
  2. import (
  3. "testing"
  4. "github.com/smartystreets/goconvey/convey"
  5. )
  6. func TestDaoConcatCondition(t *testing.T) {
  7. convey.Convey("ConcatCondition", t, func(ctx convey.C) {
  8. var (
  9. conditions Condition = Condition{Key: "id", Operator: "=", Value: 1}
  10. )
  11. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  12. conditionStr, args, hasOperator := ConcatCondition(conditions)
  13. ctx.Convey("Then conditionStr,args,hasOperator should not be nil.", func(ctx convey.C) {
  14. ctx.So(hasOperator, convey.ShouldNotBeNil)
  15. ctx.So(args, convey.ShouldNotBeNil)
  16. ctx.So(conditionStr, convey.ShouldNotBeNil)
  17. })
  18. })
  19. })
  20. }
  21. func TestDaoAndCondition(t *testing.T) {
  22. convey.Convey("AndCondition", t, func(ctx convey.C) {
  23. var (
  24. conditions Condition
  25. )
  26. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  27. result := AndCondition(conditions)
  28. ctx.Convey("Then result should not be nil.", func(ctx convey.C) {
  29. ctx.So(result, convey.ShouldNotBeNil)
  30. })
  31. })
  32. })
  33. }
  34. func TestDaoOrCondition(t *testing.T) {
  35. convey.Convey("OrCondition", t, func(ctx convey.C) {
  36. var (
  37. conditions Condition
  38. )
  39. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  40. result := OrCondition(conditions)
  41. ctx.Convey("Then result should not be nil.", func(ctx convey.C) {
  42. ctx.So(result, convey.ShouldNotBeNil)
  43. })
  44. })
  45. })
  46. }
  47. func TestDaoaddLogicOperator(t *testing.T) {
  48. convey.Convey("addLogicOperator", t, func(ctx convey.C) {
  49. var (
  50. operator = int(0)
  51. conditions Condition
  52. )
  53. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  54. result := addLogicOperator(operator, conditions)
  55. ctx.Convey("Then result should not be nil.", func(ctx convey.C) {
  56. ctx.So(result, convey.ShouldNotBeNil)
  57. })
  58. })
  59. })
  60. }