package app import ( "fmt" . "code.hoteas.com/golang/hotime" . "code.hoteas.com/golang/hotime/common" ) var DmdbTest = CtrTest{ "tables": {Desc: "查询达梦所有表", Func: func(a *Api) { if a.DB().Type != "dm" && a.DB().Type != "dameng" { return } a.Verify(func(a *Api) error { result := a.Resp().GetBody().GetMap("result") if result == nil { return fmt.Errorf("result 为 nil") } tables := result.GetSlice("tables") if tables == nil { return fmt.Errorf("tables 字段缺失") } if len(tables) == 0 { return fmt.Errorf("达梦表列表为空,至少应有测试表") } return nil }).Get("USER_TABLES 查询", 0, Map{ "tables": Slice{Map{"name": "sample"}}, }) }}, "describe": {Desc: "查询达梦表结构", Func: func(a *Api) { if a.DB().Type != "dm" && a.DB().Type != "dameng" { return } // ======== 错误用例 ======== a.Get("不传table参数", 1, "请提供 table 参数") // ======== 正确请求 + 结构校验 + Verify ======== a.Query(Map{"table": "admin"}). Verify(func(a *Api) error { result := a.Resp().GetBody().GetMap("result") if result == nil { return fmt.Errorf("result 为 nil") } if result.GetString("table") != "admin" { return fmt.Errorf("table 期望 'admin', 实际 '%s'", result.GetString("table")) } columns := result.GetSlice("columns") if len(columns) == 0 { return fmt.Errorf("columns 为空,admin 表应有字段定义") } return nil }). Get("USER_TAB_COLUMNS 查询", 0, Map{ "table": "sample", "columns": Slice{Map{"name": "sample", "type": "sample"}}, "sample_data": Slice{}, }) }}, "rawsql": {Desc: "达梦原生 SQL 测试", Func: func(a *Api) { if a.DB().Type != "dm" && a.DB().Type != "dameng" { return } a.Verify(func(a *Api) error { result := a.Resp().GetBody().GetMap("result") if result == nil { return fmt.Errorf("result 为 nil") } if !result.GetBool("success") { return fmt.Errorf("达梦原生 SQL 测试未通过") } tests := result.GetSlice("tests") if len(tests) == 0 { return fmt.Errorf("tests 数组为空") } for i := 0; i < len(tests); i++ { item := tests.GetMap(i) if item != nil && !item.GetBool("result") { return fmt.Errorf("子项 '%s' 失败", item.GetString("name")) } } return nil }).Get("达梦原生SQL", 0, Map{ "name": "sample", "success": true, "tests": Slice{Map{"name": "sample", "result": true}}, }) }}, }