shared_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package api
  2. import (
  3. "testing"
  4. statsService "github.com/v2fly/v2ray-core/v4/app/stats/command"
  5. )
  6. func TestEmptyResponese_0(t *testing.T) {
  7. r := &statsService.QueryStatsResponse{
  8. Stat: []*statsService.Stat{
  9. {
  10. Name: "1>>2",
  11. Value: 1,
  12. },
  13. {
  14. Name: "1>>2>>3",
  15. Value: 2,
  16. },
  17. },
  18. }
  19. assert(t, isEmpty(r), false)
  20. }
  21. func TestEmptyResponese_1(t *testing.T) {
  22. r := (*statsService.QueryStatsResponse)(nil)
  23. assert(t, isEmpty(r), true)
  24. }
  25. func TestEmptyResponese_2(t *testing.T) {
  26. r := &statsService.QueryStatsResponse{
  27. Stat: nil,
  28. }
  29. assert(t, isEmpty(r), true)
  30. }
  31. func TestEmptyResponese_3(t *testing.T) {
  32. r := &statsService.QueryStatsResponse{
  33. Stat: []*statsService.Stat{},
  34. }
  35. assert(t, isEmpty(r), true)
  36. }
  37. func TestEmptyResponese_4(t *testing.T) {
  38. r := &statsService.QueryStatsResponse{
  39. Stat: []*statsService.Stat{
  40. {
  41. Name: "",
  42. Value: 0,
  43. },
  44. },
  45. }
  46. assert(t, isEmpty(r), true)
  47. }
  48. func TestEmptyResponese_5(t *testing.T) {
  49. type test struct {
  50. Value *statsService.QueryStatsResponse
  51. }
  52. r := &test{
  53. Value: &statsService.QueryStatsResponse{
  54. Stat: []*statsService.Stat{
  55. {
  56. Name: "",
  57. },
  58. },
  59. },
  60. }
  61. assert(t, isEmpty(r), true)
  62. }
  63. func TestEmptyResponese_6(t *testing.T) {
  64. type test struct {
  65. Value *statsService.QueryStatsResponse
  66. }
  67. r := &test{
  68. Value: &statsService.QueryStatsResponse{
  69. Stat: []*statsService.Stat{
  70. {
  71. Value: 1,
  72. },
  73. },
  74. },
  75. }
  76. assert(t, isEmpty(r), false)
  77. }
  78. func TestEmptyResponese_7(t *testing.T) {
  79. type test struct {
  80. Value *int
  81. }
  82. v := 1
  83. r := &test{
  84. Value: &v,
  85. }
  86. assert(t, isEmpty(r), false)
  87. }
  88. func TestEmptyResponese_8(t *testing.T) {
  89. type test struct {
  90. Value *int
  91. }
  92. v := 0
  93. r := &test{
  94. Value: &v,
  95. }
  96. assert(t, isEmpty(r), true)
  97. }
  98. func TestEmptyResponese_9(t *testing.T) {
  99. assert(t, isEmpty(0), true)
  100. }
  101. func TestEmptyResponese_10(t *testing.T) {
  102. assert(t, isEmpty(1), false)
  103. }
  104. func TestEmptyResponese_11(t *testing.T) {
  105. r := []*statsService.Stat{
  106. {
  107. Name: "",
  108. },
  109. }
  110. assert(t, isEmpty(r), true)
  111. }
  112. func TestEmptyResponese_12(t *testing.T) {
  113. r := []*statsService.Stat{
  114. {
  115. Value: 1,
  116. },
  117. }
  118. assert(t, isEmpty(r), false)
  119. }
  120. func assert(t *testing.T, value, expected bool) {
  121. if value != expected {
  122. t.Fatalf("Expected: %v, actual: %v", expected, value)
  123. }
  124. }