Browse Source

fix tests

Mike 4 months ago
parent
commit
a309c6b77f
4 changed files with 29 additions and 12 deletions
  1. 3 3
      foodgroup/auth_test.go
  2. 7 0
      foodgroup/helpers_test.go
  3. 18 8
      server/oscar/server_test.go
  4. 1 1
      server/toc/cmd_client_test.go

+ 3 - 3
foodgroup/auth_test.go

@@ -1939,7 +1939,7 @@ func TestAuthService_RegisterBOSSession(t *testing.T) {
 			sessionRegistry := newMockSessionRegistry(t)
 			for _, params := range tc.mockParams.addSessionParams {
 				sessionRegistry.EXPECT().
-					AddSession(mock.Anything, params.screenName, params.doMultiSess).
+					AddSession(mock.Anything, params.screenName, params.doMultiSess, mock.Anything, mock.Anything).
 					Return(params.result, params.err)
 			}
 			userManager := newMockUserManager(t)
@@ -2153,11 +2153,11 @@ func TestAuthService_Signout(t *testing.T) {
 		t.Run(tt.name, func(t *testing.T) {
 			sessionManager := newMockSessionRegistry(t)
 			for _, params := range tt.mockParams.removeSessionParams {
-				sessionManager.EXPECT().RemoveSession(matchSession(params.screenName))
+				sessionManager.EXPECT().RemoveSession(matchUserSession(params.screenName))
 			}
 			svc := NewAuthService(config.Config{}, sessionManager, nil, nil, nil, nil, nil, nil, nil, wire.DefaultRateLimitClasses(), nil, slog.Default())
 
-			svc.Signout(context.Background(), tt.instance)
+			svc.Signout(context.Background(), tt.instance.Session())
 		})
 	}
 }

+ 7 - 0
foodgroup/helpers_test.go

@@ -953,6 +953,13 @@ func matchSession(mustMatch state.IdentScreenName) interface{} {
 	})
 }
 
+// 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 {

+ 18 - 8
server/oscar/server_test.go

@@ -371,12 +371,17 @@ func TestOscarServer_RouteConnection_BOS(t *testing.T) {
 
 	authService := newMockAuthService(t)
 	authService.EXPECT().
-		RegisterBOSSession(mock.Anything, state.ServerCookie{Service: wire.BOS}).
+		RegisterBOSSession(mock.Anything, state.ServerCookie{Service: wire.BOS}, mock.Anything).
+		Run(func(ctx context.Context, cookie state.ServerCookie, conf func(*state.Session)) {
+			if conf != nil {
+				conf(instance.Session())
+			}
+		}).
 		Return(instance, nil)
 	wg.Add(1)
 	authService.EXPECT().
-		Signout(mock.Anything, instance).
-		Run(func(ctx context.Context, s *state.SessionInstance) {
+		Signout(mock.Anything, instance.Session()).
+		Run(func(ctx context.Context, s *state.Session) {
 			defer wg.Done()
 		})
 
@@ -495,7 +500,7 @@ func TestOscarServer_RouteConnection_BOS_MultiSessionSignoff(t *testing.T) {
 
 	authService := newMockAuthService(t)
 	authService.EXPECT().
-		RegisterBOSSession(mock.Anything, state.ServerCookie{Service: wire.BOS}).
+		RegisterBOSSession(mock.Anything, state.ServerCookie{Service: wire.BOS}, mock.Anything).
 		Return(instance, nil)
 
 	authService.EXPECT().
@@ -598,7 +603,7 @@ func TestOscarServer_RouteConnection_BOS_MaxConcurrentSessionsReached(t *testing
 
 	authService := newMockAuthService(t)
 	authService.EXPECT().
-		RegisterBOSSession(mock.Anything, state.ServerCookie{Service: wire.BOS}).
+		RegisterBOSSession(mock.Anything, state.ServerCookie{Service: wire.BOS}, mock.Anything).
 		Return(nil, state.ErrMaxConcurrentSessionsReached)
 
 	authService.EXPECT().
@@ -913,14 +918,19 @@ func Test_oscarServer_receiveSessMessages_BOS_integration(t *testing.T) {
 		CrackCookie(mock.Anything).
 		Return(state.ServerCookie{Service: wire.BOS}, nil)
 	authService.EXPECT().
-		RegisterBOSSession(mock.Anything, state.ServerCookie{Service: wire.BOS}).
+		RegisterBOSSession(mock.Anything, state.ServerCookie{Service: wire.BOS}, mock.Anything).
+		Run(func(ctx context.Context, cookie state.ServerCookie, conf func(*state.Session)) {
+			if conf != nil {
+				conf(instance.Session())
+			}
+		}).
 		Return(instance, nil)
 
 	var signoutWG sync.WaitGroup
 	signoutWG.Add(1)
 	authService.EXPECT().
-		Signout(mock.Anything, instance).
-		Run(func(ctx context.Context, s *state.SessionInstance) { signoutWG.Done() })
+		Signout(mock.Anything, instance.Session()).
+		Run(func(ctx context.Context, s *state.Session) { signoutWG.Done() })
 
 	onlineNotifier := newMockOnlineNotifier(t)
 	onlineNotifier.EXPECT().

+ 1 - 1
server/toc/cmd_client_test.go

@@ -6915,7 +6915,7 @@ func TestOSCARProxy_Signon(t *testing.T) {
 			}
 			for _, params := range tc.mockParams.registerBOSSessionParams {
 				authSvc.EXPECT().
-					RegisterBOSSession(matchContext(), params.authCookie).
+					RegisterBOSSession(matchContext(), params.authCookie, mock.Anything).
 					Return(params.instance, params.err)
 			}
 			buddyRegistry := newMockBuddyListRegistry(t)