You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils_test.go 4.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. package utils
  2. import (
  3. "github.com/gofrs/uuid"
  4. "testing"
  5. )
  6. func TestGenUUID(t *testing.T) {
  7. tests := []struct {
  8. name string
  9. want string
  10. }{
  11. {
  12. name: "test-GenUUID",
  13. want: "",
  14. },
  15. }
  16. for _, tt := range tests {
  17. t.Run(tt.name, func(t *testing.T) {
  18. if got := GenUUID(); got == tt.want {
  19. t.Errorf("GenUUID() = %v, want %v", got, tt.want)
  20. }
  21. })
  22. }
  23. }
  24. func TestGenUUIDWithoutHyphen(t *testing.T) {
  25. tests := []struct {
  26. name string
  27. want string
  28. }{
  29. {
  30. name: "test-GenUUIDWithoutHyphen",
  31. want: "",
  32. },
  33. }
  34. for _, tt := range tests {
  35. t.Run(tt.name, func(t *testing.T) {
  36. if got := GenUUIDWithoutHyphen(); got == tt.want {
  37. t.Errorf("GenUUIDWithoutHyphen() = %v, want %v", got, tt.want)
  38. }
  39. })
  40. }
  41. }
  42. func Test_encodeCanonical(t *testing.T) {
  43. type args struct {
  44. dst []byte
  45. u uuid.UUID
  46. }
  47. var buf [36]byte
  48. tests := []struct {
  49. name string
  50. args args
  51. }{
  52. {
  53. name: "test-encodeCanonical",
  54. args: args{
  55. dst: buf[:],
  56. u: uuid.Must(uuid.NewV4()),
  57. },
  58. },
  59. }
  60. for _, tt := range tests {
  61. t.Run(tt.name, func(t *testing.T) {
  62. encodeCanonical(tt.args.dst, tt.args.u)
  63. })
  64. }
  65. }
  66. func Test_toString(t *testing.T) {
  67. type args struct {
  68. u uuid.UUID
  69. }
  70. tests := []struct {
  71. name string
  72. args args
  73. want string
  74. }{
  75. {
  76. name: "test-toString",
  77. args: args{
  78. u: uuid.Must(uuid.NewV4()),
  79. },
  80. want: "",
  81. },
  82. }
  83. for _, tt := range tests {
  84. t.Run(tt.name, func(t *testing.T) {
  85. if got := toString(tt.args.u); got == tt.want {
  86. t.Errorf("toString() = %v, want %v", got, tt.want)
  87. }
  88. })
  89. }
  90. }
  91. func TestComparePassword(t *testing.T) {
  92. type args struct {
  93. password string
  94. encryptedPassword string
  95. }
  96. tests := []struct {
  97. name string
  98. args args
  99. want bool
  100. }{
  101. {
  102. name: "test-ComparePassword",
  103. args: args{
  104. password: "123456",
  105. encryptedPassword: "fa9ffa9a6017dee3be4e4063d108b69b54c4c8b3e9465a65b8d3191481655141",
  106. },
  107. want: true,
  108. },
  109. }
  110. for _, tt := range tests {
  111. t.Run(tt.name, func(t *testing.T) {
  112. if got := ComparePassword(tt.args.password, tt.args.encryptedPassword); got != tt.want {
  113. t.Errorf("ComparePassword() = %v, want %v", got, tt.want)
  114. }
  115. })
  116. }
  117. }
  118. func TestEncryptPassword(t *testing.T) {
  119. type args struct {
  120. password string
  121. }
  122. tests := []struct {
  123. name string
  124. args args
  125. want string
  126. }{
  127. {
  128. name: "test-EncryptPassword",
  129. args: args{
  130. password: "123456",
  131. },
  132. want: "fa9ffa9a6017dee3be4e4063d108b69b54c4c8b3e9465a65b8d3191481655141",
  133. },
  134. }
  135. for _, tt := range tests {
  136. t.Run(tt.name, func(t *testing.T) {
  137. if got := EncryptPassword(tt.args.password); got != tt.want {
  138. t.Errorf("EncryptPassword() = %v, want %v", got, tt.want)
  139. }
  140. })
  141. }
  142. }
  143. func TestIntToString(t *testing.T) {
  144. type args struct {
  145. i interface{}
  146. }
  147. tests := []struct {
  148. name string
  149. args args
  150. want string
  151. }{
  152. {
  153. name: "test-IntToString",
  154. args: args{
  155. i: 1,
  156. },
  157. want: "1",
  158. },
  159. }
  160. for _, tt := range tests {
  161. t.Run(tt.name, func(t *testing.T) {
  162. if got := IntToString(tt.args.i); got != tt.want {
  163. t.Errorf("IntToString() = %v, want %v", got, tt.want)
  164. }
  165. })
  166. }
  167. }
  168. func TestIsValidEmail(t *testing.T) {
  169. type args struct {
  170. email string
  171. }
  172. tests := []struct {
  173. name string
  174. args args
  175. want bool
  176. }{
  177. {
  178. name: "test-IsValidEmail",
  179. args: args{
  180. email: "123@qq.com",
  181. },
  182. want: true,
  183. },
  184. }
  185. for _, tt := range tests {
  186. t.Run(tt.name, func(t *testing.T) {
  187. if got := IsValidEmail(tt.args.email); got != tt.want {
  188. t.Errorf("IsValidEmail() = %v, want %v", got, tt.want)
  189. }
  190. })
  191. }
  192. }
  193. func TestStringToInt(t *testing.T) {
  194. type args struct {
  195. i string
  196. }
  197. tests := []struct {
  198. name string
  199. args args
  200. want int
  201. }{
  202. {
  203. name: "test-StringToInt",
  204. args: args{
  205. i: "1",
  206. },
  207. want: 1,
  208. },
  209. }
  210. for _, tt := range tests {
  211. t.Run(tt.name, func(t *testing.T) {
  212. if got := StringToInt(tt.args.i); got != tt.want {
  213. t.Errorf("StringToInt() = %v, want %v", got, tt.want)
  214. }
  215. })
  216. }
  217. }