Skip to content

Commit ebb6739

Browse files
committed
Add unit tests for request body
1 parent d9cb903 commit ebb6739

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

pkg/epp/scheduling/plugins/filter/filter_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ func TestFilter(t *testing.T) {
5454
ctx := types.NewSchedulingContext(context.Background(), test.req, test.input)
5555
got := test.filter.Filter(ctx, test.input)
5656

57-
if diff := cmp.Diff(test.output, got); diff != "" {
57+
opt := cmp.AllowUnexported(types.PodMetrics{})
58+
if diff := cmp.Diff(test.output, got, opt); diff != "" {
5859
t.Errorf("Unexpected output (-want +got): %v", diff)
5960
}
6061
})
@@ -189,7 +190,8 @@ func TestFilterFunc(t *testing.T) {
189190
ctx := types.NewSchedulingContext(context.Background(), test.req, test.input)
190191
got := test.f(ctx, test.input)
191192

192-
if diff := cmp.Diff(test.output, got); diff != "" {
193+
opt := cmp.AllowUnexported(types.PodMetrics{})
194+
if diff := cmp.Diff(test.output, got, opt); diff != "" {
193195
t.Errorf("Unexpected output (-want +got): %v", diff)
194196
}
195197
})

pkg/epp/scheduling/scheduler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ func NewSchedulerWithConfig(datastore Datastore, config *SchedulerConfig) *Sched
8080
picker: config.picker,
8181
postSchedulePlugins: config.postSchedulePlugins,
8282
}
83+
84+
return scheduler
8385
}
8486

8587
type Scheduler struct {

pkg/epp/scheduling/scheduler_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,17 @@ func TestSchedule(t *testing.T) {
220220
},
221221
}
222222

223+
schedConfig := &SchedulerConfig{
224+
preSchedulePlugins: []plugins.PreSchedule{},
225+
scorers: []plugins.Scorer{},
226+
filters: []plugins.Filter{defPlugin},
227+
postSchedulePlugins: []plugins.PostSchedule{},
228+
picker: defPlugin,
229+
}
230+
223231
for _, test := range tests {
224232
t.Run(test.name, func(t *testing.T) {
225-
scheduler := NewScheduler(&fakeDataStore{pods: test.input})
233+
scheduler := NewSchedulerWithConfig(&fakeDataStore{pods: test.input}, schedConfig)
226234
got, err := scheduler.Schedule(context.Background(), test.req)
227235
if test.err != (err != nil) {
228236
t.Errorf("Unexpected error, got %v, want %v", err, test.err)

pkg/epp/scheduling/types/types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ func (r *LLMRequest) String() string {
4343
type Pod interface {
4444
GetPod() *backendmetrics.Pod
4545
GetMetrics() *backendmetrics.Metrics
46+
SetScore(float64)
47+
Score() float64
4648
String() string
4749
}
4850

@@ -74,7 +76,16 @@ func (pm *PodMetrics) GetMetrics() *backendmetrics.Metrics {
7476
return pm.Metrics
7577
}
7678

79+
func (pm *PodMetrics) SetScore(score float64) {
80+
pm.score = score
81+
}
82+
83+
func (pm *PodMetrics) Score() float64 {
84+
return pm.score
85+
}
86+
7787
type PodMetrics struct {
88+
score float64
7889
*backendmetrics.Pod
7990
*backendmetrics.Metrics
8091
}

0 commit comments

Comments
 (0)