query_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package mongo
  2. import (
  3. "testing"
  4. "github.com/globalsign/mgo"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/tal-tech/go-zero/core/breaker"
  7. )
  8. func Test_rejectedQuery_All(t *testing.T) {
  9. assert.Equal(t, breaker.ErrServiceUnavailable, new(rejectedQuery).All(nil))
  10. }
  11. func Test_rejectedQuery_Apply(t *testing.T) {
  12. info, err := new(rejectedQuery).Apply(mgo.Change{}, nil)
  13. assert.Equal(t, breaker.ErrServiceUnavailable, err)
  14. assert.Nil(t, info)
  15. }
  16. func Test_rejectedQuery_Batch(t *testing.T) {
  17. var q rejectedQuery
  18. assert.Equal(t, q, q.Batch(1))
  19. }
  20. func Test_rejectedQuery_Collation(t *testing.T) {
  21. var q rejectedQuery
  22. assert.Equal(t, q, q.Collation(nil))
  23. }
  24. func Test_rejectedQuery_Comment(t *testing.T) {
  25. var q rejectedQuery
  26. assert.Equal(t, q, q.Comment(""))
  27. }
  28. func Test_rejectedQuery_Count(t *testing.T) {
  29. n, err := new(rejectedQuery).Count()
  30. assert.Equal(t, breaker.ErrServiceUnavailable, err)
  31. assert.Equal(t, 0, n)
  32. }
  33. func Test_rejectedQuery_Distinct(t *testing.T) {
  34. assert.Equal(t, breaker.ErrServiceUnavailable, new(rejectedQuery).Distinct("", nil))
  35. }
  36. func Test_rejectedQuery_Explain(t *testing.T) {
  37. assert.Equal(t, breaker.ErrServiceUnavailable, new(rejectedQuery).Explain(nil))
  38. }
  39. func Test_rejectedQuery_For(t *testing.T) {
  40. assert.Equal(t, breaker.ErrServiceUnavailable, new(rejectedQuery).For(nil, nil))
  41. }
  42. func Test_rejectedQuery_Hint(t *testing.T) {
  43. var q rejectedQuery
  44. assert.Equal(t, q, q.Hint())
  45. }
  46. func Test_rejectedQuery_Iter(t *testing.T) {
  47. assert.EqualValues(t, rejectedIter{}, new(rejectedQuery).Iter())
  48. }
  49. func Test_rejectedQuery_Limit(t *testing.T) {
  50. var q rejectedQuery
  51. assert.Equal(t, q, q.Limit(1))
  52. }
  53. func Test_rejectedQuery_LogReplay(t *testing.T) {
  54. var q rejectedQuery
  55. assert.Equal(t, q, q.LogReplay())
  56. }
  57. func Test_rejectedQuery_MapReduce(t *testing.T) {
  58. info, err := new(rejectedQuery).MapReduce(nil, nil)
  59. assert.Equal(t, breaker.ErrServiceUnavailable, err)
  60. assert.Nil(t, info)
  61. }
  62. func Test_rejectedQuery_One(t *testing.T) {
  63. assert.Equal(t, breaker.ErrServiceUnavailable, new(rejectedQuery).One(nil))
  64. }
  65. func Test_rejectedQuery_Prefetch(t *testing.T) {
  66. var q rejectedQuery
  67. assert.Equal(t, q, q.Prefetch(1))
  68. }
  69. func Test_rejectedQuery_Select(t *testing.T) {
  70. var q rejectedQuery
  71. assert.Equal(t, q, q.Select(nil))
  72. }
  73. func Test_rejectedQuery_SetMaxScan(t *testing.T) {
  74. var q rejectedQuery
  75. assert.Equal(t, q, q.SetMaxScan(0))
  76. }
  77. func Test_rejectedQuery_SetMaxTime(t *testing.T) {
  78. var q rejectedQuery
  79. assert.Equal(t, q, q.SetMaxTime(0))
  80. }
  81. func Test_rejectedQuery_Skip(t *testing.T) {
  82. var q rejectedQuery
  83. assert.Equal(t, q, q.Skip(0))
  84. }
  85. func Test_rejectedQuery_Snapshot(t *testing.T) {
  86. var q rejectedQuery
  87. assert.Equal(t, q, q.Snapshot())
  88. }
  89. func Test_rejectedQuery_Sort(t *testing.T) {
  90. var q rejectedQuery
  91. assert.Equal(t, q, q.Sort())
  92. }
  93. func Test_rejectedQuery_Tail(t *testing.T) {
  94. assert.EqualValues(t, rejectedIter{}, new(rejectedQuery).Tail(0))
  95. }