helpers_test.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. package http
  2. import (
  3. "context"
  4. "net/mail"
  5. "github.com/stretchr/testify/mock"
  6. "github.com/mk6i/retro-aim-server/state"
  7. "github.com/mk6i/retro-aim-server/wire"
  8. )
  9. type mockParams struct {
  10. accountManagerParams
  11. bartAssetManagerParams
  12. chatRoomDeleterParams
  13. chatRoomRetrieverParams
  14. chatSessionRetrieverParams
  15. directoryManagerParams
  16. feedBagRetrieverParams
  17. profileRetrieverParams
  18. sessionRetrieverParams
  19. userManagerParams
  20. }
  21. // accountManagerParams is a helper struct that contains mock parameters for
  22. // accountManager methods
  23. type accountManagerParams struct {
  24. EmailAddressParams
  25. RegStatusParams
  26. ConfirmStatusParams
  27. updateSuspendedStatusParams
  28. setBotStatusParams
  29. }
  30. // EmailAddressParams is the list of parameters passed at the mock
  31. // accountManager.EmailAddress call site
  32. type EmailAddressParams []struct {
  33. screenName state.IdentScreenName
  34. result *mail.Address
  35. err error
  36. }
  37. // RegStatusParams is the list of parameters passed at the mock
  38. // accountManager.RegStatus call site
  39. type RegStatusParams []struct {
  40. screenName state.IdentScreenName
  41. result uint16
  42. err error
  43. }
  44. // ConfirmStatusParams is the list of parameters passed at the mock
  45. // accountManager.ConfirmStatus call site
  46. type ConfirmStatusParams []struct {
  47. screenName state.IdentScreenName
  48. result bool
  49. err error
  50. }
  51. // updateSuspendedStatus is the list of parameters passed at the mock
  52. // accountManager.updateSuspendedStatus call site
  53. type updateSuspendedStatusParams []struct {
  54. suspendedStatus uint16
  55. screenName state.IdentScreenName
  56. err error
  57. }
  58. // setBotStatusParams is the list of parameters passed at the mock
  59. // accountManager.SetBotStatus call site
  60. type setBotStatusParams []struct {
  61. isBot bool
  62. screenName state.IdentScreenName
  63. err error
  64. }
  65. // bartAssetManagerParams is a helper struct that contains mock parameters for
  66. // BARTAssetManager methods
  67. type bartAssetManagerParams struct {
  68. bartItemParams
  69. insertBARTItemParams
  70. listBARTItemsParams
  71. deleteBARTItemParams
  72. }
  73. // bartItemParams is the list of parameters passed at the mock
  74. // BARTAssetManager.BARTItem call site
  75. type bartItemParams []struct {
  76. hash []byte
  77. result []byte
  78. err error
  79. }
  80. // insertBARTItemParams is the list of parameters passed at the mock
  81. // BARTAssetManager.InsertBARTItem call site
  82. type insertBARTItemParams []struct {
  83. hash []byte
  84. blob []byte
  85. itemType uint16
  86. err error
  87. }
  88. // listBARTItemsParams is the list of parameters passed at the mock
  89. // BARTAssetManager.ListBARTItems call site
  90. type listBARTItemsParams []struct {
  91. itemType uint16
  92. result []state.BARTItem
  93. err error
  94. }
  95. // deleteBARTItemParams is the list of parameters passed at the mock
  96. // BARTAssetManager.DeleteBARTItem call site
  97. type deleteBARTItemParams []struct {
  98. hash []byte
  99. err error
  100. }
  101. // chatRoomRetrieverParams is a helper struct that contains mock parameters for
  102. // ChatRoomRetriever methods
  103. type chatRoomRetrieverParams struct {
  104. allChatRoomsParams
  105. }
  106. // allChatRoomsParams is the list of parameters passed at the mock
  107. // ChatRoomRetriever.AllChatRooms call site
  108. type allChatRoomsParams []struct {
  109. exchange uint16
  110. result []state.ChatRoom
  111. err error
  112. }
  113. // chatRoomDeleterParams is a helper struct that contains mock parameters for
  114. // ChatRoomDeleter methods
  115. type chatRoomDeleterParams struct {
  116. deleteChatRoomsParams
  117. }
  118. // deleteChatRoomsParams is the list of parameters passed at the mock
  119. // ChatRoomDeleter.DeleteChatRooms call site
  120. type deleteChatRoomsParams []struct {
  121. exchange uint16
  122. names []string
  123. err error
  124. }
  125. // chatSessionRetrieverParams is a helper struct that contains mock parameters for
  126. // ChatSessionRetriever methods
  127. type chatSessionRetrieverParams struct {
  128. chatSessionRetrieverAllSessionsParams
  129. }
  130. // chatSessionRetrieverAllSessionsParams is the list of parameters passed at the mock
  131. // ChatSessionRetriever.AllSessions call site
  132. type chatSessionRetrieverAllSessionsParams []struct {
  133. cookie string
  134. result []*state.Session
  135. }
  136. type directoryManagerParams struct {
  137. categoriesParams
  138. createCategoryParams
  139. createKeywordParams
  140. deleteCategoryParams
  141. deleteKeywordParams
  142. keywordsByCategoryParams
  143. }
  144. // categoriesParams is the list of parameters passed at the mock
  145. // DirectoryManager.Categories call site
  146. type categoriesParams []struct {
  147. result []state.Category
  148. err error
  149. }
  150. // createCategoryParams is the list of parameters passed at the mock
  151. // DirectoryManager.CreateCategory call site
  152. type createCategoryParams []struct {
  153. name string
  154. result state.Category
  155. err error
  156. }
  157. // createKeywordParams is the list of parameters passed at the mock
  158. // DirectoryManager.CreateKeyword call site
  159. type createKeywordParams []struct {
  160. name string
  161. categoryID uint8
  162. result state.Keyword
  163. err error
  164. }
  165. // deleteCategoryParams is the list of parameters passed at the mock
  166. // DirectoryManager.DeleteCategory call site
  167. type deleteCategoryParams []struct {
  168. categoryID uint8
  169. err error
  170. }
  171. // deleteKeywordParams is the list of parameters passed at the mock
  172. // DirectoryManager.DeleteKeyword call site
  173. type deleteKeywordParams []struct {
  174. id uint8
  175. err error
  176. }
  177. // keywordsByCategoryParams is the list of parameters passed at the mock
  178. // DirectoryManager.KeywordsByCategory call site
  179. type keywordsByCategoryParams []struct {
  180. categoryID uint8
  181. result []state.Keyword
  182. err error
  183. }
  184. // feedBagRetrieverParams is a helper struct that contains mock parameters for
  185. // FeedBagRetriever methods
  186. type feedBagRetrieverParams struct {
  187. buddyIconMetadataParams
  188. }
  189. // buddyIconMetadataParams is the list of parameters passed at the mock
  190. // FeedBagRetriever.BuddyIconMetadataParams call site
  191. type buddyIconMetadataParams []struct {
  192. screenName state.IdentScreenName
  193. result *wire.BARTID
  194. err error
  195. }
  196. // profileRetrieverParams is a helper struct that contains mock parameters for
  197. // ProfileRetriever methods
  198. type profileRetrieverParams struct {
  199. retrieveProfileParams
  200. }
  201. // retrieveProfileParams is the list of parameters passed at the mock
  202. // ProfileRetriever.Profile call site
  203. type retrieveProfileParams []struct {
  204. screenName state.IdentScreenName
  205. result state.UserProfile
  206. err error
  207. }
  208. // sessionRetrieverParams is a helper struct that contains mock parameters for
  209. // SessionRetriever methods
  210. type sessionRetrieverParams struct {
  211. sessionRetrieverAllSessionsParams
  212. retrieveSessionByNameParams
  213. }
  214. // sessionRetrieverAllSessionsParams is the list of parameters passed at the mock
  215. // SessionRetriever.AllSessions call site
  216. type sessionRetrieverAllSessionsParams []struct {
  217. result []*state.Session
  218. }
  219. // retrieveSessionParams is the list of parameters passed at the mock
  220. // SessionRetriever.RetrieveSessionByName call site
  221. type retrieveSessionByNameParams []struct {
  222. screenName state.IdentScreenName
  223. result *state.Session
  224. }
  225. // userManagerParams is a helper struct that contains mock parameters for
  226. // UserManager methods
  227. type userManagerParams struct {
  228. allUsersParams
  229. deleteUserParams
  230. getUserParams
  231. insertUserParams
  232. setUserPasswordParams
  233. }
  234. // allUsersParams is the list of parameters passed at the mock
  235. // UserManager.AllUsers call site
  236. type allUsersParams []struct {
  237. result []state.User
  238. err error
  239. }
  240. // deleteUserParams is the list of parameters passed at the mock
  241. // UserManager.DeleteUser call site
  242. type deleteUserParams []struct {
  243. screenName state.IdentScreenName
  244. err error
  245. }
  246. // getUserParams is the list of parameters passed at the mock
  247. // UserManager.User call site
  248. type getUserParams []struct {
  249. screenName state.IdentScreenName
  250. result *state.User
  251. err error
  252. }
  253. // insertUserParams is the list of parameters passed at the mock
  254. // UserManager.InsertUser call site
  255. type insertUserParams []struct {
  256. u state.User
  257. err error
  258. }
  259. // setUserPasswordParams is the list of parameters passed at the mock
  260. // UserManager.SetUserPassword call site
  261. type setUserPasswordParams []struct {
  262. screenName state.IdentScreenName
  263. newPassword string
  264. err error
  265. }
  266. // matchContext matches any instance of Context interface.
  267. func matchContext() interface{} {
  268. return mock.MatchedBy(func(ctx any) bool {
  269. _, ok := ctx.(context.Context)
  270. return ok
  271. })
  272. }