test: fix stale Doris SQL-shape and flaky OSS bucket assertions

Two pre-existing test failures on main, unrelated to any feature change:

- Doris VectorRetrieve/KeywordsRetrieve inline LIMIT as a literal (Doris
  does not support placeholders for LIMIT/OFFSET), but the SQL-shape tests
  still expected `LIMIT ?` with TopK as a bound arg. Match the literal
  LIMIT and drop the extra argument.
- TestOssEnsureBucket_CreateFails used the bucket name "test-bucket",
  which already exists globally on OSS, so IsBucketExist short-circuited
  and the create path never ran. Use a non-existent bucket name so the
  create-with-invalid-credentials path is actually exercised.
This commit is contained in:
wizardchen
2026-06-29 17:43:38 +08:00
committed by lyingbug
parent af432c5e06
commit 40f217c228
2 changed files with 14 additions and 7 deletions
@@ -265,8 +265,10 @@ func TestVectorRetrieve_SQLShape(t *testing.T) {
WithArgs("weknora", "weknora_embeddings_3").
WillReturnRows(sqlmock.NewRows([]string{"c"}).AddRow(1))
mock.ExpectQuery(`SELECT id, content, .*inner_product_approximate.*HAVING score >= \? ORDER BY score DESC LIMIT \?`).
WithArgs(true, 0.5, 5).
// Doris does not support placeholders for LIMIT, so TopK is inlined as a
// literal and is not a bound argument.
mock.ExpectQuery(`SELECT id, content, .*inner_product_approximate.*HAVING score >= \? ORDER BY score DESC LIMIT \d+`).
WithArgs(true, 0.5).
WillReturnRows(
sqlmock.NewRows([]string{
"id", "content", "source_id", "source_type",
@@ -298,8 +300,8 @@ func TestVectorRetrieve_SQLShape_LegacyMode(t *testing.T) {
WithArgs("weknora", "weknora_embeddings_3").
WillReturnRows(sqlmock.NewRows([]string{"c"}).AddRow(1))
mock.ExpectQuery(`SELECT id, content, .*cosine_distance_approximate.*HAVING score >= \? ORDER BY score DESC LIMIT \?`).
WithArgs(true, 0.5, 5).
mock.ExpectQuery(`SELECT id, content, .*cosine_distance_approximate.*HAVING score >= \? ORDER BY score DESC LIMIT \d+`).
WithArgs(true, 0.5).
WillReturnRows(
sqlmock.NewRows([]string{
"id", "content", "source_id", "source_type",
@@ -345,8 +347,10 @@ func TestKeywordsRetrieve_SQLShape(t *testing.T) {
WillReturnRows(sqlmock.NewRows([]string{"TABLE_NAME"}).
AddRow("weknora_embeddings_768"))
// LIMIT is inlined (see VectorRetrieve), so only is_enabled and the
// MATCH_ANY query string are bound arguments.
mock.ExpectQuery(`MATCH_ANY \?`).
WithArgs(true, "你好", 3).
WithArgs(true, "你好").
WillReturnRows(
sqlmock.NewRows([]string{
"id", "content", "source_id", "source_type",
@@ -192,8 +192,11 @@ func TestOssEnsureBucket_CreateFails(t *testing.T) {
t.Fatalf("newOSSClient() error: %v", err)
}
// Should fail with invalid credentials
err = ossEnsureBucket(client, "test-bucket")
// Use a bucket that does not exist so IsBucketExist returns false and the
// create path is exercised; with invalid credentials PutBucket then fails.
// A common name like "test-bucket" already exists globally on OSS, which
// would short-circuit at IsBucketExist and make this assertion flaky.
err = ossEnsureBucket(client, "weknora-nonexistent-bucket-create-fails-12345")
if err == nil {
t.Error("ossEnsureBucket with invalid credentials should return an error")
}