代码拉取完成,页面将自动刷新
package swag
import (
"testing"
"github.com/stretchr/testify/assert"
)
var doc = `{
"swagger": "2.0",
"info": {
"description": "This is a sample server Petstore server.",
"title": "Swagger Example API",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"name": "API Support",
"url": "http://www.swagger.io/support",
"email": "support@swagger.io"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "1.0"
},
"host": "petstore.swagger.io",
"basePath": "/v2",
"paths": {
"/testapi/get-string-by-int/{some_id}": {
"get": {
"description": "get string by ID",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Add a new pet to the store",
"parameters": [
{
"description": "Some ID",
"name": "some_id",
"in": "path",
"required": true,
"schema": {
"type": "int"
}
}
],
"responses": {
"200": {
"description": "ok",
"schema": {
"type": "string"
}
},
"400": {
"description": "We need ID!!",
"schema": {
"type": "object",
"$ref": "#/definitions/web.APIError"
}
},
"404": {
"description": "Can not find ID",
"schema": {
"type": "object",
"$ref": "#/definitions/web.APIError"
}
}
}
}
},
"/testapi/get-struct-array-by-string/{some_id}": {
"get": {
"description": "get struct array by ID",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"description": "Some ID",
"name": "some_id",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "Offset",
"name": "offset",
"in": "query",
"required": true,
"schema": {
"type": "int"
}
},
{
"description": "Offset",
"name": "limit",
"in": "query",
"required": true,
"schema": {
"type": "int"
}
}
],
"responses": {
"200": {
"description": "ok",
"schema": {
"type": "string"
}
},
"400": {
"description": "We need ID!!",
"schema": {
"type": "object",
"$ref": "#/definitions/web.APIError"
}
},
"404": {
"description": "Can not find ID",
"schema": {
"type": "object",
"$ref": "#/definitions/web.APIError"
}
}
}
}
}
},
"definitions": {
"web.APIError": {
"type": "object",
"properties": {
"ErrorCode": {
"type": "int"
},
"ErrorMessage": {
"type": "string"
}
}
}
}
}`
type s struct{}
func (s *s) ReadDoc() string {
return doc
}
func TestRegister(t *testing.T) {
setup()
Register(Name, &s{})
d, _ := ReadDoc()
assert.Equal(t, doc, d)
}
func TestRegisterByName(t *testing.T) {
setup()
Register("another_name", &s{})
d, _ := ReadDoc("another_name")
assert.Equal(t, doc, d)
}
func TestRegisterMultiple(t *testing.T) {
setup()
Register(Name, &s{})
Register("another_name", &s{})
d1, _ := ReadDoc(Name)
d2, _ := ReadDoc("another_name")
assert.Equal(t, doc, d1)
assert.Equal(t, doc, d2)
}
func TestReadDocBeforeRegistered(t *testing.T) {
setup()
_, err := ReadDoc()
assert.Error(t, err)
}
func TestReadDocWithInvalidName(t *testing.T) {
setup()
Register(Name, &s{})
_, err := ReadDoc("invalid")
assert.Error(t, err)
}
func TestNilRegister(t *testing.T) {
setup()
var swagger Swagger
assert.Panics(t, func() {
Register(Name, swagger)
})
}
func TestCalledTwicelRegister(t *testing.T) {
setup()
assert.Panics(t, func() {
Register(Name, &s{})
Register(Name, &s{})
})
}
func setup() {
swags = nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。