mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-09 16:23:27 +08:00
🐛 fix(milvus): 兼容不支持数据库枚举的服务
- 数据库列表接口不可用时验证当前数据库的集合枚举能力 - 验证成功后回退到已配置数据库并继续加载集合 - 补充测试连接成功但侧栏展开失败的回归用例
This commit is contained in:
@@ -200,6 +200,10 @@ func (m *MilvusDB) GetDatabases() ([]string, error) {
|
||||
|
||||
var raw interface{}
|
||||
if err := m.doJSON(ctx, http.MethodPost, milvusDatabasesListPath, map[string]interface{}{}, &raw); err != nil {
|
||||
if _, fallbackErr := m.listCollections(ctx, m.database); fallbackErr == nil {
|
||||
logger.Warnf("Milvus 数据库列表接口不可用,回退到当前数据库 %s: %v", m.database, err)
|
||||
return []string{m.database}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
names := milvusNamesFromValue(raw, "dbNames", "databases", "names")
|
||||
|
||||
@@ -136,6 +136,44 @@ func TestMilvusGetDatabasesPostsJSONObject(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMilvusGetDatabasesFallsBackWhenDatabaseListIsUnsupported(t *testing.T) {
|
||||
collectionListCalls := 0
|
||||
server := newMockMilvusServer(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
switch {
|
||||
case isMilvusCollectionListRequest(r):
|
||||
collectionListCalls++
|
||||
if body := decodeMilvusRequest(t, r); body["dbName"] != defaultMilvusDatabase {
|
||||
t.Fatalf("list body = %#v", body)
|
||||
}
|
||||
writeMilvusJSON(w, []string{"products"})
|
||||
case r.Method == http.MethodPost && r.URL.Path == milvusDatabasesListPath:
|
||||
http.NotFound(w, r)
|
||||
default:
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
})
|
||||
|
||||
db := newTestMilvusDB(t, server.URL)
|
||||
databases, err := db.GetDatabases()
|
||||
if err != nil {
|
||||
t.Fatalf("GetDatabases should fall back to the configured database: %v", err)
|
||||
}
|
||||
if strings.Join(databases, ",") != defaultMilvusDatabase {
|
||||
t.Fatalf("databases = %v, want [%s]", databases, defaultMilvusDatabase)
|
||||
}
|
||||
|
||||
tables, err := db.GetTables(databases[0])
|
||||
if err != nil {
|
||||
t.Fatalf("GetTables failed after database fallback: %v", err)
|
||||
}
|
||||
if strings.Join(tables, ",") != "products" {
|
||||
t.Fatalf("tables = %v, want [products]", tables)
|
||||
}
|
||||
if collectionListCalls != 3 {
|
||||
t.Fatalf("collection list calls = %d, want 3", collectionListCalls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMilvusGetTablesUsesRESTV2CollectionList(t *testing.T) {
|
||||
server := newMockMilvusServer(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
if isMilvusCollectionListRequest(r) {
|
||||
|
||||
Reference in New Issue
Block a user