helpers_test.go 6.7 KB

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