A golang set of packages that provide tools for testifying that your code will behave as you intend.
This is the go-openapi fork of the great testify package.
From the maintainers of testify
, it looks like a v2 is coming up, but they'll do it at their own pace.
We like all the principles they put forward to build this v2. See discussion about v2
However, at go-openapi
we would like to address the well-known issues in testify
with different priorities.
- We want first to remove all external dependencies.
For all our libraries and generated test code we don't want test dependencies to drill farther than
import github.com/go-openapi/testify/v2
, but on some specific (and controlled) occasions.In this fork, all external stuff is either internalized (
go-spew
,difflib
), removed (mocks
,suite
,http
) or specifically enabled by importing a specific module (github.com/go-openapi/testify/v2/enable/yaml
).
- We want to remove most of the chrome that has been added over the years
The
go-openapi
libraries and thego-swagger
project make a rather limited use of the vast API provided bytestify
.With this first version of the fork, we have removed
mocks
andsuite
, which we don't use. They might be added later on, with better controlled dependencies.In the forthcoming maintenances of this fork, much of the "chrome" or "ambiguous" API will be pared down. There is no commitment yet on the stability of the API.
Chrome would be added later: we have the "enable" packages just for that.
- We hope that this endeavour will help the original project with a live-drill of what a v2 could look like. We are always happy to discuss with people who face the same problems as we do: avoid breaking changes, APIs that became bloated over a decade or so, uncontrolled dependencies, conflicting demands from users etc.
- The first release comes with zero dependencies and an unstable API (see below our use case)
- This project is going to be injected as the main and sole test dependency of the
go-openapi
libraries and thego-swagger
tool - Valuable pending pull requests from the original project could be merged (e.g.
JSONEqBytes
) or transformed as "enable" modules (e.g. colorized output) - Unclear assertions may be provided an alternative verb (e.g.
InDelta
) - Since we have leveled the go requirements to the rest of the go-openapi (currently go1.24) there is quite a bit of relinting lying ahead.
- mocks: we use mockery and prefer the simpler
matryer
mocking-style. testify-style mocks are thus not going to be supported anytime soon. - extra convoluted stuff in the like of
InDeltaSlice
At this moment, we have identified the following usage in our tools. This API shall remain stable. Currently, there are no guarantees about the entry points not in this list.
TODO: extend the list with usage by go-swagger.
Condition
Contains,Containsf
Empty,Emptyf
Equal,Equalf
EqualError,EqualErrorf
EqualValues,EqualValuesf
Error,Errorf
ErrorContains
ErrorIs
Fail,Failf
FailNow
False,Falsef
Greater
Implements
InDelta,InDeltaf
IsType,IsTypef
JSONEq,JSONEqf
Len,Lenf
Nil,Nilf
NoError,NoErrorf
NotContains,NotContainsf
NotEmpty,NotEmptyf
NotEqual
NotNil,NotNilf
NotPanics
NotZeroG
Panics,PanicsWithValue
Subset
True,Truef
YAMLEq,YAMLEqf
Zero,Zerof
To use this package in your projects:
go get github.com/go-openapi/testify/v2
Features include:
- Easy assertions
MockingremovedTesting suite interfaces and functionsremoved
See [the original README)(./original.md)
See the license NOTICE, which recalls the licensing terms of all the pieces of software distributed with this fork, including internalized libraries.
- go-openapi/testify SPDX-License-Identifier: Apache-2.0
- stretchr/testify SPDX-License-Identifier: MIT
- github.com/davecgh/go-spew SPDX-License-Identifier: ISC
- github.com/pmezard/go-difflib SPDX-License-Identifier: MIT-like
- imports SPDX-License-Identifier: MIT
The following proposed contributions to the original repo have been merged or incorporated with some adaptations into this fork:
- github.com/stretchr#1513
- github.com/stretchr#1772
- github.com/stretchr#1797
- github.com/stretchr#1356
These would probably need some rework/fix or adaptation, but the proposed idea is worthwile, IMHO.
- github.com/stretchr#1460 (ci)
- github.com/stretchr#1467 (colorized output)
- github.com/stretchr#1480 (colorized output)
- github.com/stretchr/testify/pull#1232 (colorized output)
- github.com/stretchr#994 (colorized output)
- github.com/stretchr#1495 (bug fix)
- github.com/stretchr#1223 (layout bug fix)
Please feel free to submit issues, fork the repository and send pull requests!
When submitting an issue, we ask that you please include a complete test function that demonstrates the issue. Extra credit for those using Testify to write the test code that demonstrates it.
Code generation is used. Run go generate ./...
to update generated files.
See also the CONTRIBUTING guidelines.