http_test.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. package http
  2. import (
  3. "context"
  4. "crypto/md5"
  5. "encoding/hex"
  6. "fmt"
  7. "net/http"
  8. "net/url"
  9. "strconv"
  10. "testing"
  11. "time"
  12. "go-common/app/interface/main/favorite/conf"
  13. "go-common/app/interface/main/favorite/service"
  14. xhttp "go-common/library/net/http/blademaster"
  15. )
  16. const (
  17. _mid = 88888894
  18. _vmid = 12345
  19. _aid = 5463438
  20. _aids = "5463438,5463439"
  21. _fid = 1852
  22. _delFid = 123
  23. _oldFid = 1791
  24. _newFid = 1792
  25. _fidsSort = "1107,1852,1792,1791"
  26. _name = "folder-name-test"
  27. _rename = "folder-rename-test"
  28. _public = 1
  29. _tpid = 2659 // TopicID
  30. _type = 1 // Article
  31. _v3Fid = 0
  32. _searchFid = 0
  33. _oid = 123
  34. _pn = 1
  35. _ps = 30
  36. // video folder
  37. _videoFolders = "http://127.0.0.1:6010/x/internal/v2/fav/folder"
  38. _addVideoFolder = "http://127.0.0.1:6010/x/internal/v2/fav/folder/add"
  39. _delVideoFolder = "http://127.0.0.1:6010/x/internal/v2/fav/folder/del"
  40. _renameVideoFolder = "http://127.0.0.1:6010/x/internal/v2/fav/folder/rename"
  41. _upStateVideoFolder = "http://127.0.0.1:6010/x/internal/v2/fav/folder/public"
  42. _sortVideoFolders = "http://127.0.0.1:6010/x/internal/v2/fav/folder/sort"
  43. // video
  44. _favVideo = "http://127.0.0.1:6010/x/internal/v2/fav/video"
  45. _favVideoNewest = "http://127.0.0.1:6010/x/internal/v2/fav/video/newest"
  46. _addFavVideo = "http://127.0.0.1:6010/x/internal/v2/fav/video/add"
  47. _delFavVideo = "http://127.0.0.1:6010/x/internal/v2/fav/video/del"
  48. _delFavVideos = "http://127.0.0.1:6010/x/internal/v2/fav/video/mdel"
  49. _moveFavVideos = "http://127.0.0.1:6010/x/internal/v2/fav/video/move"
  50. _copyFavVideos = "http://127.0.0.1:6010/x/internal/v2/fav/video/copy"
  51. _isFavoureds = "http://127.0.0.1:6010/x/internal/v2/fav/video/favoureds"
  52. _isFavoured = "http://127.0.0.1:6010/x/internal/v2/fav/video/favoured"
  53. _inDefaultFav = "http://127.0.0.1:6010/x/internal/v2/fav/video/default"
  54. // topic
  55. _favTopics = "http://127.0.0.1:6010/x/internal/v2/fav/topic"
  56. _addFavTopic = "http://127.0.0.1:6010/x/internal/v2/fav/topic/add"
  57. _delFavTopic = "http://127.0.0.1:6010/x/internal/v2/fav/topic/del"
  58. _isTopicFavoured = "http://127.0.0.1:6010/x/internal/v2/fav/topic/favoured"
  59. // fav v3
  60. _favorites = "http://127.0.0.1:6010/x/internal/v3/fav"
  61. _addFav = "http://127.0.0.1:6010/x/internal/v3/fav/add"
  62. _isFavored = "http://127.0.0.1:6010/x/internal/v3/fav/favored"
  63. _delFav = "http://127.0.0.1:6010/x/internal/v3/fav/del"
  64. )
  65. func TestHttp(t *testing.T) {
  66. if err := conf.Init(); err != nil {
  67. t.Fatalf("conf.Init() error(%v)", err)
  68. }
  69. svr := service.New(conf.Conf)
  70. client := xhttp.NewClient(conf.Conf.HTTPClient)
  71. Init(conf.Conf, svr)
  72. // video foler
  73. testVideoFolders(client, t, _mid, _vmid, _aid)
  74. testRenameVideoFolder(client, t, _mid, _fid, _rename)
  75. testAddVideoFolder(client, t, _mid, _public, _name)
  76. testSortVideoFolder(client, t, _mid, _fidsSort)
  77. testUpStateVideoFolder(client, t, _mid, _fid, _public)
  78. testDelVideoFolder(client, t, _mid, _delFid)
  79. // video
  80. testVideos(client, t, _mid, _vmid, _fid)
  81. testFavVideoNewest(client, t, _mid, _vmid, _searchFid, _pn, _ps)
  82. testAddFavVideo(client, t, _mid, _fid, _aid)
  83. testMoveFavVideos(client, t, _mid, _oldFid, _newFid, _aids)
  84. testCopyFavVideos(client, t, _mid, _oldFid, _newFid, _aids)
  85. testIsFavoured(client, t, _mid, _aid)
  86. testIsFavoureds(client, t, _mid, _aids)
  87. testInDefaultFav(client, t, _mid, _aid)
  88. testDelVideo(client, t, _mid, _fid, _aid)
  89. testDelVideos(client, t, _mid, _fid, _aids)
  90. // topic
  91. testFavTopics(client, t, _mid, _pn, _ps)
  92. testAddFavTopic(client, t, _mid, _tpid)
  93. testIsTopicFavoured(client, t, _mid, _tpid)
  94. testDelFavTopic(client, t, _mid, _tpid)
  95. // fav v3
  96. testFavorites(client, t, _type, _mid, _vmid, _v3Fid)
  97. testAddFav(client, t, _type, _mid, _v3Fid, _oid)
  98. testIsFavored(client, t, _type, _mid, _v3Fid, _oid)
  99. testDelFav(client, t, _type, _mid, _v3Fid, _oid)
  100. }
  101. func testVideoFolders(client *xhttp.Client, t *testing.T, mid, vmid, aid int64) {
  102. params := &url.Values{}
  103. params.Set("mid", strconv.FormatInt(mid, 10))
  104. params.Set("appkey", conf.Conf.App.Key)
  105. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  106. params.Set("sign", createSign(params.Encode()))
  107. // send
  108. req, err := http.NewRequest("GET", _videoFolders+"?"+params.Encode(), nil)
  109. t.Log(req.URL.String())
  110. if err != nil {
  111. t.Errorf("NewRequest() error(%v)", err)
  112. }
  113. res := map[string]interface{}{}
  114. if err = client.Do(context.TODO(), req, &res); err != nil {
  115. t.Errorf("client.Do() error(%v)", err)
  116. } else {
  117. result("VideoFolders", t, res)
  118. }
  119. }
  120. func testAddVideoFolder(client *xhttp.Client, t *testing.T, mid, public int64, name string) {
  121. params := &url.Values{}
  122. params.Set("mid", strconv.FormatInt(mid, 10))
  123. params.Set("public", strconv.FormatInt(public, 10))
  124. params.Set("name", name)
  125. params.Set("appkey", conf.Conf.App.Key)
  126. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  127. params.Set("sign", createSign(params.Encode()))
  128. // send
  129. req, err := http.NewRequest("POST", _addVideoFolder+"?"+params.Encode(), nil)
  130. t.Log(req.URL.String())
  131. if err != nil {
  132. t.Errorf("NewRequest() error(%v)", err)
  133. }
  134. res := map[string]interface{}{}
  135. if err = client.Do(context.TODO(), req, &res); err != nil {
  136. t.Errorf("client.Do() error(%v)", err)
  137. } else {
  138. result("DelVideoFolder", t, res)
  139. }
  140. }
  141. func testRenameVideoFolder(client *xhttp.Client, t *testing.T, mid, fid int64, name string) {
  142. params := &url.Values{}
  143. params.Set("mid", strconv.FormatInt(mid, 10))
  144. params.Set("fid", strconv.FormatInt(fid, 10))
  145. params.Set("name", name)
  146. params.Set("appkey", conf.Conf.App.Key)
  147. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  148. params.Set("sign", createSign(params.Encode()))
  149. // send
  150. req, err := http.NewRequest("POST", _renameVideoFolder+"?"+params.Encode(), nil)
  151. t.Log(req.URL.String())
  152. if err != nil {
  153. t.Errorf("NewRequest() error(%v)", err)
  154. }
  155. res := map[string]interface{}{}
  156. if err = client.Do(context.TODO(), req, &res); err != nil {
  157. t.Errorf("client.Do() error(%v)", err)
  158. } else {
  159. result("RenameVideoFolder", t, res)
  160. }
  161. }
  162. func testUpStateVideoFolder(client *xhttp.Client, t *testing.T, mid, fid, public int64) {
  163. params := &url.Values{}
  164. params.Set("mid", strconv.FormatInt(mid, 10))
  165. params.Set("fid", strconv.FormatInt(fid, 10))
  166. params.Set("public", strconv.FormatInt(public, 10))
  167. params.Set("appkey", conf.Conf.App.Key)
  168. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  169. params.Set("sign", createSign(params.Encode()))
  170. // send
  171. req, err := http.NewRequest("POST", _upStateVideoFolder+"?"+params.Encode(), nil)
  172. t.Log(req.URL.String())
  173. if err != nil {
  174. t.Errorf("NewRequest() error(%v)", err)
  175. }
  176. res := map[string]interface{}{}
  177. if err = client.Do(context.TODO(), req, &res); err != nil {
  178. t.Errorf("client.Do() error(%v)", err)
  179. } else {
  180. result("RenameVideoFolder", t, res)
  181. }
  182. }
  183. func testSortVideoFolder(client *xhttp.Client, t *testing.T, mid int64, fids string) {
  184. params := &url.Values{}
  185. params.Set("mid", strconv.FormatInt(mid, 10))
  186. params.Set("fids", fids)
  187. params.Set("appkey", conf.Conf.App.Key)
  188. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  189. params.Set("sign", createSign(params.Encode()))
  190. // send
  191. req, err := http.NewRequest("POST", _sortVideoFolders+"?"+params.Encode(), nil)
  192. t.Log(req.URL.String())
  193. if err != nil {
  194. t.Errorf("NewRequest() error(%v)", err)
  195. }
  196. res := map[string]interface{}{}
  197. if err = client.Do(context.TODO(), req, &res); err != nil {
  198. t.Errorf("client.Do() error(%v)", err)
  199. } else {
  200. result("RenameVideoFolder", t, res)
  201. }
  202. }
  203. func testDelVideoFolder(client *xhttp.Client, t *testing.T, mid, fid int64) {
  204. params := &url.Values{}
  205. params.Set("mid", strconv.FormatInt(mid, 10))
  206. params.Set("fid", strconv.FormatInt(fid, 10))
  207. params.Set("appkey", conf.Conf.App.Key)
  208. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  209. params.Set("sign", createSign(params.Encode()))
  210. // send
  211. req, err := http.NewRequest("POST", _delVideoFolder+"?"+params.Encode(), nil)
  212. t.Log(req.URL.String())
  213. if err != nil {
  214. t.Errorf("NewRequest() error(%v)", err)
  215. }
  216. res := map[string]interface{}{}
  217. if err = client.Do(context.TODO(), req, &res); err != nil {
  218. t.Errorf("client.Do() error(%v)", err)
  219. } else {
  220. result("DelVideoFolder", t, res)
  221. }
  222. }
  223. func testVideos(client *xhttp.Client, t *testing.T, mid, vmid, fid int64) {
  224. params := &url.Values{}
  225. params.Set("mid", strconv.FormatInt(mid, 10))
  226. params.Set("fid", strconv.FormatInt(fid, 10))
  227. params.Set("appkey", conf.Conf.App.Key)
  228. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  229. params.Set("sign", createSign(params.Encode()))
  230. // send
  231. req, err := http.NewRequest("GET", _favVideo+"?"+params.Encode(), nil)
  232. t.Log(req.URL.String())
  233. if err != nil {
  234. t.Errorf("NewRequest() error(%v)", err)
  235. }
  236. res := map[string]interface{}{}
  237. if err = client.Do(context.TODO(), req, &res); err != nil {
  238. t.Errorf("client.Do() error(%v)", err)
  239. } else {
  240. result("Videos", t, res)
  241. }
  242. }
  243. func testFavVideoNewest(client *xhttp.Client, t *testing.T, mid, vmid, fid, pn, ps int64) {
  244. params := &url.Values{}
  245. params.Set("mid", strconv.FormatInt(mid, 10))
  246. params.Set("fid", strconv.FormatInt(fid, 10))
  247. params.Set("pn", strconv.FormatInt(pn, 10))
  248. params.Set("ps", strconv.FormatInt(ps, 10))
  249. params.Set("appkey", conf.Conf.App.Key)
  250. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  251. params.Set("sign", createSign(params.Encode()))
  252. // send
  253. req, err := http.NewRequest("GET", _favVideoNewest+"?"+params.Encode(), nil)
  254. t.Log(req.URL.String())
  255. if err != nil {
  256. t.Errorf("NewRequest() error(%v)", err)
  257. }
  258. res := map[string]interface{}{}
  259. if err = client.Do(context.TODO(), req, &res); err != nil {
  260. t.Errorf("client.Do() error(%v)", err)
  261. } else {
  262. result("FavVideoNewest", t, res)
  263. }
  264. }
  265. func testAddFavVideo(client *xhttp.Client, t *testing.T, mid, fid, aid int64) {
  266. params := &url.Values{}
  267. params.Set("mid", strconv.FormatInt(mid, 10))
  268. params.Set("fid", strconv.FormatInt(fid, 10))
  269. params.Set("aid", strconv.FormatInt(aid, 10))
  270. params.Set("appkey", conf.Conf.App.Key)
  271. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  272. params.Set("sign", createSign(params.Encode()))
  273. // send
  274. req, err := http.NewRequest("POST", _addFavVideo+"?"+params.Encode(), nil)
  275. t.Log(req.URL.String())
  276. if err != nil {
  277. t.Errorf("NewRequest() error(%v)", err)
  278. }
  279. res := map[string]interface{}{}
  280. if err = client.Do(context.TODO(), req, &res); err != nil {
  281. t.Errorf("client.Do() error(%v)", err)
  282. } else {
  283. result("AddFavVideo", t, res)
  284. }
  285. }
  286. func testMoveFavVideos(client *xhttp.Client, t *testing.T, mid, oldFid, newFid int64, aids string) {
  287. params := &url.Values{}
  288. params.Set("mid", strconv.FormatInt(mid, 10))
  289. params.Set("old_fid", strconv.FormatInt(oldFid, 10))
  290. params.Set("new_fid", strconv.FormatInt(newFid, 10))
  291. params.Set("aids", aids)
  292. params.Set("appkey", conf.Conf.App.Key)
  293. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  294. params.Set("sign", createSign(params.Encode()))
  295. // send
  296. req, err := http.NewRequest("POST", _moveFavVideos+"?"+params.Encode(), nil)
  297. t.Log(req.URL.String())
  298. if err != nil {
  299. t.Errorf("NewRequest() error(%v)", err)
  300. }
  301. res := map[string]interface{}{}
  302. if err = client.Do(context.TODO(), req, &res); err != nil {
  303. t.Errorf("client.Do() error(%v)", err)
  304. } else {
  305. result("MoveFavVideos", t, res)
  306. }
  307. }
  308. func testCopyFavVideos(client *xhttp.Client, t *testing.T, mid, oldFid, newFid int64, aids string) {
  309. params := &url.Values{}
  310. params.Set("mid", strconv.FormatInt(mid, 10))
  311. params.Set("old_fid", strconv.FormatInt(oldFid, 10))
  312. params.Set("new_fid", strconv.FormatInt(newFid, 10))
  313. params.Set("aids", aids)
  314. params.Set("appkey", conf.Conf.App.Key)
  315. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  316. params.Set("sign", createSign(params.Encode()))
  317. // send
  318. req, err := http.NewRequest("POST", _copyFavVideos+"?"+params.Encode(), nil)
  319. t.Log(req.URL.String())
  320. if err != nil {
  321. t.Errorf("NewRequest() error(%v)", err)
  322. }
  323. res := map[string]interface{}{}
  324. if err = client.Do(context.TODO(), req, &res); err != nil {
  325. t.Errorf("client.Do() error(%v)", err)
  326. } else {
  327. result("CopyFavVideos", t, res)
  328. }
  329. }
  330. func testIsFavoured(client *xhttp.Client, t *testing.T, mid, aid int64) {
  331. params := &url.Values{}
  332. params.Set("mid", strconv.FormatInt(mid, 10))
  333. params.Set("aid", strconv.FormatInt(aid, 10))
  334. params.Set("appkey", conf.Conf.App.Key)
  335. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  336. params.Set("sign", createSign(params.Encode()))
  337. // send
  338. req, err := http.NewRequest("GET", _isFavoured+"?"+params.Encode(), nil)
  339. t.Log(req.URL.String())
  340. if err != nil {
  341. t.Errorf("NewRequest() error(%v)", err)
  342. }
  343. res := map[string]interface{}{}
  344. if err = client.Do(context.TODO(), req, &res); err != nil {
  345. t.Errorf("client.Do() error(%v)", err)
  346. } else {
  347. result("IsFavoured", t, res)
  348. }
  349. }
  350. func testIsFavoureds(client *xhttp.Client, t *testing.T, mid int64, aids string) {
  351. params := &url.Values{}
  352. params.Set("mid", strconv.FormatInt(mid, 10))
  353. params.Set("aids", aids)
  354. params.Set("appkey", conf.Conf.App.Key)
  355. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  356. params.Set("sign", createSign(params.Encode()))
  357. // send
  358. req, err := http.NewRequest("GET", _isFavoureds+"?"+params.Encode(), nil)
  359. t.Log(req.URL.String())
  360. if err != nil {
  361. t.Errorf("NewRequest() error(%v)", err)
  362. }
  363. res := map[string]interface{}{}
  364. if err = client.Do(context.TODO(), req, &res); err != nil {
  365. t.Errorf("client.Do() error(%v)", err)
  366. } else {
  367. result("IsFavoureds", t, res)
  368. }
  369. }
  370. func testInDefaultFav(client *xhttp.Client, t *testing.T, mid, aid int64) {
  371. params := &url.Values{}
  372. params.Set("mid", strconv.FormatInt(mid, 10))
  373. params.Set("aid", strconv.FormatInt(aid, 10))
  374. params.Set("appkey", conf.Conf.App.Key)
  375. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  376. params.Set("sign", createSign(params.Encode()))
  377. // send
  378. req, err := http.NewRequest("GET", _inDefaultFav+"?"+params.Encode(), nil)
  379. t.Log(req.URL.String())
  380. if err != nil {
  381. t.Errorf("NewRequest() error(%v)", err)
  382. }
  383. res := map[string]interface{}{}
  384. if err = client.Do(context.TODO(), req, &res); err != nil {
  385. t.Errorf("client.Do() error(%v)", err)
  386. } else {
  387. result("IsFavoureds", t, res)
  388. }
  389. }
  390. func testDelVideo(client *xhttp.Client, t *testing.T, mid, fid, aid int64) {
  391. params := &url.Values{}
  392. params.Set("mid", strconv.FormatInt(mid, 10))
  393. params.Set("aid", strconv.FormatInt(aid, 10))
  394. params.Set("appkey", conf.Conf.App.Key)
  395. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  396. params.Set("sign", createSign(params.Encode()))
  397. // send
  398. req, err := http.NewRequest("POST", _delFavVideo+"?"+params.Encode(), nil)
  399. t.Log(req.URL.String())
  400. if err != nil {
  401. t.Errorf("NewRequest() error(%v)", err)
  402. }
  403. res := map[string]interface{}{}
  404. if err = client.Do(context.TODO(), req, &res); err != nil {
  405. t.Errorf("client.Do() error(%v)", err)
  406. } else {
  407. result("DelVideo", t, res)
  408. }
  409. }
  410. func testDelVideos(client *xhttp.Client, t *testing.T, mid, fid int64, aids string) {
  411. params := &url.Values{}
  412. params.Set("mid", strconv.FormatInt(mid, 10))
  413. params.Set("fid", strconv.FormatInt(fid, 10))
  414. params.Set("aids", aids)
  415. params.Set("appkey", conf.Conf.App.Key)
  416. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  417. params.Set("sign", createSign(params.Encode()))
  418. // send
  419. req, err := http.NewRequest("POST", _delFavVideos+"?"+params.Encode(), nil)
  420. t.Log(req.URL.String())
  421. if err != nil {
  422. t.Errorf("NewRequest() error(%v)", err)
  423. }
  424. res := map[string]interface{}{}
  425. if err = client.Do(context.TODO(), req, &res); err != nil {
  426. t.Errorf("client.Do() error(%v)", err)
  427. } else {
  428. result("DelVideos", t, res)
  429. }
  430. }
  431. func testFavTopics(client *xhttp.Client, t *testing.T, mid, pn, ps int64) {
  432. params := &url.Values{}
  433. params.Set("mid", strconv.FormatInt(mid, 10))
  434. params.Set("pn", strconv.FormatInt(pn, 10))
  435. params.Set("ps", strconv.FormatInt(ps, 10))
  436. params.Set("appkey", conf.Conf.App.Key)
  437. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  438. params.Set("sign", createSign(params.Encode()))
  439. // send
  440. req, err := http.NewRequest("GET", _favTopics+"?"+params.Encode(), nil)
  441. t.Log(req.URL.String())
  442. if err != nil {
  443. t.Errorf("NewRequest() error(%v)", err)
  444. }
  445. res := map[string]interface{}{}
  446. if err = client.Do(context.TODO(), req, &res); err != nil {
  447. t.Errorf("client.Do() error(%v)", err)
  448. } else {
  449. result("FavTopics", t, res)
  450. }
  451. }
  452. func testAddFavTopic(client *xhttp.Client, t *testing.T, mid, tpid int64) {
  453. params := &url.Values{}
  454. params.Set("mid", strconv.FormatInt(mid, 10))
  455. params.Set("tpid", strconv.FormatInt(tpid, 10))
  456. params.Set("appkey", conf.Conf.App.Key)
  457. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  458. params.Set("sign", createSign(params.Encode()))
  459. // send
  460. req, err := http.NewRequest("POST", _addFavTopic+"?"+params.Encode(), nil)
  461. t.Log(req.URL.String())
  462. if err != nil {
  463. t.Errorf("NewRequest() error(%v)", err)
  464. }
  465. res := map[string]interface{}{}
  466. if err = client.Do(context.TODO(), req, &res); err != nil {
  467. t.Errorf("client.Do() error(%v)", err)
  468. } else {
  469. result("AddFavTopic", t, res)
  470. }
  471. }
  472. func testIsTopicFavoured(client *xhttp.Client, t *testing.T, mid, tpid int64) {
  473. params := &url.Values{}
  474. params.Set("mid", strconv.FormatInt(mid, 10))
  475. params.Set("tpid", strconv.FormatInt(tpid, 10))
  476. params.Set("appkey", conf.Conf.App.Key)
  477. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  478. params.Set("sign", createSign(params.Encode()))
  479. // send
  480. req, err := http.NewRequest("GET", _isTopicFavoured+"?"+params.Encode(), nil)
  481. t.Log(req.URL.String())
  482. if err != nil {
  483. t.Errorf("NewRequest() error(%v)", err)
  484. }
  485. res := map[string]interface{}{}
  486. if err = client.Do(context.TODO(), req, &res); err != nil {
  487. t.Errorf("client.Do() error(%v)", err)
  488. } else {
  489. result("IsTopicFavoured", t, res)
  490. }
  491. }
  492. func testDelFavTopic(client *xhttp.Client, t *testing.T, mid, tpid int64) {
  493. params := &url.Values{}
  494. params.Set("mid", strconv.FormatInt(mid, 10))
  495. params.Set("tpid", strconv.FormatInt(tpid, 10))
  496. params.Set("appkey", conf.Conf.App.Key)
  497. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  498. params.Set("sign", createSign(params.Encode()))
  499. // send
  500. req, err := http.NewRequest("POST", _delFavTopic+"?"+params.Encode(), nil)
  501. t.Log(req.URL.String())
  502. if err != nil {
  503. t.Errorf("NewRequest() error(%v)", err)
  504. }
  505. res := map[string]interface{}{}
  506. if err = client.Do(context.TODO(), req, &res); err != nil {
  507. t.Errorf("client.Do() error(%v)", err)
  508. } else {
  509. result("DelFavTopic", t, res)
  510. }
  511. }
  512. func testFavorites(client *xhttp.Client, t *testing.T, tp, mid, vmid, fid int64) {
  513. params := &url.Values{}
  514. params.Set("type", strconv.FormatInt(tp, 10))
  515. params.Set("mid", strconv.FormatInt(mid, 10))
  516. params.Set("fid", strconv.FormatInt(fid, 10))
  517. params.Set("appkey", conf.Conf.App.Key)
  518. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  519. params.Set("sign", createSign(params.Encode()))
  520. // send
  521. req, err := http.NewRequest("GET", _favorites+"?"+params.Encode(), nil)
  522. t.Log(req.URL.String())
  523. if err != nil {
  524. t.Errorf("NewRequest() error(%v)", err)
  525. }
  526. res := map[string]interface{}{}
  527. if err = client.Do(context.TODO(), req, &res); err != nil {
  528. t.Errorf("client.Do() error(%v)", err)
  529. } else {
  530. result("Favorites", t, res)
  531. }
  532. }
  533. func testAddFav(client *xhttp.Client, t *testing.T, tp, mid, fid, oid int64) {
  534. params := &url.Values{}
  535. params.Set("type", strconv.FormatInt(tp, 10))
  536. params.Set("mid", strconv.FormatInt(mid, 10))
  537. params.Set("fid", strconv.FormatInt(fid, 10))
  538. params.Set("oid", strconv.FormatInt(oid, 10))
  539. params.Set("appkey", conf.Conf.App.Key)
  540. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  541. params.Set("sign", createSign(params.Encode()))
  542. // send
  543. req, err := http.NewRequest("POST", _addFav+"?"+params.Encode(), nil)
  544. t.Log(req.URL.String())
  545. if err != nil {
  546. t.Errorf("NewRequest() error(%v)", err)
  547. }
  548. res := map[string]interface{}{}
  549. if err = client.Do(context.TODO(), req, &res); err != nil {
  550. t.Errorf("client.Do() error(%v)", err)
  551. } else {
  552. result("AddFav", t, res)
  553. }
  554. }
  555. func testIsFavored(client *xhttp.Client, t *testing.T, tp, mid, fid, oid int64) {
  556. params := &url.Values{}
  557. params.Set("type", strconv.FormatInt(tp, 10))
  558. params.Set("mid", strconv.FormatInt(mid, 10))
  559. params.Set("fid", strconv.FormatInt(fid, 10))
  560. params.Set("oid", strconv.FormatInt(oid, 10))
  561. params.Set("appkey", conf.Conf.App.Key)
  562. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  563. params.Set("sign", createSign(params.Encode()))
  564. // send
  565. req, err := http.NewRequest("GET", _isFavored+"?"+params.Encode(), nil)
  566. t.Log(req.URL.String())
  567. if err != nil {
  568. t.Errorf("NewRequest() error(%v)", err)
  569. }
  570. res := map[string]interface{}{}
  571. if err = client.Do(context.TODO(), req, &res); err != nil {
  572. t.Errorf("client.Do() error(%v)", err)
  573. } else {
  574. result("IsFavored", t, res)
  575. }
  576. }
  577. func testDelFav(client *xhttp.Client, t *testing.T, tp, mid, fid, oid int64) {
  578. params := &url.Values{}
  579. params.Set("type", strconv.FormatInt(tp, 10))
  580. params.Set("mid", strconv.FormatInt(mid, 10))
  581. params.Set("fid", strconv.FormatInt(fid, 10))
  582. params.Set("oid", strconv.FormatInt(oid, 10))
  583. params.Set("appkey", conf.Conf.App.Key)
  584. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  585. params.Set("sign", createSign(params.Encode()))
  586. // send
  587. req, err := http.NewRequest("POST", _delFav+"?"+params.Encode(), nil)
  588. t.Log(req.URL.String())
  589. if err != nil {
  590. t.Errorf("NewRequest() error(%v)", err)
  591. }
  592. res := map[string]interface{}{}
  593. if err = client.Do(context.TODO(), req, &res); err != nil {
  594. t.Errorf("client.Do() error(%v)", err)
  595. } else {
  596. result("DelFav", t, res)
  597. }
  598. }
  599. func createSign(params string) string {
  600. mh := md5.Sum([]byte(params + conf.Conf.App.Secret))
  601. return hex.EncodeToString(mh[:])
  602. }
  603. func result(name string, t *testing.T, res map[string]interface{}) {
  604. t.Log("[==========" + name + " Testing Result==========]")
  605. if rs, ok := res["code"]; ok {
  606. t.Log(fmt.Sprintf("code:%v, message:%s, data:%v", rs, res["message"], res["data"]))
  607. }
  608. t.Log("[↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑]\r\n")
  609. }