@@ -651,41 +651,42 @@ func TestDirector_HandleRequest(t *testing.T) {
651651 ds .PodUpdateOrAddIfNotExist (testPod )
652652 }
653653
654- for _ , test := range tests {
655- t .Run (test .name , func (t * testing.T ) {
656- mockSched := & mockScheduler {}
657- if test .schedulerMockSetup != nil {
658- test .schedulerMockSetup (mockSched )
659- }
660- config := NewConfig ()
661- if test .prepareDataPlugin != nil {
662- config = config .WithPrepareDataPlugins (test .prepareDataPlugin )
663- }
664- config = config .WithAdmissionPlugins (newMockAdmissionPlugin ("test-admit-plugin" , test .admitRequestDenialError ))
665-
666- locator := NewCachedPodLocator (context .Background (), NewDatastorePodLocator (ds ), time .Minute )
667- director := NewDirectorWithConfig (ds , mockSched , test .mockAdmissionController , locator , config )
668- if test .name == "successful request with model rewrite" {
669- mockDs := & mockDatastore {
670- pods : ds .PodList (datastore .AllPodsPredicate ),
671- rewrites : []* v1alpha2.InferenceModelRewrite {rewrite },
672- }
673- director .datastore = mockDs
674- director .podLocator = NewCachedPodLocator (context .Background (), NewDatastorePodLocator (mockDs ), time .Minute )
654+ for _ , test := range tests {
655+ t .Run (test .name , func (t * testing.T ) {
656+ mockSched := & mockScheduler {}
657+ if test .schedulerMockSetup != nil {
658+ test .schedulerMockSetup (mockSched )
659+ }
660+ config := NewConfig ()
661+ if test .prepareDataPlugin != nil {
662+ config = config .WithPrepareDataPlugins (test .prepareDataPlugin )
663+ }
664+ config = config .WithAdmissionPlugins (newMockAdmissionPlugin ("test-admit-plugin" , test .admitRequestDenialError ))
665+
666+ locator := NewCachedPodLocator (context .Background (), NewDatastorePodLocator (ds ), time .Minute )
667+ director := NewDirectorWithConfig (ds , mockSched , test .mockAdmissionController , locator , config )
668+ if test .name == "successful request with model rewrite" {
669+ mockDs := & mockDatastore {
670+ pods : ds .PodList (datastore .AllPodsPredicate ),
671+ rewrites : []* v1alpha2.InferenceModelRewrite {rewrite },
675672 }
676- reqCtx := & handlers.RequestContext {
677- Request : & handlers.Request {
678- // Create a copy of the map for each test run to avoid mutation issues.
679- Body : make (map [string ]any ),
680- Headers : map [string ]string {
681- requtil .RequestIdHeaderKey : "test-req-id-" + test .name , // Ensure a default request ID
682- },
673+ director .datastore = mockDs
674+ director .podLocator = NewCachedPodLocator (context .Background (), NewDatastorePodLocator (mockDs ), time .Minute )
675+ }
676+
677+ reqCtx := & handlers.RequestContext {
678+ Request : & handlers.Request {
679+ // Create a copy of the map for each test run to avoid mutation issues.
680+ Body : make (map [string ]any ),
681+ Headers : map [string ]string {
682+ requtil .RequestIdHeaderKey : "test-req-id-" + test .name , // Ensure a default request ID
683683 },
684- ObjectiveKey : test .inferenceObjectiveName ,
685- TargetModelName : test .initialTargetModelName ,
686- }
687- // Deep copy the body map.
688- maps .Copy (reqCtx .Request .Body , test .reqBodyMap )
684+ },
685+ ObjectiveKey : test .inferenceObjectiveName ,
686+ TargetModelName : test .initialTargetModelName ,
687+ }
688+ // Deep copy the body map.
689+ maps .Copy (reqCtx .Request .Body , test .reqBodyMap )
689690
690691 returnedReqCtx , err := director .HandleRequest (ctx , reqCtx )
691692
@@ -708,13 +709,12 @@ func TestDirector_HandleRequest(t *testing.T) {
708709 assert .Equal (t , test .wantReqCtx .TargetEndpoint , returnedReqCtx .TargetEndpoint , "reqCtx.TargetEndpoint mismatch" )
709710 }
710711
711- if test .wantMutatedBodyModel != "" {
712- assert .NotNil (t , returnedReqCtx .Request .Body , "Expected mutated body, but reqCtx.Request.Body is nil" )
713- assert .Equal (t , test .wantMutatedBodyModel , returnedReqCtx .Request .Body ["model" ],
714- "Mutated reqCtx.Request.Body model mismatch" )
715- }
716- })
717- }
712+ if test .wantMutatedBodyModel != "" {
713+ assert .NotNil (t , returnedReqCtx .Request .Body , "Expected mutated body, but reqCtx.Request.Body is nil" )
714+ assert .Equal (t , test .wantMutatedBodyModel , returnedReqCtx .Request .Body ["model" ],
715+ "Mutated reqCtx.Request.Body model mismatch" )
716+ }
717+ })
718718 }
719719}
720720
0 commit comments