helpers_test.go 5.5 KB

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