go-gin-example icon indicating copy to clipboard operation
go-gin-example copied to clipboard

关于测试方法

Open stevenlee87 opened this issue 4 years ago • 1 comments

首先说明下,如果没有获取token,提交POST请求的时候没有添加token参数,会提示{"code":400,"data":null,"msg":"请求参数错误"} 比如:curl -X POST 'http://127.0.0.1:8000/api/v1/articles?tag_id=1&title=test1&desc=test-desc&content=test-content&created_by=test-created&state=1&cover_image_url=http://www.baidu.cn'

1.首先获取token curl -X GET 'http://127.0.0.1:8000/auth?username=test&password=test123' {"code":200,"msg":"ok","data":{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IjA5OGY2YmNkNDYyMWQzNzNjYWRlNGU4MzI2MjdiNGY2IiwicGFzc3dvcmQiOiJjYzAzZTc0N2E2YWZiYmNiZjhiZTc2NjhhY2ZlYmVlNSIsImV4cCI6MTU3Mjk1NDUwMiwiaXNzIjoiZ2luLWJsb2cifQ.RvRDDP5DCscdsDFex31S6LyH6iAhWUIwTZU_nZEtJXc"}}

2.添加tag curl -X POST 'http://127.0.0.1:8000/api/v1/tags?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IjA5OGY2YmNkNDYyMWQzNzNjYWRlNGU4MzI2MjdiNGY2IiwicGFzc3dvcmQiOiJjYzAzZTc0N2E2YWZiYmNiZjhiZTc2NjhhY2ZlYmVlNSIsImV4cCI6MTU3Mjk1NDUwMiwiaXNzIjoiZ2luLWJsb2cifQ.RvRDDP5DCscdsDFex31S6LyH6iAhWUIwTZU_nZEtJXc&name=tim&state=1&created_by=tim' {"code":200,"msg":"ok","data":null} 数据库里blog_tag表会插入一行数据

3.使用添加的tag_id 添加article curl -X POST 'http://127.0.0.1:8000/api/v1/articles?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IjA5OGY2YmNkNDYyMWQzNzNjYWRlNGU4MzI2MjdiNGY2IiwicGFzc3dvcmQiOiJjYzAzZTc0N2E2YWZiYmNiZjhiZTc2NjhhY2ZlYmVlNSIsImV4cCI6MTU3Mjk1NDUwMiwiaXNzIjoiZ2luLWJsb2cifQ.RvRDDP5DCscdsDFex31S6LyH6iAhWUIwTZU_nZEtJXc&tag_id=3&title=golanglearning&desc=study&content=gogogo&created_by=lee&state=1&cover_image_url=http://www.baidu.cn' {"code":200,"msg":"ok","data":null}

4.获取article curl -X GET 'http://127.0.0.1:8000/api/v1/articles?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IjA5OGY2YmNkNDYyMWQzNzNjYWRlNGU4MzI2MjdiNGY2IiwicGFzc3dvcmQiOiJjYzAzZTc0N2E2YWZiYmNiZjhiZTc2NjhhY2ZlYmVlNSIsImV4cCI6MTU3Mjk1NDUwMiwiaXNzIjoiZ2luLWJsb2cifQ.RvRDDP5DCscdsDFex31S6LyH6iAhWUIwTZU_nZEtJXc'

{ code: 200, msg: "ok", data: { lists: [ { id: 1, created_on: 1572944291, modified_on: 1572944291, deleted_on: 0, tag_id: 1, tag: { id: 1, created_on: 1572944243, modified_on: 1572944243, deleted_on: 0, name: "li1", created_by: "test-created", modified_by: "", state: 1 }, title: "test1", desc: "test-desc", content: "test-content", cover_image_url: "http://www.baidu.cn", created_by: "", modified_by: "", state: 1 }, { id: 2, created_on: 1572945959, modified_on: 1572945959, deleted_on: 0, tag_id: 2, tag: { id: 2, created_on: 1572945705, modified_on: 1572945705, deleted_on: 0, name: "lee", created_by: "lee", modified_by: "", state: 1 }, title: "test1", desc: "test-desc", content: "test-content", cover_image_url: "http://www.baidu.cn", created_by: "", modified_by: "", state: 1 }, { id: 3, created_on: 1572954204, modified_on: 1572954204, deleted_on: 0, tag_id: 3, tag: { id: 3, created_on: 1572953649, modified_on: 1572953649, deleted_on: 0, name: "tim", created_by: "tim", modified_by: "", state: 1 }, title: "golanglearning", desc: "study", content: "gogogo", cover_image_url: "http://www.baidu.cn", created_by: "", modified_by: "", state: 1 } ], total: 3 } }

欢迎大家一起来讨论!

stevenlee87 avatar Nov 05 '19 11:11 stevenlee87

@stevenlee87 这是要讨论什么?

eddycjy avatar Mar 16 '20 05:03 eddycjy