Files
milvus/internal/proxy/task_validator_test.go
congqixiaandGitHub 7311d450a0 enhance: bump Go dependencies to v3 modules (#49485)
Related to #49398

Bump Go module references from pkg/v2 and milvus-proto/go-api/v2 to
pkg/v3 and milvus-proto/go-api/v3 so the client tracks the Milvus 3.x
release line.

This prepares the repository for the upcoming 3.x.y release by aligning
imports, module dependencies, and proto API references with the new
major-version module paths.

---------

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
2026-05-01 10:30:13 +08:00

102 lines
2.1 KiB
Go

package proxy
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/milvus-io/milvus/pkg/v3/proto/internalpb"
"github.com/milvus-io/milvus/pkg/v3/util/paramtable"
)
func TestValidateTask(t *testing.T) {
// Initialize paramtable for testing
paramtable.Init()
paramtable.Get().Save(paramtable.Get().ProxyCfg.MaxResultEntries.Key, "1000000")
defer paramtable.Get().Save(paramtable.Get().ProxyCfg.MaxResultEntries.Key, "-1")
tests := []struct {
name string
task any
expectError bool
errorMsg string
}{
{
name: "valid search task",
task: &searchTask{
SearchRequest: &internalpb.SearchRequest{
Nq: 10,
Topk: 100,
IsAdvanced: false,
},
},
expectError: false,
},
{
name: "invalid search task",
task: &searchTask{
SearchRequest: &internalpb.SearchRequest{
Nq: 1000,
Topk: 2000,
IsAdvanced: false,
},
},
expectError: true,
errorMsg: "number of result entries is too large",
},
{
name: "invalid search task with group size",
task: &searchTask{
SearchRequest: &internalpb.SearchRequest{
Nq: 100,
Topk: 200,
GroupSize: 100,
IsAdvanced: false,
},
},
expectError: true,
errorMsg: "number of result entries is too large",
},
{
name: "invalid search task with sub-request",
task: &searchTask{
SearchRequest: &internalpb.SearchRequest{
IsAdvanced: true,
SubReqs: []*internalpb.SubSearchRequest{
{
Nq: 100,
Topk: 200,
GroupSize: 100,
},
},
},
},
expectError: true,
errorMsg: "number of result entries is too large",
},
{
name: "non-search task should return nil",
task: "not a search task",
expectError: false,
},
{
name: "nil task should return nil",
task: nil,
expectError: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := ValidateTask(tt.task)
if tt.expectError {
assert.Error(t, err)
assert.Contains(t, err.Error(), tt.errorMsg)
} else {
assert.NoError(t, err)
}
})
}
}