@@ -49,15 +49,15 @@ func TestHandleRequestBody(t *testing.T) {
49
49
// Setup datastore
50
50
tsModel := "food-review"
51
51
modelWithTarget := "food-review-0"
52
- model1ts := testutil .MakeInferenceModel ("model1" ).
52
+ model1 := testutil .MakeInferenceModel ("model1" ).
53
53
CreationTimestamp (metav1 .Unix (1000 , 0 )).
54
54
ModelName (tsModel ).ObjRef ()
55
55
model2 := testutil .MakeInferenceModel ("model2" ).
56
56
CreationTimestamp (metav1 .Unix (1000 , 0 )).
57
57
ModelName (modelWithTarget ).ObjRef ()
58
58
pmf := backendmetrics .NewPodMetricsFactory (& backendmetrics.FakePodMetricsClient {}, time .Second )
59
59
ds := datastore .NewDatastore (t .Context (), pmf )
60
- ds .ModelSetIfOlder (model1ts )
60
+ ds .ModelSetIfOlder (model1 )
61
61
ds .ModelSetIfOlder (model2 )
62
62
63
63
pool := & v1alpha2.InferencePool {
@@ -82,9 +82,7 @@ func TestHandleRequestBody(t *testing.T) {
82
82
tests := []struct {
83
83
name string
84
84
reqBodyMap map [string ]interface {}
85
- reqCtx * RequestContext
86
85
wantErrCode string
87
- wantErr bool
88
86
wantReqCtx * RequestContext
89
87
wantRespBody map [string ]interface {}
90
88
}{
@@ -124,7 +122,6 @@ func TestHandleRequestBody(t *testing.T) {
124
122
},
125
123
{
126
124
name : "no model defined, expect err" ,
127
- wantErr : true ,
128
125
wantErrCode : errutil .BadRequest ,
129
126
},
130
127
{
@@ -133,7 +130,6 @@ func TestHandleRequestBody(t *testing.T) {
133
130
"model" : "non-existent-model" ,
134
131
"prompt" : "test prompt" ,
135
132
},
136
- wantErr : true ,
137
133
wantErrCode : errutil .BadConfiguration ,
138
134
},
139
135
{
@@ -142,22 +138,18 @@ func TestHandleRequestBody(t *testing.T) {
142
138
"model" : "food-review-1" ,
143
139
"prompt" : "test prompt" ,
144
140
},
145
- wantErr : true ,
146
141
wantErrCode : errutil .BadConfiguration ,
147
142
},
148
143
}
149
144
150
145
for _ , test := range tests {
151
146
t .Run (test .name , func (t * testing.T ) {
152
147
server := NewStreamingServer (scheduling .NewScheduler (ds ), DefaultDestinationEndpointHintMetadataNamespace , DefaultDestinationEndpointHintKey , ds )
153
- reqCtx := test .reqCtx
154
- if reqCtx == nil {
155
- reqCtx = & RequestContext {}
156
- }
148
+ reqCtx := & RequestContext {}
157
149
req := & extProcPb.ProcessingRequest {}
158
- gotReqCtx , err := server .HandleRequestBody (ctx , reqCtx , req , test .reqBodyMap )
150
+ reqCtx , err := server .HandleRequestBody (ctx , reqCtx , req , test .reqBodyMap )
159
151
160
- if test .wantErr {
152
+ if test .wantErrCode != "" {
161
153
if err == nil {
162
154
t .Fatalf ("HandleRequestBody should have returned an error containing '%s', but got nil" , test .wantErrCode )
163
155
}
@@ -172,16 +164,16 @@ func TestHandleRequestBody(t *testing.T) {
172
164
}
173
165
174
166
if test .wantReqCtx != nil {
175
- if diff := cmp .Diff (test .wantReqCtx .Model , gotReqCtx .Model ); diff != "" {
167
+ if diff := cmp .Diff (test .wantReqCtx .Model , reqCtx .Model ); diff != "" {
176
168
t .Errorf ("HandleRequestBody returned unexpected reqCtx.Model, diff(-want, +got): %v" , diff )
177
169
}
178
- if diff := cmp .Diff (test .wantReqCtx .ResolvedTargetModel , gotReqCtx .ResolvedTargetModel ); diff != "" {
170
+ if diff := cmp .Diff (test .wantReqCtx .ResolvedTargetModel , reqCtx .ResolvedTargetModel ); diff != "" {
179
171
t .Errorf ("HandleRequestBody returned unexpected reqCtx.ResolvedTargetModel, diff(-want, +got): %v" , diff )
180
172
}
181
- if diff := cmp .Diff (test .wantReqCtx .TargetPod , gotReqCtx .TargetPod ); diff != "" {
173
+ if diff := cmp .Diff (test .wantReqCtx .TargetPod , reqCtx .TargetPod ); diff != "" {
182
174
t .Errorf ("HandleRequestBody returned unexpected reqCtx.TargetPod, diff(-want, +got): %v" , diff )
183
175
}
184
- if diff := cmp .Diff (test .wantReqCtx .TargetEndpoint , gotReqCtx .TargetEndpoint ); diff != "" {
176
+ if diff := cmp .Diff (test .wantReqCtx .TargetEndpoint , reqCtx .TargetEndpoint ); diff != "" {
185
177
t .Errorf ("HandleRequestBody returned unexpected reqCtx.TargetEndpoint, diff(-want, +got): %v" , diff )
186
178
}
187
179
}
0 commit comments