helpers_test.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. package toc
  2. import (
  3. "github.com/stretchr/testify/mock"
  4. "github.com/mk6i/retro-aim-server/state"
  5. "github.com/mk6i/retro-aim-server/wire"
  6. )
  7. type adminParams struct {
  8. infoChangeRequestParams
  9. }
  10. type infoChangeRequestParams []struct {
  11. me state.IdentScreenName
  12. inBody wire.SNAC_0x07_0x04_AdminInfoChangeRequest
  13. msg wire.SNACMessage
  14. err error
  15. }
  16. type addBuddiesParams []struct {
  17. me state.IdentScreenName
  18. inBody wire.SNAC_0x03_0x04_BuddyAddBuddies
  19. err error
  20. }
  21. type broadcastBuddyDepartedParams []struct {
  22. me state.IdentScreenName
  23. err error
  24. }
  25. type delBuddiesParams []struct {
  26. me state.IdentScreenName
  27. inBody wire.SNAC_0x03_0x05_BuddyDelBuddies
  28. err error
  29. }
  30. type buddyParams struct {
  31. addBuddiesParams
  32. broadcastBuddyDepartedParams
  33. delBuddiesParams
  34. }
  35. type chatParams struct {
  36. channelMsgToHostParamsChat
  37. }
  38. type createRoomParams []struct {
  39. me state.IdentScreenName
  40. inBody wire.SNAC_0x0E_0x02_ChatRoomInfoUpdate
  41. msg wire.SNACMessage
  42. err error
  43. }
  44. type requestRoomInfoParams []struct {
  45. inBody wire.SNAC_0x0D_0x04_ChatNavRequestRoomInfo
  46. msg wire.SNACMessage
  47. err error
  48. }
  49. type chatNavParams struct {
  50. createRoomParams
  51. requestRoomInfoParams
  52. }
  53. type channelMsgToHostParamsChat []struct {
  54. sender state.IdentScreenName
  55. inBody wire.SNAC_0x0E_0x05_ChatChannelMsgToHost
  56. result *wire.SNACMessage
  57. err error
  58. }
  59. type channelMsgToHostParamsICBM []struct {
  60. sender state.IdentScreenName
  61. inFrame wire.SNACFrame
  62. inBody wire.SNAC_0x04_0x06_ICBMChannelMsgToHost
  63. result *wire.SNACMessage
  64. err error
  65. }
  66. type evilRequestParams []struct {
  67. me state.IdentScreenName
  68. inBody wire.SNAC_0x04_0x08_ICBMEvilRequest
  69. msg wire.SNACMessage
  70. err error
  71. }
  72. type icbmParams struct {
  73. channelMsgToHostParamsICBM
  74. evilRequestParams
  75. }
  76. type clientOnlineParams []struct {
  77. body wire.SNAC_0x01_0x02_OServiceClientOnline
  78. me state.IdentScreenName
  79. err error
  80. }
  81. type idleNotificationParams []struct {
  82. me state.IdentScreenName
  83. bodyIn wire.SNAC_0x01_0x11_OServiceIdleNotification
  84. err error
  85. }
  86. type serviceRequestParams []struct {
  87. me state.IdentScreenName
  88. bodyIn wire.SNAC_0x01_0x04_OServiceServiceRequest
  89. msg wire.SNACMessage
  90. err error
  91. }
  92. type oServiceParams struct {
  93. clientOnlineParams
  94. idleNotificationParams
  95. serviceRequestParams
  96. }
  97. type flapLoginParams []struct {
  98. frame wire.FLAPSignonFrame
  99. newUserFn func(screenName state.DisplayScreenName) (state.User, error)
  100. tlv wire.TLVRestBlock
  101. err error
  102. }
  103. type registerBOSSessionParams []struct {
  104. authCookie []byte
  105. sess *state.Session
  106. err error
  107. }
  108. type registerChatSessionParams []struct {
  109. authCookie []byte
  110. sess *state.Session
  111. err error
  112. }
  113. type signoutParams []struct {
  114. me state.IdentScreenName
  115. }
  116. type signoutChatParams []struct {
  117. me state.IdentScreenName
  118. }
  119. type authParams struct {
  120. flapLoginParams
  121. registerBOSSessionParams
  122. registerChatSessionParams
  123. signoutParams
  124. signoutChatParams
  125. }
  126. type setDirInfoParams []struct {
  127. me state.IdentScreenName
  128. inBody wire.SNAC_0x02_0x09_LocateSetDirInfo
  129. msg wire.SNACMessage
  130. err error
  131. }
  132. type setInfoParams []struct {
  133. me state.IdentScreenName
  134. inBody wire.SNAC_0x02_0x04_LocateSetInfo
  135. err error
  136. }
  137. type userInfoQueryParams []struct {
  138. me state.IdentScreenName
  139. inBody wire.SNAC_0x02_0x05_LocateUserInfoQuery
  140. msg wire.SNACMessage
  141. err error
  142. }
  143. type dirInfoParams []struct {
  144. body wire.SNAC_0x02_0x0B_LocateGetDirInfo
  145. msg wire.SNACMessage
  146. err error
  147. }
  148. type locateParams struct {
  149. setDirInfoParams
  150. setInfoParams
  151. userInfoQueryParams
  152. dirInfoParams
  153. }
  154. type infoQueryParams []struct {
  155. inBody wire.SNAC_0x0F_0x02_InfoQuery
  156. msg wire.SNACMessage
  157. err error
  158. }
  159. type dirSearchParams struct {
  160. infoQueryParams
  161. }
  162. type addDenyListEntriesParams []struct {
  163. me state.IdentScreenName
  164. body wire.SNAC_0x09_0x07_PermitDenyAddDenyListEntries
  165. err error
  166. }
  167. type addPermListEntriesParams []struct {
  168. me state.IdentScreenName
  169. body wire.SNAC_0x09_0x05_PermitDenyAddPermListEntries
  170. err error
  171. }
  172. type permitDenyParams struct {
  173. addDenyListEntriesParams
  174. addPermListEntriesParams
  175. }
  176. type registerBuddyListParams []struct {
  177. user state.IdentScreenName
  178. err error
  179. }
  180. type unregisterBuddyListParams []struct {
  181. user state.IdentScreenName
  182. err error
  183. }
  184. type buddyListRegistryParams struct {
  185. registerBuddyListParams
  186. unregisterBuddyListParams
  187. }
  188. type setTOCConfigParams []struct {
  189. user state.IdentScreenName
  190. config string
  191. err error
  192. }
  193. type userParams []struct {
  194. screenName state.IdentScreenName
  195. returnedUser *state.User
  196. err error
  197. }
  198. type tocConfigParams struct {
  199. setTOCConfigParams
  200. userParams
  201. }
  202. type mockParams struct {
  203. adminParams
  204. authParams
  205. buddyListRegistryParams
  206. buddyParams
  207. chatNavParams
  208. chatParams
  209. cookieBakerParams
  210. dirSearchParams
  211. icbmParams
  212. locateParams
  213. oServiceBOSParams oServiceParams
  214. oServiceChatParams oServiceParams
  215. permitDenyParams
  216. tocConfigParams
  217. }
  218. // issueParams holds multiple scenarios for the Issue method.
  219. type issueParams []struct {
  220. data []byte
  221. returnData []byte
  222. returnErr error
  223. }
  224. // cookieBakerParams groups the method scenarios for a CookieBaker.
  225. type cookieBakerParams struct {
  226. issueParams issueParams
  227. }
  228. // matchSession matches a mock call based session ident screen name.
  229. func matchSession(mustMatch state.IdentScreenName) interface{} {
  230. return mock.MatchedBy(func(s *state.Session) bool {
  231. return mustMatch == s.IdentScreenName()
  232. })
  233. }
  234. // newTestSession creates a session object with 0 or more functional options
  235. // applied
  236. func newTestSession(screenName state.DisplayScreenName, options ...func(session *state.Session)) *state.Session {
  237. s := state.NewSession()
  238. s.SetIdentScreenName(screenName.IdentScreenName())
  239. s.SetDisplayScreenName(screenName)
  240. for _, op := range options {
  241. op(s)
  242. }
  243. return s
  244. }