package schedulers

import (
	"context"
	"testing"

	commM "github.com/pingcap/test-infra/common/model"
	"github.com/pingcap/test-infra/services/tps/pkg/common"
	"github.com/stretchr/testify/assert"
)

func newJobByCaseCount(count int) *common.ArgoJob {
	return &common.ArgoJob{PlanExec: &commM.TestPlanExecution{}, Plan: &commM.TestPlan{TestPlanBase: commM.TestPlanBase{Pipeline: make([]commM.PipelineStep, count)}}}
}

func TestSorter_Filter(t *testing.T) {
	s := &Sorter{}
	jobs := []*common.ArgoJob{newJobByCaseCount(5), newJobByCaseCount(10), newJobByCaseCount(6)}
	expected := []*common.ArgoJob{jobs[1], jobs[2], jobs[0]}
	filtered, err := s.Filter(context.TODO(), jobs)
	assert.NoError(t, err)
	assert.Equal(t, expected, filtered)
}
