Fix the dependency issue (#231)
This commit is contained in:
26
vendor/github.com/go-openapi/swag/.editorconfig
generated
vendored
26
vendor/github.com/go-openapi/swag/.editorconfig
generated
vendored
@@ -1,26 +0,0 @@
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# Unix-style newlines with a newline ending every file
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# Set default charset
|
||||
[*.{js,py,go,scala,rb,java,html,css,less,sass,md}]
|
||||
charset = utf-8
|
||||
|
||||
# Tab indentation (no size specified)
|
||||
[*.go]
|
||||
indent_style = tab
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
# Matches the exact files either package.json or .travis.yml
|
||||
[{package.json,.travis.yml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
117
vendor/github.com/go-openapi/swag/.github/CONTRIBUTING.md
generated
vendored
117
vendor/github.com/go-openapi/swag/.github/CONTRIBUTING.md
generated
vendored
@@ -1,117 +0,0 @@
|
||||
## Contribution Guidelines
|
||||
|
||||
### Pull requests are always welcome
|
||||
|
||||
We are always thrilled to receive pull requests, and do our best to
|
||||
process them as fast as possible. Not sure if that typo is worth a pull
|
||||
request? Do it! We will appreciate it.
|
||||
|
||||
If your pull request is not accepted on the first try, don't be
|
||||
discouraged! If there's a problem with the implementation, hopefully you
|
||||
received feedback on what to improve.
|
||||
|
||||
We're trying very hard to keep go-swagger lean and focused. We don't want it
|
||||
to do everything for everybody. This means that we might decide against
|
||||
incorporating a new feature. However, there might be a way to implement
|
||||
that feature *on top of* go-swagger.
|
||||
|
||||
|
||||
### Conventions
|
||||
|
||||
Fork the repo and make changes on your fork in a feature branch:
|
||||
|
||||
- If it's a bugfix branch, name it XXX-something where XXX is the number of the
|
||||
issue
|
||||
- If it's a feature branch, create an enhancement issue to announce your
|
||||
intentions, and name it XXX-something where XXX is the number of the issue.
|
||||
|
||||
Submit unit tests for your changes. Go has a great test framework built in; use
|
||||
it! Take a look at existing tests for inspiration. Run the full test suite on
|
||||
your branch before submitting a pull request.
|
||||
|
||||
Update the documentation when creating or modifying features. Test
|
||||
your documentation changes for clarity, concision, and correctness, as
|
||||
well as a clean documentation build. See ``docs/README.md`` for more
|
||||
information on building the docs and how docs get released.
|
||||
|
||||
Write clean code. Universally formatted code promotes ease of writing, reading,
|
||||
and maintenance. Always run `gofmt -s -w file.go` on each changed file before
|
||||
committing your changes. Most editors have plugins that do this automatically.
|
||||
|
||||
Pull requests descriptions should be as clear as possible and include a
|
||||
reference to all the issues that they address.
|
||||
|
||||
Pull requests must not contain commits from other users or branches.
|
||||
|
||||
Commit messages must start with a capitalized and short summary (max. 50
|
||||
chars) written in the imperative, followed by an optional, more detailed
|
||||
explanatory text which is separated from the summary by an empty line.
|
||||
|
||||
Code review comments may be added to your pull request. Discuss, then make the
|
||||
suggested modifications and push additional commits to your feature branch. Be
|
||||
sure to post a comment after pushing. The new commits will show up in the pull
|
||||
request automatically, but the reviewers will not be notified unless you
|
||||
comment.
|
||||
|
||||
Before the pull request is merged, make sure that you squash your commits into
|
||||
logical units of work using `git rebase -i` and `git push -f`. After every
|
||||
commit the test suite should be passing. Include documentation changes in the
|
||||
same commit so that a revert would remove all traces of the feature or fix.
|
||||
|
||||
Commits that fix or close an issue should include a reference like `Closes #XXX`
|
||||
or `Fixes #XXX`, which will automatically close the issue when merged.
|
||||
|
||||
### Sign your work
|
||||
|
||||
The sign-off is a simple line at the end of the explanation for the
|
||||
patch, which certifies that you wrote it or otherwise have the right to
|
||||
pass it on as an open-source patch. The rules are pretty simple: if you
|
||||
can certify the below (from
|
||||
[developercertificate.org](http://developercertificate.org/)):
|
||||
|
||||
```
|
||||
Developer Certificate of Origin
|
||||
Version 1.1
|
||||
|
||||
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
|
||||
660 York Street, Suite 102,
|
||||
San Francisco, CA 94110 USA
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this
|
||||
license document, but changing it is not allowed.
|
||||
|
||||
|
||||
Developer's Certificate of Origin 1.1
|
||||
|
||||
By making a contribution to this project, I certify that:
|
||||
|
||||
(a) The contribution was created in whole or in part by me and I
|
||||
have the right to submit it under the open source license
|
||||
indicated in the file; or
|
||||
|
||||
(b) The contribution is based upon previous work that, to the best
|
||||
of my knowledge, is covered under an appropriate open source
|
||||
license and I have the right under that license to submit that
|
||||
work with modifications, whether created in whole or in part
|
||||
by me, under the same open source license (unless I am
|
||||
permitted to submit under a different license), as indicated
|
||||
in the file; or
|
||||
|
||||
(c) The contribution was provided directly to me by some other
|
||||
person who certified (a), (b) or (c) and I have not modified
|
||||
it.
|
||||
|
||||
(d) I understand and agree that this project and the contribution
|
||||
are public and that a record of the contribution (including all
|
||||
personal information I submit with it, including my sign-off) is
|
||||
maintained indefinitely and may be redistributed consistent with
|
||||
this project or the open source license(s) involved.
|
||||
```
|
||||
|
||||
then you just add a line to every git commit message:
|
||||
|
||||
Signed-off-by: Joe Smith <joe@gmail.com>
|
||||
|
||||
using your real name (sorry, no pseudonyms or anonymous contributions.)
|
||||
|
||||
You can add the sign off when creating the git commit via `git commit -s`.
|
||||
3
vendor/github.com/go-openapi/swag/.gitignore
generated
vendored
3
vendor/github.com/go-openapi/swag/.gitignore
generated
vendored
@@ -1,3 +0,0 @@
|
||||
secrets.yml
|
||||
vendor
|
||||
Godeps
|
||||
14
vendor/github.com/go-openapi/swag/.travis.yml
generated
vendored
14
vendor/github.com/go-openapi/swag/.travis.yml
generated
vendored
@@ -1,14 +0,0 @@
|
||||
language: go
|
||||
go:
|
||||
- 1.8
|
||||
install:
|
||||
- go get -u github.com/stretchr/testify
|
||||
- go get -u github.com/mailru/easyjson
|
||||
- go get -u gopkg.in/yaml.v2
|
||||
script:
|
||||
- go test -v -race -cover -coverprofile=coverage.txt -covermode=atomic ./...
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
notifications:
|
||||
slack:
|
||||
secure: QUWvCkBBK09GF7YtEvHHVt70JOkdlNBG0nIKu/5qc4/nW5HP8I2w0SEf/XR2je0eED1Qe3L/AfMCWwrEj+IUZc3l4v+ju8X8R3Lomhme0Eb0jd1MTMCuPcBT47YCj0M7RON7vXtbFfm1hFJ/jLe5+9FXz0hpXsR24PJc5ZIi/ogNwkaPqG4BmndzecpSh0vc2FJPZUD9LT0I09REY/vXR0oQAalLkW0asGD5taHZTUZq/kBpsNxaAFrLM23i4mUcf33M5fjLpvx5LRICrX/57XpBrDh2TooBU6Qj3CgoY0uPRYUmSNxbVx1czNzl2JtEpb5yjoxfVPQeg0BvQM00G8LJINISR+ohrjhkZmAqchDupAX+yFrxTtORa78CtnIL6z/aTNlgwwVD8kvL/1pFA/JWYmKDmz93mV/+6wubGzNSQCstzjkFA4/iZEKewKUoRIAi/fxyscP6L/rCpmY/4llZZvrnyTqVbt6URWpopUpH4rwYqreXAtJxJsfBJIeSmUIiDIOMGkCTvyTEW3fWGmGoqWtSHLoaWDyAIGb7azb+KvfpWtEcoPFWfSWU+LGee0A/YsUhBl7ADB9A0CJEuR8q4BPpKpfLwPKSiKSAXL7zDkyjExyhtgqbSl2jS+rKIHOZNL8JkCcTP2MKMVd563C5rC5FMKqu3S9m2b6380E=
|
||||
74
vendor/github.com/go-openapi/swag/CODE_OF_CONDUCT.md
generated
vendored
74
vendor/github.com/go-openapi/swag/CODE_OF_CONDUCT.md
generated
vendored
@@ -1,74 +0,0 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
||||
nationality, personal appearance, race, religion, or sexual identity and
|
||||
orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at ivan+abuse@flanders.co.nz. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
||||
12
vendor/github.com/go-openapi/swag/README.md
generated
vendored
12
vendor/github.com/go-openapi/swag/README.md
generated
vendored
@@ -1,12 +0,0 @@
|
||||
# Swag [](https://travis-ci.org/go-openapi/swag) [](https://codecov.io/gh/go-openapi/swag) [](https://slackin.goswagger.io)
|
||||
|
||||
[](https://raw.githubusercontent.com/go-openapi/swag/master/LICENSE) [](http://godoc.org/github.com/go-openapi/swag)
|
||||
|
||||
Contains a bunch of helper functions:
|
||||
|
||||
* convert between value and pointers for builtins
|
||||
* convert from string to builtin
|
||||
* fast json concatenation
|
||||
* search in path
|
||||
* load from file or http
|
||||
* name manglin
|
||||
215
vendor/github.com/go-openapi/swag/convert_test.go
generated
vendored
215
vendor/github.com/go-openapi/swag/convert_test.go
generated
vendored
@@ -1,215 +0,0 @@
|
||||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package swag
|
||||
|
||||
import (
|
||||
"math"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// These are really dumb tests
|
||||
|
||||
func TestConvertBool(t *testing.T) {
|
||||
for k := range evaluatesAsTrue {
|
||||
r, err := ConvertBool(k)
|
||||
if assert.NoError(t, err) {
|
||||
assert.True(t, r)
|
||||
}
|
||||
}
|
||||
for _, k := range []string{"a", "", "0", "false", "unchecked"} {
|
||||
r, err := ConvertBool(k)
|
||||
if assert.NoError(t, err) {
|
||||
assert.False(t, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertFloat32(t *testing.T) {
|
||||
validFloats := []float32{1.0, -1, math.MaxFloat32, math.SmallestNonzeroFloat32, 0, 5.494430303}
|
||||
invalidFloats := []string{"a", strconv.FormatFloat(math.MaxFloat64, 'f', -1, 64), "true"}
|
||||
|
||||
for _, f := range validFloats {
|
||||
c, err := ConvertFloat32(FormatFloat32(f))
|
||||
if assert.NoError(t, err) {
|
||||
assert.EqualValues(t, f, c)
|
||||
}
|
||||
}
|
||||
for _, f := range invalidFloats {
|
||||
_, err := ConvertFloat32(f)
|
||||
assert.Error(t, err, "expected '"+f+"' to generate an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertFloat64(t *testing.T) {
|
||||
validFloats := []float64{1.0, -1, float64(math.MaxFloat32), float64(math.SmallestNonzeroFloat32), math.MaxFloat64, math.SmallestNonzeroFloat64, 0, 5.494430303}
|
||||
invalidFloats := []string{"a", "true"}
|
||||
|
||||
for _, f := range validFloats {
|
||||
c, err := ConvertFloat64(FormatFloat64(f))
|
||||
if assert.NoError(t, err) {
|
||||
assert.EqualValues(t, f, c)
|
||||
}
|
||||
}
|
||||
for _, f := range invalidFloats {
|
||||
_, err := ConvertFloat64(f)
|
||||
assert.Error(t, err, "expected '"+f+"' to generate an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertInt8(t *testing.T) {
|
||||
validInts := []int8{0, 1, -1, math.MaxInt8, math.MinInt8}
|
||||
invalidInts := []string{"1.233", "a", "false", strconv.Itoa(int(math.MaxInt64))}
|
||||
|
||||
for _, f := range validInts {
|
||||
c, err := ConvertInt8(FormatInt8(f))
|
||||
if assert.NoError(t, err) {
|
||||
assert.EqualValues(t, f, c)
|
||||
}
|
||||
}
|
||||
for _, f := range invalidInts {
|
||||
_, err := ConvertInt8(f)
|
||||
assert.Error(t, err, "expected '"+f+"' to generate an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertInt16(t *testing.T) {
|
||||
validInts := []int16{0, 1, -1, math.MaxInt8, math.MinInt8, math.MaxInt16, math.MinInt16}
|
||||
invalidInts := []string{"1.233", "a", "false", strconv.Itoa(int(math.MaxInt64))}
|
||||
|
||||
for _, f := range validInts {
|
||||
c, err := ConvertInt16(FormatInt16(f))
|
||||
if assert.NoError(t, err) {
|
||||
assert.EqualValues(t, f, c)
|
||||
}
|
||||
}
|
||||
for _, f := range invalidInts {
|
||||
_, err := ConvertInt16(f)
|
||||
assert.Error(t, err, "expected '"+f+"' to generate an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertInt32(t *testing.T) {
|
||||
validInts := []int32{0, 1, -1, math.MaxInt8, math.MinInt8, math.MaxInt16, math.MinInt16, math.MinInt32, math.MaxInt32}
|
||||
invalidInts := []string{"1.233", "a", "false", strconv.Itoa(int(math.MaxInt64))}
|
||||
|
||||
for _, f := range validInts {
|
||||
c, err := ConvertInt32(FormatInt32(f))
|
||||
if assert.NoError(t, err) {
|
||||
assert.EqualValues(t, f, c)
|
||||
}
|
||||
}
|
||||
for _, f := range invalidInts {
|
||||
_, err := ConvertInt32(f)
|
||||
assert.Error(t, err, "expected '"+f+"' to generate an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertInt64(t *testing.T) {
|
||||
validInts := []int64{0, 1, -1, math.MaxInt8, math.MinInt8, math.MaxInt16, math.MinInt16, math.MinInt32, math.MaxInt32, math.MaxInt64, math.MinInt64}
|
||||
invalidInts := []string{"1.233", "a", "false"}
|
||||
|
||||
for _, f := range validInts {
|
||||
c, err := ConvertInt64(FormatInt64(f))
|
||||
if assert.NoError(t, err) {
|
||||
assert.EqualValues(t, f, c)
|
||||
}
|
||||
}
|
||||
for _, f := range invalidInts {
|
||||
_, err := ConvertInt64(f)
|
||||
assert.Error(t, err, "expected '"+f+"' to generate an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertUint8(t *testing.T) {
|
||||
validInts := []uint8{0, 1, math.MaxUint8}
|
||||
invalidInts := []string{"1.233", "a", "false", strconv.FormatUint(math.MaxUint64, 10)}
|
||||
|
||||
for _, f := range validInts {
|
||||
c, err := ConvertUint8(FormatUint8(f))
|
||||
if assert.NoError(t, err) {
|
||||
assert.EqualValues(t, f, c)
|
||||
}
|
||||
}
|
||||
for _, f := range invalidInts {
|
||||
_, err := ConvertUint8(f)
|
||||
assert.Error(t, err, "expected '"+f+"' to generate an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertUint16(t *testing.T) {
|
||||
validUints := []uint16{0, 1, math.MaxUint8, math.MaxUint16}
|
||||
invalidUints := []string{"1.233", "a", "false", strconv.FormatUint(math.MaxUint64, 10)}
|
||||
|
||||
for _, f := range validUints {
|
||||
c, err := ConvertUint16(FormatUint16(f))
|
||||
if assert.NoError(t, err) {
|
||||
assert.EqualValues(t, f, c)
|
||||
}
|
||||
}
|
||||
for _, f := range invalidUints {
|
||||
_, err := ConvertUint16(f)
|
||||
assert.Error(t, err, "expected '"+f+"' to generate an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertUint32(t *testing.T) {
|
||||
validUints := []uint32{0, 1, math.MaxUint8, math.MaxUint16, math.MaxUint32}
|
||||
invalidUints := []string{"1.233", "a", "false", strconv.FormatUint(math.MaxUint64, 10)}
|
||||
|
||||
for _, f := range validUints {
|
||||
c, err := ConvertUint32(FormatUint32(f))
|
||||
if assert.NoError(t, err) {
|
||||
assert.EqualValues(t, f, c)
|
||||
}
|
||||
}
|
||||
for _, f := range invalidUints {
|
||||
_, err := ConvertUint32(f)
|
||||
assert.Error(t, err, "expected '"+f+"' to generate an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertUint64(t *testing.T) {
|
||||
validUints := []uint64{0, 1, math.MaxUint8, math.MaxUint16, math.MaxUint32, math.MaxUint64}
|
||||
invalidUints := []string{"1.233", "a", "false"}
|
||||
|
||||
for _, f := range validUints {
|
||||
c, err := ConvertUint64(FormatUint64(f))
|
||||
if assert.NoError(t, err) {
|
||||
assert.EqualValues(t, f, c)
|
||||
}
|
||||
}
|
||||
for _, f := range invalidUints {
|
||||
_, err := ConvertUint64(f)
|
||||
assert.Error(t, err, "expected '"+f+"' to generate an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsFloat64AJSONInteger(t *testing.T) {
|
||||
assert.False(t, IsFloat64AJSONInteger(math.Inf(1)))
|
||||
assert.False(t, IsFloat64AJSONInteger(maxJSONFloat+1))
|
||||
|
||||
assert.False(t, IsFloat64AJSONInteger(minJSONFloat-1))
|
||||
assert.True(t, IsFloat64AJSONInteger(1.0))
|
||||
assert.True(t, IsFloat64AJSONInteger(maxJSONFloat))
|
||||
assert.True(t, IsFloat64AJSONInteger(minJSONFloat))
|
||||
}
|
||||
|
||||
func TestFormatBool(t *testing.T) {
|
||||
assert.Equal(t, "true", FormatBool(true))
|
||||
assert.Equal(t, "false", FormatBool(false))
|
||||
}
|
||||
579
vendor/github.com/go-openapi/swag/convert_types_test.go
generated
vendored
579
vendor/github.com/go-openapi/swag/convert_types_test.go
generated
vendored
@@ -1,579 +0,0 @@
|
||||
package swag
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var testCasesStringSlice = [][]string{
|
||||
{"a", "b", "c", "d", "e"},
|
||||
{"a", "b", "", "", "e"},
|
||||
}
|
||||
|
||||
func TestStringSlice(t *testing.T) {
|
||||
for idx, in := range testCasesStringSlice {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := StringSlice(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
|
||||
}
|
||||
|
||||
out2 := StringValueSlice(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesStringValueSlice = [][]*string{
|
||||
{String("a"), String("b"), nil, String("c")},
|
||||
}
|
||||
|
||||
func TestStringValueSlice(t *testing.T) {
|
||||
for idx, in := range testCasesStringValueSlice {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := StringValueSlice(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
if in[i] == nil {
|
||||
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
|
||||
} else {
|
||||
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
out2 := StringSlice(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out2 {
|
||||
if in[i] == nil {
|
||||
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
|
||||
} else {
|
||||
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesStringMap = []map[string]string{
|
||||
{"a": "1", "b": "2", "c": "3"},
|
||||
}
|
||||
|
||||
func TestStringMap(t *testing.T) {
|
||||
for idx, in := range testCasesStringMap {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := StringMap(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
|
||||
}
|
||||
|
||||
out2 := StringValueMap(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesBoolSlice = [][]bool{
|
||||
{true, true, false, false},
|
||||
}
|
||||
|
||||
func TestBoolSlice(t *testing.T) {
|
||||
for idx, in := range testCasesBoolSlice {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := BoolSlice(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
|
||||
}
|
||||
|
||||
out2 := BoolValueSlice(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesBoolValueSlice = [][]*bool{}
|
||||
|
||||
func TestBoolValueSlice(t *testing.T) {
|
||||
for idx, in := range testCasesBoolValueSlice {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := BoolValueSlice(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
if in[i] == nil {
|
||||
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
|
||||
} else {
|
||||
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
out2 := BoolSlice(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out2 {
|
||||
if in[i] == nil {
|
||||
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
|
||||
} else {
|
||||
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesBoolMap = []map[string]bool{
|
||||
{"a": true, "b": false, "c": true},
|
||||
}
|
||||
|
||||
func TestBoolMap(t *testing.T) {
|
||||
for idx, in := range testCasesBoolMap {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := BoolMap(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
|
||||
}
|
||||
|
||||
out2 := BoolValueMap(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesIntSlice = [][]int{
|
||||
{1, 2, 3, 4},
|
||||
}
|
||||
|
||||
func TestIntSlice(t *testing.T) {
|
||||
for idx, in := range testCasesIntSlice {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := IntSlice(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
|
||||
}
|
||||
|
||||
out2 := IntValueSlice(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesIntValueSlice = [][]*int{}
|
||||
|
||||
func TestIntValueSlice(t *testing.T) {
|
||||
for idx, in := range testCasesIntValueSlice {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := IntValueSlice(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
if in[i] == nil {
|
||||
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
|
||||
} else {
|
||||
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
out2 := IntSlice(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out2 {
|
||||
if in[i] == nil {
|
||||
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
|
||||
} else {
|
||||
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesIntMap = []map[string]int{
|
||||
{"a": 3, "b": 2, "c": 1},
|
||||
}
|
||||
|
||||
func TestIntMap(t *testing.T) {
|
||||
for idx, in := range testCasesIntMap {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := IntMap(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
|
||||
}
|
||||
|
||||
out2 := IntValueMap(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesInt64Slice = [][]int64{
|
||||
{1, 2, 3, 4},
|
||||
}
|
||||
|
||||
func TestInt64Slice(t *testing.T) {
|
||||
for idx, in := range testCasesInt64Slice {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := Int64Slice(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
|
||||
}
|
||||
|
||||
out2 := Int64ValueSlice(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesInt64ValueSlice = [][]*int64{}
|
||||
|
||||
func TestInt64ValueSlice(t *testing.T) {
|
||||
for idx, in := range testCasesInt64ValueSlice {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := Int64ValueSlice(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
if in[i] == nil {
|
||||
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
|
||||
} else {
|
||||
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
out2 := Int64Slice(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out2 {
|
||||
if in[i] == nil {
|
||||
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
|
||||
} else {
|
||||
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesInt64Map = []map[string]int64{
|
||||
{"a": 3, "b": 2, "c": 1},
|
||||
}
|
||||
|
||||
func TestInt64Map(t *testing.T) {
|
||||
for idx, in := range testCasesInt64Map {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := Int64Map(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
|
||||
}
|
||||
|
||||
out2 := Int64ValueMap(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesFloat64Slice = [][]float64{
|
||||
{1, 2, 3, 4},
|
||||
}
|
||||
|
||||
func TestFloat64Slice(t *testing.T) {
|
||||
for idx, in := range testCasesFloat64Slice {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := Float64Slice(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
|
||||
}
|
||||
|
||||
out2 := Float64ValueSlice(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesUintSlice = [][]uint{
|
||||
{1, 2, 3, 4},
|
||||
}
|
||||
|
||||
func TestUintSlice(t *testing.T) {
|
||||
for idx, in := range testCasesUintSlice {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := UintSlice(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
|
||||
}
|
||||
|
||||
out2 := UintValueSlice(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesUintValueSlice = [][]*uint{}
|
||||
|
||||
func TestUintValueSlice(t *testing.T) {
|
||||
for idx, in := range testCasesUintValueSlice {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := UintValueSlice(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
if in[i] == nil {
|
||||
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
|
||||
} else {
|
||||
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
out2 := UintSlice(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out2 {
|
||||
if in[i] == nil {
|
||||
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
|
||||
} else {
|
||||
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesUintMap = []map[string]uint{
|
||||
{"a": 3, "b": 2, "c": 1},
|
||||
}
|
||||
|
||||
func TestUintMap(t *testing.T) {
|
||||
for idx, in := range testCasesUintMap {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := UintMap(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
|
||||
}
|
||||
|
||||
out2 := UintValueMap(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesUint64Slice = [][]uint64{
|
||||
{1, 2, 3, 4},
|
||||
}
|
||||
|
||||
func TestUint64Slice(t *testing.T) {
|
||||
for idx, in := range testCasesUint64Slice {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := Uint64Slice(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
|
||||
}
|
||||
|
||||
out2 := Uint64ValueSlice(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesUint64ValueSlice = [][]*uint64{}
|
||||
|
||||
func TestUint64ValueSlice(t *testing.T) {
|
||||
for idx, in := range testCasesUint64ValueSlice {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := Uint64ValueSlice(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
if in[i] == nil {
|
||||
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
|
||||
} else {
|
||||
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
out2 := Uint64Slice(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out2 {
|
||||
if in[i] == nil {
|
||||
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
|
||||
} else {
|
||||
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesUint64Map = []map[string]uint64{
|
||||
{"a": 3, "b": 2, "c": 1},
|
||||
}
|
||||
|
||||
func TestUint64Map(t *testing.T) {
|
||||
for idx, in := range testCasesUint64Map {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := Uint64Map(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
|
||||
}
|
||||
|
||||
out2 := Uint64ValueMap(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesFloat64ValueSlice = [][]*float64{}
|
||||
|
||||
func TestFloat64ValueSlice(t *testing.T) {
|
||||
for idx, in := range testCasesFloat64ValueSlice {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := Float64ValueSlice(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
if in[i] == nil {
|
||||
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
|
||||
} else {
|
||||
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
out2 := Float64Slice(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out2 {
|
||||
if in[i] == nil {
|
||||
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
|
||||
} else {
|
||||
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesFloat64Map = []map[string]float64{
|
||||
{"a": 3, "b": 2, "c": 1},
|
||||
}
|
||||
|
||||
func TestFloat64Map(t *testing.T) {
|
||||
for idx, in := range testCasesFloat64Map {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := Float64Map(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
|
||||
}
|
||||
|
||||
out2 := Float64ValueMap(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesTimeSlice = [][]time.Time{
|
||||
{time.Now(), time.Now().AddDate(100, 0, 0)},
|
||||
}
|
||||
|
||||
func TestTimeSlice(t *testing.T) {
|
||||
for idx, in := range testCasesTimeSlice {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := TimeSlice(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
|
||||
}
|
||||
|
||||
out2 := TimeValueSlice(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesTimeValueSlice = [][]*time.Time{}
|
||||
|
||||
func TestTimeValueSlice(t *testing.T) {
|
||||
for idx, in := range testCasesTimeValueSlice {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := TimeValueSlice(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
if in[i] == nil {
|
||||
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
|
||||
} else {
|
||||
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
|
||||
out2 := TimeSlice(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out2 {
|
||||
if in[i] == nil {
|
||||
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
|
||||
} else {
|
||||
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var testCasesTimeMap = []map[string]time.Time{
|
||||
{"a": time.Now().AddDate(-100, 0, 0), "b": time.Now()},
|
||||
}
|
||||
|
||||
func TestTimeMap(t *testing.T) {
|
||||
for idx, in := range testCasesTimeMap {
|
||||
if in == nil {
|
||||
continue
|
||||
}
|
||||
out := TimeMap(in)
|
||||
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
|
||||
for i := range out {
|
||||
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
|
||||
}
|
||||
|
||||
out2 := TimeValueMap(out)
|
||||
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
|
||||
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
|
||||
}
|
||||
}
|
||||
163
vendor/github.com/go-openapi/swag/json_test.go
generated
vendored
163
vendor/github.com/go-openapi/swag/json_test.go
generated
vendored
@@ -1,163 +0,0 @@
|
||||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package swag
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type testNameStruct struct {
|
||||
Name string `json:"name"`
|
||||
NotTheSame int64 `json:"plain"`
|
||||
Ignored string `json:"-"`
|
||||
}
|
||||
|
||||
func TestNameProvider(t *testing.T) {
|
||||
|
||||
provider := NewNameProvider()
|
||||
|
||||
var obj = testNameStruct{}
|
||||
|
||||
nm, ok := provider.GetGoName(obj, "name")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "Name", nm)
|
||||
|
||||
nm, ok = provider.GetGoName(obj, "plain")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "NotTheSame", nm)
|
||||
|
||||
nm, ok = provider.GetGoName(obj, "doesNotExist")
|
||||
assert.False(t, ok)
|
||||
assert.Empty(t, nm)
|
||||
|
||||
nm, ok = provider.GetGoName(obj, "ignored")
|
||||
assert.False(t, ok)
|
||||
assert.Empty(t, nm)
|
||||
|
||||
tpe := reflect.TypeOf(obj)
|
||||
nm, ok = provider.GetGoNameForType(tpe, "name")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "Name", nm)
|
||||
|
||||
nm, ok = provider.GetGoNameForType(tpe, "plain")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "NotTheSame", nm)
|
||||
|
||||
nm, ok = provider.GetGoNameForType(tpe, "doesNotExist")
|
||||
assert.False(t, ok)
|
||||
assert.Empty(t, nm)
|
||||
|
||||
nm, ok = provider.GetGoNameForType(tpe, "ignored")
|
||||
assert.False(t, ok)
|
||||
assert.Empty(t, nm)
|
||||
|
||||
ptr := &obj
|
||||
nm, ok = provider.GetGoName(ptr, "name")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "Name", nm)
|
||||
|
||||
nm, ok = provider.GetGoName(ptr, "plain")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "NotTheSame", nm)
|
||||
|
||||
nm, ok = provider.GetGoName(ptr, "doesNotExist")
|
||||
assert.False(t, ok)
|
||||
assert.Empty(t, nm)
|
||||
|
||||
nm, ok = provider.GetGoName(ptr, "ignored")
|
||||
assert.False(t, ok)
|
||||
assert.Empty(t, nm)
|
||||
|
||||
nm, ok = provider.GetJSONName(obj, "Name")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "name", nm)
|
||||
|
||||
nm, ok = provider.GetJSONName(obj, "NotTheSame")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "plain", nm)
|
||||
|
||||
nm, ok = provider.GetJSONName(obj, "DoesNotExist")
|
||||
assert.False(t, ok)
|
||||
assert.Empty(t, nm)
|
||||
|
||||
nm, ok = provider.GetJSONName(obj, "Ignored")
|
||||
assert.False(t, ok)
|
||||
assert.Empty(t, nm)
|
||||
|
||||
nm, ok = provider.GetJSONNameForType(tpe, "Name")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "name", nm)
|
||||
|
||||
nm, ok = provider.GetJSONNameForType(tpe, "NotTheSame")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "plain", nm)
|
||||
|
||||
nm, ok = provider.GetJSONNameForType(tpe, "doesNotExist")
|
||||
assert.False(t, ok)
|
||||
assert.Empty(t, nm)
|
||||
|
||||
nm, ok = provider.GetJSONNameForType(tpe, "Ignored")
|
||||
assert.False(t, ok)
|
||||
assert.Empty(t, nm)
|
||||
|
||||
nm, ok = provider.GetJSONName(ptr, "Name")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "name", nm)
|
||||
|
||||
nm, ok = provider.GetJSONName(ptr, "NotTheSame")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "plain", nm)
|
||||
|
||||
nm, ok = provider.GetJSONName(ptr, "doesNotExist")
|
||||
assert.False(t, ok)
|
||||
assert.Empty(t, nm)
|
||||
|
||||
nm, ok = provider.GetJSONName(ptr, "Ignored")
|
||||
assert.False(t, ok)
|
||||
assert.Empty(t, nm)
|
||||
|
||||
nms := provider.GetJSONNames(ptr)
|
||||
assert.Len(t, nms, 2)
|
||||
|
||||
assert.Len(t, provider.index, 1)
|
||||
|
||||
}
|
||||
|
||||
func TestJSONConcatenation(t *testing.T) {
|
||||
assert.Nil(t, ConcatJSON())
|
||||
assert.Equal(t, ConcatJSON([]byte(`{"id":1}`)), []byte(`{"id":1}`))
|
||||
assert.Equal(t, ConcatJSON([]byte(`{}`), []byte(`{}`)), []byte(`{}`))
|
||||
assert.Equal(t, ConcatJSON([]byte(`[]`), []byte(`[]`)), []byte(`[]`))
|
||||
assert.Equal(t, ConcatJSON([]byte(`{"id":1}`), []byte(`{"name":"Rachel"}`)), []byte(`{"id":1,"name":"Rachel"}`))
|
||||
assert.Equal(t, ConcatJSON([]byte(`[{"id":1}]`), []byte(`[{"name":"Rachel"}]`)), []byte(`[{"id":1},{"name":"Rachel"}]`))
|
||||
assert.Equal(t, ConcatJSON([]byte(`{}`), []byte(`{"name":"Rachel"}`)), []byte(`{"name":"Rachel"}`))
|
||||
assert.Equal(t, ConcatJSON([]byte(`[]`), []byte(`[{"name":"Rachel"}]`)), []byte(`[{"name":"Rachel"}]`))
|
||||
assert.Equal(t, ConcatJSON([]byte(`{"id":1}`), []byte(`{}`)), []byte(`{"id":1}`))
|
||||
assert.Equal(t, ConcatJSON([]byte(`[{"id":1}]`), []byte(`[]`)), []byte(`[{"id":1}]`))
|
||||
assert.Equal(t, ConcatJSON([]byte(`{}`), []byte(`{}`), []byte(`{}`)), []byte(`{}`))
|
||||
assert.Equal(t, ConcatJSON([]byte(`[]`), []byte(`[]`), []byte(`[]`)), []byte(`[]`))
|
||||
assert.Equal(t, ConcatJSON([]byte(`{"id":1}`), []byte(`{"name":"Rachel"}`), []byte(`{"age":32}`)), []byte(`{"id":1,"name":"Rachel","age":32}`))
|
||||
assert.Equal(t, ConcatJSON([]byte(`[{"id":1}]`), []byte(`[{"name":"Rachel"}]`), []byte(`[{"age":32}]`)), []byte(`[{"id":1},{"name":"Rachel"},{"age":32}]`))
|
||||
assert.Equal(t, ConcatJSON([]byte(`{}`), []byte(`{"name":"Rachel"}`), []byte(`{"age":32}`)), []byte(`{"name":"Rachel","age":32}`))
|
||||
assert.Equal(t, ConcatJSON([]byte(`[]`), []byte(`[{"name":"Rachel"}]`), []byte(`[{"age":32}]`)), []byte(`[{"name":"Rachel"},{"age":32}]`))
|
||||
assert.Equal(t, ConcatJSON([]byte(`{"id":1}`), []byte(`{}`), []byte(`{"age":32}`)), []byte(`{"id":1,"age":32}`))
|
||||
assert.Equal(t, ConcatJSON([]byte(`[{"id":1}]`), []byte(`[]`), []byte(`[{"age":32}]`)), []byte(`[{"id":1},{"age":32}]`))
|
||||
assert.Equal(t, ConcatJSON([]byte(`{"id":1}`), []byte(`{"name":"Rachel"}`), []byte(`{}`)), []byte(`{"id":1,"name":"Rachel"}`))
|
||||
assert.Equal(t, ConcatJSON([]byte(`[{"id":1}]`), []byte(`[{"name":"Rachel"}]`), []byte(`[]`)), []byte(`[{"id":1},{"name":"Rachel"}]`))
|
||||
|
||||
}
|
||||
47
vendor/github.com/go-openapi/swag/loading_test.go
generated
vendored
47
vendor/github.com/go-openapi/swag/loading_test.go
generated
vendored
@@ -1,47 +0,0 @@
|
||||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package swag
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestLoadFromHTTP(t *testing.T) {
|
||||
|
||||
_, err := LoadFromFileOrHTTP("httx://12394:abd")
|
||||
assert.Error(t, err)
|
||||
|
||||
serv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
rw.WriteHeader(http.StatusNotFound)
|
||||
}))
|
||||
defer serv.Close()
|
||||
|
||||
_, err = LoadFromFileOrHTTP(serv.URL)
|
||||
assert.Error(t, err)
|
||||
|
||||
ts2 := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
rw.Write([]byte("the content"))
|
||||
}))
|
||||
defer ts2.Close()
|
||||
|
||||
d, err := LoadFromFileOrHTTP(ts2.URL)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []byte("the content"), d)
|
||||
}
|
||||
30
vendor/github.com/go-openapi/swag/net_test.go
generated
vendored
30
vendor/github.com/go-openapi/swag/net_test.go
generated
vendored
@@ -1,30 +0,0 @@
|
||||
package swag
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSplitHostPort(t *testing.T) {
|
||||
data := []struct {
|
||||
Input string
|
||||
Host string
|
||||
Port int
|
||||
Err bool
|
||||
}{
|
||||
{"localhost:3933", "localhost", 3933, false},
|
||||
{"localhost:yellow", "", -1, true},
|
||||
{"localhost", "", -1, true},
|
||||
{"localhost:", "", -1, true},
|
||||
{"localhost:3933", "localhost", 3933, false},
|
||||
}
|
||||
|
||||
for _, e := range data {
|
||||
h, p, err := SplitHostPort(e.Input)
|
||||
if (!e.Err && assert.NoError(t, err)) || (e.Err && assert.Error(t, err)) {
|
||||
assert.Equal(t, e.Host, h)
|
||||
assert.Equal(t, e.Port, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
118
vendor/github.com/go-openapi/swag/path_test.go
generated
vendored
118
vendor/github.com/go-openapi/swag/path_test.go
generated
vendored
@@ -1,118 +0,0 @@
|
||||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package swag
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func makeDirStructure(t *testing.T, tgt string) (string, string, error) {
|
||||
if tgt == "" {
|
||||
tgt = "pkgpaths"
|
||||
}
|
||||
td, err := ioutil.TempDir("", tgt)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
td2, err := ioutil.TempDir("", tgt+"-2")
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
realPath := filepath.Join(td, "src", "foo", "bar")
|
||||
if err := os.MkdirAll(realPath, os.ModePerm); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
linkPathBase := filepath.Join(td, "src", "baz")
|
||||
if err := os.MkdirAll(linkPathBase, os.ModePerm); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
linkPath := filepath.Join(linkPathBase, "das")
|
||||
if err := os.Symlink(realPath, linkPath); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
realPath = filepath.Join(td2, "src", "fuu", "bir")
|
||||
if err := os.MkdirAll(realPath, os.ModePerm); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
linkPathBase = filepath.Join(td2, "src", "biz")
|
||||
if err := os.MkdirAll(linkPathBase, os.ModePerm); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
linkPath = filepath.Join(linkPathBase, "dis")
|
||||
if err := os.Symlink(realPath, linkPath); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
return td, td2, nil
|
||||
}
|
||||
|
||||
func TestFindPackage(t *testing.T) {
|
||||
pth, pth2, err := makeDirStructure(t, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() {
|
||||
os.RemoveAll(pth)
|
||||
os.RemoveAll(pth2)
|
||||
}()
|
||||
|
||||
searchPath := pth + string(filepath.ListSeparator) + pth2
|
||||
// finds package when real name mentioned
|
||||
pkg := FindInSearchPath(searchPath, "foo/bar")
|
||||
assert.NotEmpty(t, pkg)
|
||||
assertPath(t, path.Join(pth, "src", "foo", "bar"), pkg)
|
||||
// finds package when real name is mentioned in secondary
|
||||
pkg = FindInSearchPath(searchPath, "fuu/bir")
|
||||
assert.NotEmpty(t, pkg)
|
||||
assertPath(t, path.Join(pth2, "src", "fuu", "bir"), pkg)
|
||||
// finds package when symlinked
|
||||
pkg = FindInSearchPath(searchPath, "baz/das")
|
||||
assert.NotEmpty(t, pkg)
|
||||
assertPath(t, path.Join(pth, "src", "foo", "bar"), pkg)
|
||||
// finds package when symlinked in secondary
|
||||
pkg = FindInSearchPath(searchPath, "biz/dis")
|
||||
assert.NotEmpty(t, pkg)
|
||||
assertPath(t, path.Join(pth2, "src", "fuu", "bir"), pkg)
|
||||
// return empty string when nothing is found
|
||||
pkg = FindInSearchPath(searchPath, "not/there")
|
||||
assert.Empty(t, pkg)
|
||||
}
|
||||
|
||||
func assertPath(t testing.TB, expected, actual string) bool {
|
||||
fp, err := filepath.EvalSymlinks(expected)
|
||||
if assert.NoError(t, err) {
|
||||
return assert.Equal(t, fp, actual)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func TestFullGOPATH(t *testing.T) {
|
||||
os.Unsetenv(GOPATHKey)
|
||||
ngp := "/some/where:/other/place"
|
||||
os.Setenv(GOPATHKey, ngp)
|
||||
|
||||
ogp := os.Getenv(GOPATHKey)
|
||||
defer os.Setenv(GOPATHKey, ogp)
|
||||
|
||||
expected := ngp + ":" + runtime.GOROOT()
|
||||
assert.Equal(t, expected, FullGoSearchPath())
|
||||
}
|
||||
286
vendor/github.com/go-openapi/swag/util_test.go
generated
vendored
286
vendor/github.com/go-openapi/swag/util_test.go
generated
vendored
@@ -1,286 +0,0 @@
|
||||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package swag
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type translationSample struct {
|
||||
str, out string
|
||||
}
|
||||
|
||||
func titleize(s string) string { return strings.ToTitle(s[:1]) + lower(s[1:]) }
|
||||
|
||||
func TestToGoName(t *testing.T) {
|
||||
samples := []translationSample{
|
||||
{"sample text", "SampleText"},
|
||||
{"sample-text", "SampleText"},
|
||||
{"sample_text", "SampleText"},
|
||||
{"sampleText", "SampleText"},
|
||||
{"sample 2 Text", "Sample2Text"},
|
||||
{"findThingById", "FindThingByID"},
|
||||
{"日本語sample 2 Text", "X日本語sample2Text"},
|
||||
{"日本語findThingById", "X日本語findThingByID"},
|
||||
{"findTHINGSbyID", "FindTHINGSbyID"},
|
||||
}
|
||||
|
||||
for k := range commonInitialisms {
|
||||
samples = append(samples,
|
||||
translationSample{"sample " + lower(k) + " text", "Sample" + k + "Text"},
|
||||
translationSample{"sample-" + lower(k) + "-text", "Sample" + k + "Text"},
|
||||
translationSample{"sample_" + lower(k) + "_text", "Sample" + k + "Text"},
|
||||
translationSample{"sample" + titleize(k) + "Text", "Sample" + k + "Text"},
|
||||
translationSample{"sample " + lower(k), "Sample" + k},
|
||||
translationSample{"sample-" + lower(k), "Sample" + k},
|
||||
translationSample{"sample_" + lower(k), "Sample" + k},
|
||||
translationSample{"sample" + titleize(k), "Sample" + k},
|
||||
translationSample{"sample " + titleize(k) + " text", "Sample" + k + "Text"},
|
||||
translationSample{"sample-" + titleize(k) + "-text", "Sample" + k + "Text"},
|
||||
translationSample{"sample_" + titleize(k) + "_text", "Sample" + k + "Text"},
|
||||
)
|
||||
}
|
||||
|
||||
for _, sample := range samples {
|
||||
assert.Equal(t, sample.out, ToGoName(sample.str))
|
||||
}
|
||||
}
|
||||
|
||||
func TestContainsStringsCI(t *testing.T) {
|
||||
list := []string{"hello", "world", "and", "such"}
|
||||
|
||||
assert.True(t, ContainsStringsCI(list, "hELLo"))
|
||||
assert.True(t, ContainsStringsCI(list, "world"))
|
||||
assert.True(t, ContainsStringsCI(list, "AND"))
|
||||
assert.False(t, ContainsStringsCI(list, "nuts"))
|
||||
}
|
||||
|
||||
func TestSplitByFormat(t *testing.T) {
|
||||
expected := []string{"one", "two", "three"}
|
||||
for _, fmt := range []string{"csv", "pipes", "tsv", "ssv", "multi"} {
|
||||
|
||||
var actual []string
|
||||
switch fmt {
|
||||
case "multi":
|
||||
assert.Nil(t, SplitByFormat("", fmt))
|
||||
assert.Nil(t, SplitByFormat("blah", fmt))
|
||||
case "ssv":
|
||||
actual = SplitByFormat(strings.Join(expected, " "), fmt)
|
||||
assert.EqualValues(t, expected, actual)
|
||||
case "pipes":
|
||||
actual = SplitByFormat(strings.Join(expected, "|"), fmt)
|
||||
assert.EqualValues(t, expected, actual)
|
||||
case "tsv":
|
||||
actual = SplitByFormat(strings.Join(expected, "\t"), fmt)
|
||||
assert.EqualValues(t, expected, actual)
|
||||
default:
|
||||
actual = SplitByFormat(strings.Join(expected, ","), fmt)
|
||||
assert.EqualValues(t, expected, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestJoinByFormat(t *testing.T) {
|
||||
for _, fmt := range []string{"csv", "pipes", "tsv", "ssv", "multi"} {
|
||||
|
||||
lval := []string{"one", "two", "three"}
|
||||
var expected []string
|
||||
switch fmt {
|
||||
case "multi":
|
||||
expected = lval
|
||||
case "ssv":
|
||||
expected = []string{strings.Join(lval, " ")}
|
||||
case "pipes":
|
||||
expected = []string{strings.Join(lval, "|")}
|
||||
case "tsv":
|
||||
expected = []string{strings.Join(lval, "\t")}
|
||||
default:
|
||||
expected = []string{strings.Join(lval, ",")}
|
||||
}
|
||||
assert.Nil(t, JoinByFormat(nil, fmt))
|
||||
assert.EqualValues(t, expected, JoinByFormat(lval, fmt))
|
||||
}
|
||||
}
|
||||
|
||||
func TestToFileName(t *testing.T) {
|
||||
samples := []translationSample{
|
||||
{"SampleText", "sample_text"},
|
||||
{"FindThingByID", "find_thing_by_id"},
|
||||
{"CAPWD.folwdBYlc", "capwd_folwd_bylc"},
|
||||
{"CAPWDfolwdBYlc", "capwdfolwd_bylc"},
|
||||
{"CAP_WD_folwdBYlc", "cap_wd_folwd_bylc"},
|
||||
{"TypeOAI_alias", "type_oai_alias"},
|
||||
{"Type_OAI_alias", "type_oai_alias"},
|
||||
{"Type_OAIAlias", "type_oai_alias"},
|
||||
{"ELB.HTTPLoadBalancer", "elb_http_load_balancer"},
|
||||
{"elbHTTPLoadBalancer", "elb_http_load_balancer"},
|
||||
{"ELBHTTPLoadBalancer", "elb_http_load_balancer"},
|
||||
}
|
||||
for k := range commonInitialisms {
|
||||
samples = append(samples,
|
||||
translationSample{"Sample" + k + "Text", "sample_" + lower(k) + "_text"},
|
||||
)
|
||||
}
|
||||
|
||||
for _, sample := range samples {
|
||||
assert.Equal(t, sample.out, ToFileName(sample.str))
|
||||
}
|
||||
}
|
||||
|
||||
func TestToCommandName(t *testing.T) {
|
||||
samples := []translationSample{
|
||||
{"SampleText", "sample-text"},
|
||||
{"FindThingByID", "find-thing-by-id"},
|
||||
}
|
||||
|
||||
for k := range commonInitialisms {
|
||||
samples = append(samples,
|
||||
translationSample{"Sample" + k + "Text", "sample-" + lower(k) + "-text"},
|
||||
)
|
||||
}
|
||||
|
||||
for _, sample := range samples {
|
||||
assert.Equal(t, sample.out, ToCommandName(sample.str))
|
||||
}
|
||||
}
|
||||
|
||||
func TestToHumanName(t *testing.T) {
|
||||
samples := []translationSample{
|
||||
{"SampleText", "sample text"},
|
||||
{"FindThingByID", "find thing by ID"},
|
||||
}
|
||||
|
||||
for k := range commonInitialisms {
|
||||
samples = append(samples,
|
||||
translationSample{"Sample" + k + "Text", "sample " + k + " text"},
|
||||
)
|
||||
}
|
||||
|
||||
for _, sample := range samples {
|
||||
assert.Equal(t, sample.out, ToHumanNameLower(sample.str))
|
||||
}
|
||||
}
|
||||
|
||||
func TestToJSONName(t *testing.T) {
|
||||
samples := []translationSample{
|
||||
{"SampleText", "sampleText"},
|
||||
{"FindThingByID", "findThingById"},
|
||||
}
|
||||
|
||||
for k := range commonInitialisms {
|
||||
samples = append(samples,
|
||||
translationSample{"Sample" + k + "Text", "sample" + titleize(k) + "Text"},
|
||||
)
|
||||
}
|
||||
|
||||
for _, sample := range samples {
|
||||
assert.Equal(t, sample.out, ToJSONName(sample.str))
|
||||
}
|
||||
}
|
||||
|
||||
type SimpleZeroes struct {
|
||||
ID string
|
||||
Name string
|
||||
}
|
||||
type ZeroesWithTime struct {
|
||||
Time time.Time
|
||||
}
|
||||
|
||||
func TestIsZero(t *testing.T) {
|
||||
var strs [5]string
|
||||
var strss []string
|
||||
var a int
|
||||
var b int8
|
||||
var c int16
|
||||
var d int32
|
||||
var e int64
|
||||
var f uint
|
||||
var g uint8
|
||||
var h uint16
|
||||
var i uint32
|
||||
var j uint64
|
||||
var k map[string]string
|
||||
var l interface{}
|
||||
var m *SimpleZeroes
|
||||
var n string
|
||||
var o SimpleZeroes
|
||||
var p ZeroesWithTime
|
||||
var q time.Time
|
||||
data := []struct {
|
||||
Data interface{}
|
||||
Expected bool
|
||||
}{
|
||||
{a, true},
|
||||
{b, true},
|
||||
{c, true},
|
||||
{d, true},
|
||||
{e, true},
|
||||
{f, true},
|
||||
{g, true},
|
||||
{h, true},
|
||||
{i, true},
|
||||
{j, true},
|
||||
{k, true},
|
||||
{l, true},
|
||||
{m, true},
|
||||
{n, true},
|
||||
{o, true},
|
||||
{p, true},
|
||||
{q, true},
|
||||
{strss, true},
|
||||
{strs, true},
|
||||
{"", true},
|
||||
{nil, true},
|
||||
{1, false},
|
||||
{0, true},
|
||||
{int8(1), false},
|
||||
{int8(0), true},
|
||||
{int16(1), false},
|
||||
{int16(0), true},
|
||||
{int32(1), false},
|
||||
{int32(0), true},
|
||||
{int64(1), false},
|
||||
{int64(0), true},
|
||||
{uint(1), false},
|
||||
{uint(0), true},
|
||||
{uint8(1), false},
|
||||
{uint8(0), true},
|
||||
{uint16(1), false},
|
||||
{uint16(0), true},
|
||||
{uint32(1), false},
|
||||
{uint32(0), true},
|
||||
{uint64(1), false},
|
||||
{uint64(0), true},
|
||||
{0.0, true},
|
||||
{0.1, false},
|
||||
{float32(0.0), true},
|
||||
{float32(0.1), false},
|
||||
{float64(0.0), true},
|
||||
{float64(0.1), false},
|
||||
{[...]string{}, true},
|
||||
{[...]string{"hello"}, false},
|
||||
{[]string(nil), true},
|
||||
{[]string{"a"}, false},
|
||||
}
|
||||
|
||||
for _, it := range data {
|
||||
assert.Equal(t, it.Expected, IsZero(it.Data), fmt.Sprintf("%#v", it.Data))
|
||||
}
|
||||
}
|
||||
444
vendor/github.com/go-openapi/swag/yaml_test.go
generated
vendored
444
vendor/github.com/go-openapi/swag/yaml_test.go
generated
vendored
@@ -1,444 +0,0 @@
|
||||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package swag
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type failJSONMarhal struct {
|
||||
}
|
||||
|
||||
func (f failJSONMarhal) MarshalJSON() ([]byte, error) {
|
||||
return nil, errors.New("expected")
|
||||
}
|
||||
|
||||
func TestLoadHTTPBytes(t *testing.T) {
|
||||
_, err := LoadFromFileOrHTTP("httx://12394:abd")
|
||||
assert.Error(t, err)
|
||||
|
||||
serv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
rw.WriteHeader(http.StatusNotFound)
|
||||
}))
|
||||
defer serv.Close()
|
||||
|
||||
_, err = LoadFromFileOrHTTP(serv.URL)
|
||||
assert.Error(t, err)
|
||||
|
||||
ts2 := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
rw.Write([]byte("the content"))
|
||||
}))
|
||||
defer ts2.Close()
|
||||
|
||||
d, err := LoadFromFileOrHTTP(ts2.URL)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []byte("the content"), d)
|
||||
}
|
||||
|
||||
func TestYAMLToJSON(t *testing.T) {
|
||||
|
||||
sd := `---
|
||||
1: the int key value
|
||||
name: a string value
|
||||
'y': some value
|
||||
`
|
||||
var data yaml.MapSlice
|
||||
yaml.Unmarshal([]byte(sd), &data)
|
||||
|
||||
d, err := YAMLToJSON(data)
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, `{"1":"the int key value","name":"a string value","y":"some value"}`, string(d))
|
||||
}
|
||||
|
||||
data = append(data, yaml.MapItem{Key: true, Value: "the bool value"})
|
||||
d, err = YAMLToJSON(data)
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, d)
|
||||
|
||||
data = data[:len(data)-1]
|
||||
|
||||
tag := yaml.MapSlice{{Key: "name", Value: "tag name"}}
|
||||
data = append(data, yaml.MapItem{Key: "tag", Value: tag})
|
||||
|
||||
d, err = YAMLToJSON(data)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, `{"1":"the int key value","name":"a string value","y":"some value","tag":{"name":"tag name"}}`, string(d))
|
||||
|
||||
tag = yaml.MapSlice{{Key: true, Value: "bool tag name"}}
|
||||
data = append(data[:len(data)-1], yaml.MapItem{Key: "tag", Value: tag})
|
||||
|
||||
d, err = YAMLToJSON(data)
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, d)
|
||||
|
||||
var lst []interface{}
|
||||
lst = append(lst, "hello")
|
||||
|
||||
d, err = YAMLToJSON(lst)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []byte(`["hello"]`), []byte(d))
|
||||
|
||||
lst = append(lst, data)
|
||||
|
||||
d, err = YAMLToJSON(lst)
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, d)
|
||||
|
||||
// _, err := yamlToJSON(failJSONMarhal{})
|
||||
// assert.Error(t, err)
|
||||
|
||||
_, err = BytesToYAMLDoc([]byte("- name: hello\n"))
|
||||
assert.Error(t, err)
|
||||
|
||||
dd, err := BytesToYAMLDoc([]byte("description: 'object created'\n"))
|
||||
assert.NoError(t, err)
|
||||
|
||||
d, err = YAMLToJSON(dd)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, json.RawMessage(`{"description":"object created"}`), d)
|
||||
}
|
||||
|
||||
func TestLoadStrategy(t *testing.T) {
|
||||
|
||||
loader := func(p string) ([]byte, error) {
|
||||
return []byte(yamlPetStore), nil
|
||||
}
|
||||
remLoader := func(p string) ([]byte, error) {
|
||||
return []byte("not it"), nil
|
||||
}
|
||||
|
||||
ld := LoadStrategy("blah", loader, remLoader)
|
||||
b, _ := ld("")
|
||||
assert.Equal(t, []byte(yamlPetStore), b)
|
||||
|
||||
serv := httptest.NewServer(http.HandlerFunc(yamlPestoreServer))
|
||||
defer serv.Close()
|
||||
|
||||
s, err := YAMLDoc(serv.URL)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, s)
|
||||
|
||||
ts2 := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
rw.WriteHeader(http.StatusNotFound)
|
||||
rw.Write([]byte("\n"))
|
||||
}))
|
||||
defer ts2.Close()
|
||||
_, err = YAMLDoc(ts2.URL)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
var yamlPestoreServer = func(rw http.ResponseWriter, r *http.Request) {
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
rw.Write([]byte(yamlPetStore))
|
||||
}
|
||||
|
||||
func TestWithYKey(t *testing.T) {
|
||||
doc, err := BytesToYAMLDoc([]byte(withYKey))
|
||||
if assert.NoError(t, err) {
|
||||
_, err := YAMLToJSON(doc)
|
||||
if assert.Error(t, err) {
|
||||
doc, err := BytesToYAMLDoc([]byte(withQuotedYKey))
|
||||
if assert.NoError(t, err) {
|
||||
jsond, err := YAMLToJSON(doc)
|
||||
if assert.NoError(t, err) {
|
||||
var yt struct {
|
||||
Definitions struct {
|
||||
Viewbox struct {
|
||||
Properties struct {
|
||||
Y struct {
|
||||
Type string `json:"type"`
|
||||
} `json:"y"`
|
||||
} `json:"properties"`
|
||||
} `json:"viewbox"`
|
||||
} `json:"definitions"`
|
||||
}
|
||||
if assert.NoError(t, json.Unmarshal(jsond, &yt)) {
|
||||
assert.Equal(t, "integer", yt.Definitions.Viewbox.Properties.Y.Type)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
const withQuotedYKey = `consumes:
|
||||
- application/json
|
||||
definitions:
|
||||
viewBox:
|
||||
type: object
|
||||
properties:
|
||||
x:
|
||||
type: integer
|
||||
format: int16
|
||||
# y -> types don't match: expect map key string or int get: bool
|
||||
"y":
|
||||
type: integer
|
||||
format: int16
|
||||
width:
|
||||
type: integer
|
||||
format: int16
|
||||
height:
|
||||
type: integer
|
||||
format: int16
|
||||
info:
|
||||
description: Test RESTful APIs
|
||||
title: Test Server
|
||||
version: 1.0.0
|
||||
basePath: /api
|
||||
paths:
|
||||
/test:
|
||||
get:
|
||||
operationId: findAll
|
||||
parameters:
|
||||
- name: since
|
||||
in: query
|
||||
type: integer
|
||||
format: int64
|
||||
- name: limit
|
||||
in: query
|
||||
type: integer
|
||||
format: int32
|
||||
default: 20
|
||||
responses:
|
||||
200:
|
||||
description: Array[Trigger]
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/definitions/viewBox"
|
||||
produces:
|
||||
- application/json
|
||||
schemes:
|
||||
- https
|
||||
swagger: "2.0"
|
||||
`
|
||||
|
||||
const withYKey = `consumes:
|
||||
- application/json
|
||||
definitions:
|
||||
viewBox:
|
||||
type: object
|
||||
properties:
|
||||
x:
|
||||
type: integer
|
||||
format: int16
|
||||
# y -> types don't match: expect map key string or int get: bool
|
||||
y:
|
||||
type: integer
|
||||
format: int16
|
||||
width:
|
||||
type: integer
|
||||
format: int16
|
||||
height:
|
||||
type: integer
|
||||
format: int16
|
||||
info:
|
||||
description: Test RESTful APIs
|
||||
title: Test Server
|
||||
version: 1.0.0
|
||||
basePath: /api
|
||||
paths:
|
||||
/test:
|
||||
get:
|
||||
operationId: findAll
|
||||
parameters:
|
||||
- name: since
|
||||
in: query
|
||||
type: integer
|
||||
format: int64
|
||||
- name: limit
|
||||
in: query
|
||||
type: integer
|
||||
format: int32
|
||||
default: 20
|
||||
responses:
|
||||
200:
|
||||
description: Array[Trigger]
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/definitions/viewBox"
|
||||
produces:
|
||||
- application/json
|
||||
schemes:
|
||||
- https
|
||||
swagger: "2.0"
|
||||
`
|
||||
|
||||
const yamlPetStore = `swagger: '2.0'
|
||||
info:
|
||||
version: '1.0.0'
|
||||
title: Swagger Petstore
|
||||
description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification
|
||||
termsOfService: http://helloreverb.com/terms/
|
||||
contact:
|
||||
name: Swagger API team
|
||||
email: foo@example.com
|
||||
url: http://swagger.io
|
||||
license:
|
||||
name: MIT
|
||||
url: http://opensource.org/licenses/MIT
|
||||
host: petstore.swagger.wordnik.com
|
||||
basePath: /api
|
||||
schemes:
|
||||
- http
|
||||
consumes:
|
||||
- application/json
|
||||
produces:
|
||||
- application/json
|
||||
paths:
|
||||
/pets:
|
||||
get:
|
||||
description: Returns all pets from the system that the user has access to
|
||||
operationId: findPets
|
||||
produces:
|
||||
- application/json
|
||||
- application/xml
|
||||
- text/xml
|
||||
- text/html
|
||||
parameters:
|
||||
- name: tags
|
||||
in: query
|
||||
description: tags to filter by
|
||||
required: false
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
collectionFormat: csv
|
||||
- name: limit
|
||||
in: query
|
||||
description: maximum number of results to return
|
||||
required: false
|
||||
type: integer
|
||||
format: int32
|
||||
responses:
|
||||
'200':
|
||||
description: pet response
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/pet'
|
||||
default:
|
||||
description: unexpected error
|
||||
schema:
|
||||
$ref: '#/definitions/errorModel'
|
||||
post:
|
||||
description: Creates a new pet in the store. Duplicates are allowed
|
||||
operationId: addPet
|
||||
produces:
|
||||
- application/json
|
||||
parameters:
|
||||
- name: pet
|
||||
in: body
|
||||
description: Pet to add to the store
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/newPet'
|
||||
responses:
|
||||
'200':
|
||||
description: pet response
|
||||
schema:
|
||||
$ref: '#/definitions/pet'
|
||||
default:
|
||||
description: unexpected error
|
||||
schema:
|
||||
$ref: '#/definitions/errorModel'
|
||||
/pets/{id}:
|
||||
get:
|
||||
description: Returns a user based on a single ID, if the user does not have access to the pet
|
||||
operationId: findPetById
|
||||
produces:
|
||||
- application/json
|
||||
- application/xml
|
||||
- text/xml
|
||||
- text/html
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
description: ID of pet to fetch
|
||||
required: true
|
||||
type: integer
|
||||
format: int64
|
||||
responses:
|
||||
'200':
|
||||
description: pet response
|
||||
schema:
|
||||
$ref: '#/definitions/pet'
|
||||
default:
|
||||
description: unexpected error
|
||||
schema:
|
||||
$ref: '#/definitions/errorModel'
|
||||
delete:
|
||||
description: deletes a single pet based on the ID supplied
|
||||
operationId: deletePet
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
description: ID of pet to delete
|
||||
required: true
|
||||
type: integer
|
||||
format: int64
|
||||
responses:
|
||||
'204':
|
||||
description: pet deleted
|
||||
default:
|
||||
description: unexpected error
|
||||
schema:
|
||||
$ref: '#/definitions/errorModel'
|
||||
definitions:
|
||||
pet:
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
name:
|
||||
type: string
|
||||
tag:
|
||||
type: string
|
||||
newPet:
|
||||
allOf:
|
||||
- $ref: '#/definitions/pet'
|
||||
- required:
|
||||
- name
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
name:
|
||||
type: string
|
||||
errorModel:
|
||||
required:
|
||||
- code
|
||||
- message
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
format: int32
|
||||
message:
|
||||
type: string
|
||||
`
|
||||
Reference in New Issue
Block a user