| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022 |
- package foodgroup
- import (
- "context"
- "net/mail"
- "net/netip"
- "time"
- "github.com/stretchr/testify/mock"
- "github.com/mk6i/open-oscar-server/state"
- "github.com/mk6i/open-oscar-server/wire"
- )
- // mockParams is a helper struct that centralizes mock function call parameters
- // in one place for a table test
- type mockParams struct {
- accountManagerParams
- bartItemManagerParams
- buddyBroadcasterParams
- contactPreAuthorizerParams
- buddyAddedNotifierDeduperParams
- relationshipFetcherParams
- chatMessageRelayerParams
- chatRoomRegistryParams
- cookieBakerParams
- feedbagManagerParams
- icqUserFinderParams
- icqUserUpdaterParams
- clientSideBuddyListManagerParams
- messageRelayerParams
- offlineMessageManagerParams
- profileManagerParams
- sessionRegistryParams
- sessionRetrieverParams
- userManagerParams
- }
- // contactPreAuthorizerParams is a helper struct that contains mock parameters for
- // ContactPreAuthorizer methods
- type contactPreAuthorizerParams struct {
- recordPreAuthParams
- requiresAuthorizationParams
- }
- // recordPreAuthParams is the list of parameters passed at the mock
- // ContactPreAuthorizer.RecordPreAuth call site
- type recordPreAuthParams []struct {
- owner state.IdentScreenName
- buddy state.IdentScreenName
- err error
- }
- // requiresAuthorizationParams is the list of parameters passed at the mock
- // ContactPreAuthorizer.RequiresAuthorization call site
- type requiresAuthorizationParams []struct {
- owner state.IdentScreenName
- requester state.IdentScreenName
- result bool
- err error
- }
- // buddyAddedNotifierDeduperParams is a helper struct that contains mock parameters
- // for BuddyAddedNotifierDeduper methods.
- type buddyAddedNotifierDeduperParams struct {
- hasBuddyAddedNotificationParams
- recordBuddyAddedNotificationParams
- }
- // hasBuddyAddedNotificationParams is the list of parameters passed at the mock
- // BuddyAddedNotifierDeduper.HasBuddyAddedNotification call site.
- type hasBuddyAddedNotificationParams []struct {
- granter state.IdentScreenName
- requester state.IdentScreenName
- result bool
- err error
- }
- // recordBuddyAddedNotificationParams is the list of parameters passed at the mock
- // BuddyAddedNotifierDeduper.RecordBuddyAddedNotification call site.
- type recordBuddyAddedNotificationParams []struct {
- granter state.IdentScreenName
- requester state.IdentScreenName
- err error
- }
- // relationshipFetcherParams is a helper struct that contains mock parameters
- // for RelationshipFetcher methods
- type relationshipFetcherParams struct {
- allRelationshipsParams
- relationshipParams
- }
- // allRelationshipsParams is the list of parameters passed at the mock
- // RelationshipFetcher.AllRelationships call site
- type allRelationshipsParams []struct {
- screenName state.IdentScreenName
- filter []state.IdentScreenName
- result []state.Relationship
- err error
- }
- // relationshipParams is the list of parameters passed at the mock
- // RelationshipFetcher.Relationship call site
- type relationshipParams []struct {
- me state.IdentScreenName
- them state.IdentScreenName
- result state.Relationship
- err error
- }
- // offlineMessageManagerParams is a helper struct that contains mock parameters for
- // OfflineMessageManager methods
- type offlineMessageManagerParams struct {
- deleteMessagesParams
- retrieveMessagesParams
- saveMessageParams
- setOfflineMsgCountParams
- }
- // deleteMessagesParams is the list of parameters passed at the mock
- // OfflineMessageManager.DeleteMessages call site
- type deleteMessagesParams []struct {
- recipIn state.IdentScreenName
- err error
- }
- // deleteMessagesParams is the list of parameters passed at the mock
- // OfflineMessageManager.RetrieveMessages call site
- type retrieveMessagesParams []struct {
- recipIn state.IdentScreenName
- messagesOut []state.OfflineMessage
- err error
- }
- // deleteMessagesParams is the list of parameters passed at the mock
- // OfflineMessageManager.SaveMessage call site
- type saveMessageParams []struct {
- offlineMessageIn state.OfflineMessage
- countOut int
- err error
- }
- // setOfflineMsgCountParams is the list of parameters passed at the mock
- // OfflineMessageManager.SetOfflineMsgCount call site
- type setOfflineMsgCountParams []struct {
- screenName state.IdentScreenName
- count int
- err error
- }
- // sessionRetrieverParams is a helper struct that contains mock parameters for
- // SessionRetriever methods
- type sessionRetrieverParams struct {
- retrieveSessionParams
- }
- // retrieveSessionParams is the list of parameters passed at the mock
- // SessionRetriever.RetrieveSession call site
- type retrieveSessionParams []struct {
- screenName state.IdentScreenName
- result *state.Session
- }
- // icqUserFinderParams is a helper struct that contains mock parameters for
- // ICQUserFinder methods
- type icqUserFinderParams struct {
- findByDetailsParams
- findByEmailParams
- findByInterestsParams
- findByUINParams
- searchICQUsersParams
- }
- // findByUINParams is the list of parameters passed at the mock
- // ICQUserFinder.FindByUIN call site
- type findByUINParams []struct {
- UIN uint32
- result state.User
- err error
- }
- // findByEmailParams is the list of parameters passed at the mock
- // ICQUserFinder.FindByEmail call site
- type findByEmailParams []struct {
- email string
- result state.User
- err error
- }
- // setBasicInfoParams is the list of parameters passed at the mock
- // ICQUserFinder.FindByDetails call site
- type findByDetailsParams []struct {
- firstName string
- lastName string
- nickName string
- result []state.User
- err error
- }
- // setBasicInfoParams is the list of parameters passed at the mock
- // ICQUserFinder.FindByInterests call site
- type findByInterestsParams []struct {
- code uint16
- keywords []string
- result []state.User
- err error
- }
- // searchICQUsersParams is the list of parameters passed at the mock
- // ICQUserFinder.SearchICQUsers call site.
- type searchICQUsersParams []struct {
- criteria state.ICQUserSearchCriteria
- result []state.User
- err error
- }
- // icqUserUpdaterParams is a helper struct that contains mock parameters for
- // ICQUserUpdater methods
- type icqUserUpdaterParams struct {
- setAffiliationsParams
- setBasicInfoParams
- setFullInfoParams
- setInterestsParams
- setMoreInfoParams
- setPermissionsParams
- setUserNotesParams
- setWorkInfoParams
- }
- // setAffiliationsParams is the list of parameters passed at the mock
- // ICQUserUpdater.SetAffiliations call site
- type setAffiliationsParams []struct {
- name state.IdentScreenName
- data state.ICQAffiliations
- err error
- }
- // setInterestsParams is the list of parameters passed at the mock
- // ICQUserUpdater.SetInterests call site
- type setInterestsParams []struct {
- name state.IdentScreenName
- data state.ICQInterests
- err error
- }
- // setUserNotesParams is the list of parameters passed at the mock
- // ICQUserUpdater.SetUserNotes call site
- type setUserNotesParams []struct {
- name state.IdentScreenName
- data state.ICQUserNotes
- err error
- }
- // setBasicInfoParams is the list of parameters passed at the mock
- // ICQUserUpdater.SetBasicInfo call site
- type setBasicInfoParams []struct {
- name state.IdentScreenName
- data state.ICQBasicInfo
- err error
- }
- // setFullInfoParams is the list of parameters passed at the mock
- // ICQUserUpdater.SetICQInfo call site
- type setFullInfoParams []struct {
- name state.IdentScreenName
- info state.ICQInfo
- err error
- }
- // setWorkInfoParams is the list of parameters passed at the mock
- // ICQUserUpdater.SetWorkInfo call site
- type setWorkInfoParams []struct {
- name state.IdentScreenName
- data state.ICQWorkInfo
- err error
- }
- // setMoreInfoParams is the list of parameters passed at the mock
- // ICQUserUpdater.SetMoreInfo call site
- type setMoreInfoParams []struct {
- name state.IdentScreenName
- data state.ICQMoreInfo
- err error
- }
- // setPermissionsParams is the list of parameters passed at the mock
- // ICQUserUpdater.SetPermissions call site
- type setPermissionsParams []struct {
- name state.IdentScreenName
- data state.ICQPermissions
- err error
- }
- // bartItemManagerParams is a helper struct that contains mock parameters for
- // BARTItemManager methods
- type bartItemManagerParams struct {
- bartItemManagerRetrieveParams
- bartItemManagerUpsertParams
- buddyIconMetadataParams
- }
- // bartItemManagerRetrieveParams is the list of parameters passed at the mock
- // BARTItemManager.BuddyIcon call site
- type bartItemManagerRetrieveParams []struct {
- itemHash []byte
- result []byte
- err error
- }
- // bartItemManagerUpsertParams is the list of parameters passed at the mock
- // BARTItemManager.SetBuddyIcon call site
- type bartItemManagerUpsertParams []struct {
- itemHash []byte
- payload []byte
- bartType uint16
- err error
- }
- // buddyIconMetadataParams is the list of parameters passed at the mock
- // BARTItemManager.BuddyIconMetadata call site
- type buddyIconMetadataParams []struct {
- screenName state.IdentScreenName
- result *wire.BARTID
- err error
- }
- // userManagerParams is a helper struct that contains mock parameters for
- // UserManager methods
- type userManagerParams struct {
- getUserParams
- }
- // getUserParams is the list of parameters passed at the mock
- // UserManager.User call site
- type getUserParams []struct {
- screenName state.IdentScreenName
- result *state.User
- err error
- }
- // sessionRegistryParams is a helper struct that contains mock parameters for
- // SessionRegistry methods
- type sessionRegistryParams struct {
- addSessionParams
- removeSessionParams
- }
- // addSessionParams is the list of parameters passed at the mock
- // SessionRegistry.AddSession call site
- type addSessionParams []struct {
- screenName state.DisplayScreenName
- doMultiSess bool
- result *state.SessionInstance
- err error
- }
- // removeSessionParams is the list of parameters passed at the mock
- // SessionRegistry.RemoveSession call site
- type removeSessionParams []struct {
- screenName state.IdentScreenName
- }
- // feedbagManagerParams is a helper struct that contains mock parameters for
- // FeedbagManager methods
- type feedbagManagerParams struct {
- adjacentUsersParams
- feedbagUpsertParams
- feedbagParams
- feedbagLastModifiedParams
- feedbagDeleteParams
- useParams
- }
- // adjacentUsersParams is the list of parameters passed at the mock
- // FeedbagManager.AdjacentUsers call site
- type adjacentUsersParams []struct {
- screenName state.IdentScreenName
- users []state.IdentScreenName
- err error
- }
- // feedbagUpsertParams is the list of parameters passed at the mock
- // FeedbagManager.FeedbagUpsert call site
- type feedbagUpsertParams []struct {
- screenName state.IdentScreenName
- items []wire.FeedbagItem
- }
- // useParams is the list of parameters passed at the mock
- // FeedbagManager.Use call site
- type useParams []struct {
- screenName state.IdentScreenName
- }
- // feedbagParams is the list of parameters passed at the mock
- // FeedbagManager.Feedbag call site
- type feedbagParams []struct {
- screenName state.IdentScreenName
- results []wire.FeedbagItem
- err error
- }
- // feedbagLastModifiedParams is the list of parameters passed at the mock
- // FeedbagManager.FeedbagLastModified call site
- type feedbagLastModifiedParams []struct {
- screenName state.IdentScreenName
- result time.Time
- }
- // feedbagDeleteParams is the list of parameters passed at the mock
- // FeedbagManager.FeedbagDelete call site
- type feedbagDeleteParams []struct {
- screenName state.IdentScreenName
- items []wire.FeedbagItem
- }
- // messageRelayerParams is a helper struct that contains mock parameters for
- // MessageRelayer methods
- type messageRelayerParams struct {
- relayToScreenNamesParams
- relayToScreenNameParams
- relayToOtherInstancesParams
- relayToScreenNameActiveOnlyParams
- relayToSelfParams
- }
- // relayToSelfParams is the list of parameters passed at the mock
- // MessageRelayer.RelayToSelf call site
- type relayToSelfParams []struct {
- screenName state.IdentScreenName
- message wire.SNACMessage
- }
- // relayToScreenNamesParams is the list of parameters passed at the mock
- // MessageRelayer.RelayToScreenNames call site
- type relayToScreenNamesParams []struct {
- screenNames []state.IdentScreenName
- message wire.SNACMessage
- }
- // relayToScreenNameParams is the list of parameters passed at the mock
- // MessageRelayer.RelayToScreenName call site
- type relayToScreenNameParams []struct {
- screenName state.IdentScreenName
- message wire.SNACMessage
- }
- // relayToOtherInstancesParams is the list of parameters passed at the mock
- // MessageRelayer.RelayToOtherInstances call site
- type relayToOtherInstancesParams []struct {
- screenName state.IdentScreenName
- message wire.SNACMessage
- }
- // relayToScreenNameActiveOnlyParams is the list of parameters passed at the mock
- // MessageRelayer.RelayToScreenNameActiveOnly call site
- type relayToScreenNameActiveOnlyParams []struct {
- screenName state.IdentScreenName
- message wire.SNACMessage
- }
- // profileManagerParams is a helper struct that contains mock parameters for
- // ProfileManager methods
- type profileManagerParams struct {
- findByAIMEmailParams
- findByAIMKeywordParams
- findByAIMNameAndAddrParams
- getUserParams
- interestListParams
- retrieveProfileParams
- setDirectoryInfoParams
- setKeywordsParams
- setProfileParams
- }
- // findByAIMEmailParams is the list of parameters passed at the mock
- // ProfileManager.FindByAIMEmail call site
- type findByAIMEmailParams []struct {
- email string
- result state.User
- err error
- }
- // findByAIMKeywordParams is the list of parameters passed at the mock
- // ProfileManager.FindByAIMKeyword call site
- type findByAIMKeywordParams []struct {
- keyword string
- result []state.User
- err error
- }
- // findByAIMNameAndAddrParams is the list of parameters passed at the mock
- // ProfileManager.FindByAIMNameAndAddr call site
- type findByAIMNameAndAddrParams []struct {
- info state.AIMNameAndAddr
- result []state.User
- err error
- }
- // interestListParams is the list of parameters passed at the mock
- // ProfileManager.InterestList call site
- type interestListParams []struct {
- result []wire.ODirKeywordListItem
- err error
- }
- // setDirectoryInfoParams is the list of parameters passed at the mock
- // ProfileManager.SetDirectoryInfo call site
- type setDirectoryInfoParams []struct {
- screenName state.IdentScreenName
- info state.AIMNameAndAddr
- err error
- }
- // retrieveProfileParams is the list of parameters passed at the mock
- // ProfileManager.Profile call site
- type retrieveProfileParams []struct {
- screenName state.IdentScreenName
- result state.UserProfile
- err error
- }
- // setProfileParams is the list of parameters passed at the mock
- // ProfileManager.SetProfile call site
- type setProfileParams []struct {
- screenName state.IdentScreenName
- body state.UserProfile
- }
- // setKeywordsParams is the list of parameters passed at the mock
- // ProfileManager.SetKeywords call site
- type setKeywordsParams []struct {
- screenName state.IdentScreenName
- keywords [5]string
- err error
- }
- // chatMessageRelayerParams is a helper struct that contains mock parameters
- // for ChatMessageRelayer methods
- type chatMessageRelayerParams struct {
- chatAllSessionsParams
- chatRelayToAllExceptParams
- chatRelayToScreenNameParams
- }
- // chatAllSessionsParams is the list of parameters passed at the mock
- // ChatMessageRelayer.AllSessions call site
- type chatAllSessionsParams []struct {
- cookie string
- sessions []*state.Session
- err error
- }
- // chatRelayToAllExceptParams is the list of parameters passed at the mock
- // ChatMessageRelayer.RelayToAllExcept call site
- type chatRelayToAllExceptParams []struct {
- cookie string
- screenName state.IdentScreenName
- message wire.SNACMessage
- err error
- }
- // chatRelayToScreenNameParams is the list of parameters passed at the mock
- // ChatMessageRelayer.RelayToScreenName call site
- type chatRelayToScreenNameParams []struct {
- cookie string
- screenName state.IdentScreenName
- message wire.SNACMessage
- err error
- }
- // clientSideBuddyListManagerParams is a helper struct that contains mock
- // parameters for ClientSideBuddyListManager methods
- type clientSideBuddyListManagerParams struct {
- addBuddyParams
- deleteBuddyParams
- denyBuddyParams
- permitBuddyParams
- removeDenyBuddyParams
- removePermitBuddyParams
- setPDModeParams
- }
- // legacyBuddiesParams is the list of parameters passed at the mock
- // ClientSideBuddyListManager.AddBuddy call site
- type addBuddyParams []struct {
- me state.IdentScreenName
- them state.IdentScreenName
- err error
- }
- // legacyBuddiesParams is the list of parameters passed at the mock
- // ClientSideBuddyListManager.RemoveBuddy call site
- type deleteBuddyParams []struct {
- me state.IdentScreenName
- them state.IdentScreenName
- err error
- }
- // deleteUserParams is the list of parameters passed at the mock
- // ClientSideBuddyListManager.RemoveBuddy call site
- type denyBuddyParams []struct {
- me state.IdentScreenName
- them state.IdentScreenName
- err error
- }
- // permitBuddyParams is the list of parameters passed at the mock
- // ClientSideBuddyListManager.PermitBuddy call site
- type permitBuddyParams []struct {
- me state.IdentScreenName
- them state.IdentScreenName
- err error
- }
- // removeDenyBuddyParams is the list of parameters passed at the mock
- // ClientSideBuddyListManager.RemoveDenyBuddy call site
- type removeDenyBuddyParams []struct {
- me state.IdentScreenName
- them state.IdentScreenName
- err error
- }
- // removePermitBuddyParams is the list of parameters passed at the mock
- // ClientSideBuddyListManager.RemovePermitBuddy call site
- type removePermitBuddyParams []struct {
- me state.IdentScreenName
- them state.IdentScreenName
- err error
- }
- // setPDModeParams is the list of parameters passed at the mock
- // ClientSideBuddyListManager.SetPDMode call site
- type setPDModeParams []struct {
- userScreenName state.IdentScreenName
- pdMode wire.FeedbagPDMode
- err error
- }
- // cookieBakerParams is a helper struct that contains mock parameters for
- // CookieBaker methods
- type cookieBakerParams struct {
- cookieIssueParams
- }
- // cookieIssueParams is the list of parameters passed at the mock
- // CookieBaker.Issue call site
- type cookieIssueParams []struct {
- dataIn []byte
- cookieOut []byte
- err error
- }
- // accountManagerParams is a helper struct that contains mock parameters for
- // accountManager methods
- type accountManagerParams struct {
- accountManagerUpdateDisplayScreenNameParams
- accountManagerUpdateEmailAddressParams
- accountManagerEmailAddressParams
- accountManagerUpdateRegStatusParams
- accountManagerRegStatusParams
- accountManagerUpdateConfirmStatusParams
- accountManagerConfirmStatusParams
- accountManagerUserParams
- accountManagerSetUserPasswordParams
- }
- // accountManagerUpdateDisplayScreenNameParams is the list of parameters passed at the mock
- // accountManager.UpdateDisplayScreenName call site
- type accountManagerUpdateDisplayScreenNameParams []struct {
- displayScreenName state.DisplayScreenName
- err error
- }
- // accountManagerUpdateEmailAddressParams is the list of parameters passed at the mock
- // accountManager.UpdateEmailAddress call site
- type accountManagerUpdateEmailAddressParams []struct {
- emailAddress *mail.Address
- screenName state.IdentScreenName
- err error
- }
- // accountManagerEmailAddressParams is the list of parameters passed at the mock
- // accountManager.EmailAddress call site
- type accountManagerEmailAddressParams []struct {
- screenName state.IdentScreenName
- emailAddress *mail.Address
- err error
- }
- // accountManagerUpdateRegStatusParams is the list of parameters passed at the mock
- // accountManager.UpdateRegStatus call site
- type accountManagerUpdateRegStatusParams []struct {
- regStatus uint16
- screenName state.IdentScreenName
- err error
- }
- // accountManagerRegStatusParams is the list of parameters passed at the mock
- // accountManager.RegStatus call site
- type accountManagerRegStatusParams []struct {
- screenName state.IdentScreenName
- regStatus uint16
- err error
- }
- // accountManagerUpdateConfirmStatusParams is the list of parameters passed at the mock
- // accountManager.UpdateConfirmStatus call site
- type accountManagerUpdateConfirmStatusParams []struct {
- confirmStatus bool
- screenName state.IdentScreenName
- err error
- }
- // accountManagerConfirmStatusParams is the list of parameters passed at the mock
- // accountManager.ConfirmStatus call site
- type accountManagerConfirmStatusParams []struct {
- screenName state.IdentScreenName
- confirmStatus bool
- err error
- }
- // accountManagerUserParams is the list of parameters passed at the mock
- // accountManager.User call site
- type accountManagerUserParams []struct {
- screenName state.IdentScreenName
- result *state.User
- err error
- }
- // accountManagerSetUserPasswordParams is the list of parameters passed at the mock
- // accountManager.SetUserPassword call site
- type accountManagerSetUserPasswordParams []struct {
- screenName state.IdentScreenName
- password string
- err error
- }
- // buddyBroadcasterParams is a helper struct that contains mock parameters for
- // buddyBroadcaster methods
- type buddyBroadcasterParams struct {
- broadcastBuddyArrivedParams
- broadcastBuddyDepartedParams
- broadcastVisibilityParams
- }
- // broadcastVisibilityParams is the list of parameters passed at the mock
- // buddyBroadcaster.BroadcastVisibility call site
- type broadcastVisibilityParams []struct {
- from state.IdentScreenName
- filter []state.IdentScreenName
- doSendDepartures bool
- err error
- }
- // broadcastBuddyArrivedParams is the list of parameters passed at the mock
- // buddyBroadcaster.BroadcastBuddyArrived call site
- type broadcastBuddyArrivedParams []struct {
- screenName state.DisplayScreenName
- err error
- bodyMatcher func(snac wire.TLVUserInfo) bool
- }
- // broadcastBuddyDepartedParams is the list of parameters passed at the mock
- // buddyBroadcaster.BroadcastBuddyDeparted call site
- type broadcastBuddyDepartedParams []struct {
- screenName state.IdentScreenName
- err error
- }
- // chatRoomRegistryParams is a helper struct that contains mock parameters for
- // ChatRoomRegistry methods
- type chatRoomRegistryParams struct {
- chatRoomByCookieParams
- chatRoomByNameParams
- createChatRoomParams
- }
- // chatRoomByCookieParams is the list of parameters passed at the mock
- // ChatRoomRegistry.ChatRoomByCookie call site
- type chatRoomByCookieParams []struct {
- cookie string
- room state.ChatRoom
- err error
- }
- // chatRoomByCookieParams is the list of parameters passed at the mock
- // ChatRoomRegistry.ChatRoomByName call site
- type chatRoomByNameParams []struct {
- exchange uint16
- name string
- room state.ChatRoom
- err error
- }
- // createChatRoomParams is the list of parameters passed at the mock
- // ChatRoomRegistry.CreateChatRoom call site
- type createChatRoomParams []struct {
- room *state.ChatRoom
- err error
- }
- // sessOptWarning sets a warning level on the session object
- func sessOptWarning(level int16) func(instance *state.SessionInstance) {
- return func(instance *state.SessionInstance) {
- instance.Session().SetWarning(uint16(level))
- }
- }
- // sessOptCannedAwayMessage sets a canned away message ("this is my away
- // message!") on the session object
- func sessOptCannedAwayMessage(instance *state.SessionInstance) {
- instance.SetAwayMessage("this is my away message!")
- }
- // sessOptUserInfoFlag sets a user info flag on the session object
- func sessOptUserInfoFlag(flag uint16) func(instance *state.SessionInstance) {
- return func(instance *state.SessionInstance) {
- instance.SetUserInfoFlag(flag)
- }
- }
- // sessOptCannedSignonTime sets a canned sign-on time (1696790127565) on the
- // session object
- func sessOptCannedSignonTime(instance *state.SessionInstance) {
- instance.Session().SetSignonTime(time.UnixMilli(1696790127565))
- }
- // sessOptChatRoomCookie sets cookie on the session object
- func sessOptChatRoomCookie(cookie string) func(instance *state.SessionInstance) {
- return func(instance *state.SessionInstance) {
- instance.Session().SetChatRoomCookie(cookie)
- }
- }
- // sessOptBot sets the bot flag to true on the session
- // object
- func sessOptBot(instance *state.SessionInstance) {
- instance.SetUserInfoFlag(wire.OServiceUserFlagBot)
- }
- // sessOptInvisible sets the invisible flag to true on the session
- // object
- func sessOptInvisible(instance *state.SessionInstance) {
- instance.SetUserStatusBitmask(wire.OServiceUserStatusInvisible)
- }
- // sessOptIdle sets the idle flag to dur on the session object
- func sessOptIdle(dur time.Duration) func(instance *state.SessionInstance) {
- return func(instance *state.SessionInstance) {
- instance.SetIdle(dur)
- }
- }
- // sessOptSignonComplete sets the sign on complete flag to true
- func sessOptSignonComplete(instance *state.SessionInstance) {
- instance.SetSignonComplete()
- }
- // sessOptContactsInit sets the contacts-init flag to true
- func sessOptContactsInit(instance *state.SessionInstance) {
- instance.SetContactsInit()
- }
- // sessOptCaps sets caps
- func sessOptUIN(UIN uint32) func(instance *state.SessionInstance) {
- return func(instance *state.SessionInstance) {
- instance.Session().SetUIN(UIN)
- }
- }
- // sessOptCaps sets caps
- func sessOptWantTypingEvents(instance *state.SessionInstance) {
- instance.Session().SetTypingEventsEnabled(true)
- }
- // sessOptMultiConnFlag sets the multi-connection flag on the session instance
- func sessOptMultiConnFlag(flag wire.MultiConnFlag) func(instance *state.SessionInstance) {
- return func(instance *state.SessionInstance) {
- instance.SetMultiConnFlag(flag)
- }
- }
- // sessOptSetFoodGroupVersion sets food group versions
- func sessOptSetFoodGroupVersion(foodGroup uint16, version uint16) func(instance *state.SessionInstance) {
- return func(instance *state.SessionInstance) {
- var versions [wire.MDir + 1]uint16
- versions[foodGroup] = version
- instance.SetFoodGroupVersions(versions)
- }
- }
- // sessOptSetRateClasses sets rate limit classes
- func sessOptSetRateClasses(classes wire.RateLimitClasses) func(instance *state.SessionInstance) {
- return func(instance *state.SessionInstance) {
- instance.Session().SetRateClasses(time.Now(), classes)
- }
- }
- // sessOptMemberSince sets the member since timestamp on the session object.
- func sessOptMemberSince(t time.Time) func(instance *state.SessionInstance) {
- return func(instance *state.SessionInstance) {
- instance.Session().SetMemberSince(t)
- }
- }
- // sessOptSignonTime sets the sign-on time on the session object.
- func sessOptSignonTime(t time.Time) func(instance *state.SessionInstance) {
- return func(instance *state.SessionInstance) {
- instance.Session().SetSignonTime(t)
- }
- }
- // sessOptProfile sets profile
- func sessOptProfile(profile state.UserProfile) func(instance *state.SessionInstance) {
- return func(instance *state.SessionInstance) {
- instance.SetProfile(profile)
- }
- }
- // sessOptKerberosAuth indicates the session signed on
- func sessOptKerberosAuth(instance *state.SessionInstance) {
- instance.SetKerberosAuth(true)
- }
- // sessClientID sets the client ID
- func sessClientID(clientID string) func(instance *state.SessionInstance) {
- return func(instance *state.SessionInstance) {
- instance.SetClientID(clientID)
- }
- }
- // sessRemoteAddr sets the client's ip address / port
- func sessRemoteAddr(remoteAddr netip.AddrPort) func(instance *state.SessionInstance) {
- return func(instance *state.SessionInstance) {
- instance.SetRemoteAddr(&remoteAddr)
- }
- }
- // sessOptAllInactive makes all instances in the session group inactive (away/idle/closed)
- func sessOptAllInactive(instance *state.SessionInstance) {
- // Set away message to make instance inactive
- instance.SetAwayMessage("away message")
- // Also set idle to ensure it's inactive
- instance.SetIdle(time.Hour)
- }
- // sessOptSomeActive ensures some instances are active (not all inactive)
- func sessOptSomeActive(instance *state.SessionInstance) {
- // Don't set away message or idle - keep instance active
- // This simulates a multisession scenario where at least one instance is active
- }
- // sessOptClosed makes the session instance closed (inactive)
- func sessOptClosed(instance *state.SessionInstance) {
- instance.CloseInstance()
- }
- // sessOptMixedStates simulates a multisession scenario with mixed states
- // This would require multiple instances, but for testing purposes we'll just
- // keep the instance active to simulate having some active sessions
- func sessOptMixedStates(instance *state.SessionInstance) {
- // Keep instance active to simulate mixed states scenario
- // In a real multisession scenario, this would have multiple instances
- // with some active and some inactive
- }
- // sessOptFeedbagEnabled marks the instance as using the feedbag buddy list this sign-on.
- func sessOptFeedbagEnabled(instance *state.SessionInstance) {
- instance.Session().SetUsesFeedbag()
- }
- // sessBuddyIcon sets session buddy icon
- func sessOptBuddyIcon(icon wire.BARTID) func(instance *state.SessionInstance) {
- return func(instance *state.SessionInstance) {
- instance.Session().SetBuddyIcon(icon)
- }
- }
- // sessOptOfflineMsgCount sets the offline message count on the session object.
- func sessOptOfflineMsgCount(count int) func(instance *state.SessionInstance) {
- return func(instance *state.SessionInstance) {
- instance.Session().SetOfflineMsgCount(count)
- }
- }
- // newTestInstance creates a session object with 0 or more functional options
- // applied
- func newTestInstance(screenName state.DisplayScreenName, options ...func(instance *state.SessionInstance)) *state.SessionInstance {
- session := state.NewSession()
- session.SetIdentScreenName(screenName.IdentScreenName())
- session.SetDisplayScreenName(screenName)
- session.SetRateClasses(time.Now(), wire.DefaultRateLimitClasses())
- instance := session.AddInstance()
- for _, op := range options {
- op(instance)
- }
- return instance
- }
- // matchSession matches a mock call based session ident screen name.
- func matchSession(mustMatch state.IdentScreenName) interface{} {
- return mock.MatchedBy(func(s *state.SessionInstance) bool {
- return mustMatch == s.IdentScreenName()
- })
- }
- // matchUserSession matches a mock call for *state.Session by ident screen name.
- func matchUserSession(mustMatch state.IdentScreenName) interface{} {
- return mock.MatchedBy(func(s *state.Session) bool {
- return mustMatch == s.IdentScreenName()
- })
- }
- // matchContext matches any instance of Context interface.
- func matchContext() interface{} {
- return mock.MatchedBy(func(ctx any) bool {
- _, ok := ctx.(context.Context)
- return ok
- })
- }
|