Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testing.TB to mock.Mock in constructors #455

Merged
merged 3 commits into from Apr 21, 2022

Conversation

Gevrai
Copy link

@Gevrai Gevrai commented Apr 20, 2022

Description

Following the recent addition of constructors for mocks by @grongor in #406, this PR is a suggestion to also register the testing.TB interface on mock.Mock.

This is a feature in testify's mock.Mock that makes it so that whenever a mock is not matched, the whole suite does not panic, but instead makes the test fails. It is in some way breaking in the sense that the behaviour that some might be used to (ie. stop the world panic) will not be the same, but while we added a cleanup function I think this is desirable.

This is of course debatable 馃槂

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Version of Golang used when building/testing:

  • 1.11
  • 1.12
  • 1.13
  • 1.14
  • 1.15
  • 1.16
  • 1.17
  • 1.18

How Has This Been Tested?

Added generation to related files and tested locally with go test ./...

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@codecov-commenter
Copy link

codecov-commenter commented Apr 20, 2022

Codecov Report

Merging #455 (c7e7f4f) into master (aad3571) will decrease coverage by 0.03%.
The diff coverage is 66.66%.

@@            Coverage Diff             @@
##           master     #455      +/-   ##
==========================================
- Coverage   70.76%   70.73%   -0.04%     
==========================================
  Files           7        7              
  Lines        1293     1295       +2     
==========================================
+ Hits          915      916       +1     
- Misses        325      326       +1     
  Partials       53       53              
Impacted Files Coverage 螖
pkg/fixtures/mocks/expecter.go 83.33% <0.00%> (-0.67%) 猬囷笍
pkg/generator.go 90.83% <100.00%> (+0.01%) 猬嗭笍

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update aad3571...c7e7f4f. Read the comment docs.

Copy link
Contributor

@grongor grongor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about this functionality before...nice one. LGTM.

Copy link
Contributor

@LandonTClipp LandonTClipp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this technically wouldn't be a breaking change so long as some test in a suite would fail. I like this change, looks good. Thatnks!

README.md Outdated
func NewSendFunc(t testing.TB) *SendFunc {
mock := &SendFunc{}
mock.Mock.Test(t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting issue here (tab vs space), could you correct the line before this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

@LandonTClipp LandonTClipp merged commit 8174e46 into vektra:master Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants