Skip to content

A toolkit with common assertions and mocks that plays nicely with the standard library

License

Notifications You must be signed in to change notification settings

go-openapi/testify

 
 

Testify Build Status codecov

Slack Status license Go Reference Go Report Card

Testify - Thou Shalt Write Tests

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.

Why this fork?

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.

  1. 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).

  1. We want to remove most of the chrome that has been added over the years

The go-openapi libraries and the go-swagger project make a rather limited use of the vast API provided by testify.

With this first version of the fork, we have removed mocks and suite, 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.

  1. 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.

What's next with this project?

  1. The first release comes with zero dependencies and an unstable API (see below our use case)
  2. This project is going to be injected as the main and sole test dependency of the go-openapi libraries and the go-swagger tool
  3. Valuable pending pull requests from the original project could be merged (e.g. JSONEqBytes) or transformed as "enable" modules (e.g. colorized output)
  4. Unclear assertions may be provided an alternative verb (e.g. InDelta)
  5. 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.

What won't come anytime soon

  • 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

Usage at go-openapi

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

Installation

To use this package in your projects:

    go get github.com/go-openapi/testify/v2

Get started

Features include:

Examples

See [the original README)(./original.md)

Licensing

See the license NOTICE, which recalls the licensing terms of all the pieces of software distributed with this fork, including internalized libraries.

PRs from the original repo

The following proposed contributions to the original repo have been merged or incorporated with some adaptations into this fork:

Other noticeable contributions, not merged

These would probably need some rework/fix or adaptation, but the proposed idea is worthwile, IMHO.

Contributing

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.

About

A toolkit with common assertions and mocks that plays nicely with the standard library

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.6%
  • Shell 0.4%