package app import ( "fmt" . "code.hoteas.com/golang/hotime" . "code.hoteas.com/golang/hotime/common" ) var CacheTest = CtrTest{ "all": {Desc: "缓存全部测试", Func: func(a *Api) { 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("缓存测试未全部通过") } if result.GetString("cache_mode") == "" { return fmt.Errorf("cache_mode 字段缺失") } 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("缓存全部测试", 0, Map{ "name": "sample", "cache_mode": "sample", "success": true, "cleanup": "sample", "tests": Slice{Map{ "name": "sample", "result": true, }}, }) }}, // 兼容模式下的老表回退/写新删老操作在测试事务隔离下已知异常(cache API // 使用独立连接,不在 testTx 事务内),因此只校验结构完整性 "compat": {Desc: "缓存兼容模式测试", Func: func(a *Api) { a.Verify(func(a *Api) error { result := a.Resp().GetBody().GetMap("result") if result == nil { return fmt.Errorf("result 为 nil") } if result.GetString("test_name") == "" { return fmt.Errorf("test_name 字段缺失") } if result.GetString("timestamp") == "" { return fmt.Errorf("timestamp 字段缺失") } tests := result.GetSlice("tests") if len(tests) == 0 { return fmt.Errorf("tests 数组为空") } return nil }).Get("兼容模式测试", 0, Map{ "test_name": "sample", "timestamp": "sample", "success": true, "tests": Slice{Map{ "name": "sample", "result": true, }}, }) }}, "batch": {Desc: "批量缓存测试", Func: func(a *Api) { a.Verify(func(a *Api) error { result := a.Resp().GetBody().GetMap("result") if result == nil { return fmt.Errorf("result 为 nil") } msg := result.GetString("message") if msg == "" { return fmt.Errorf("message 字段为空") } return nil }).Get("批量缓存测试", 0, Map{ "message": "sample", }) }}, }