stretchr / testify

A toolkit with common assertions and mocks that plays nicely with the standard library
MIT License
23.53k stars 1.6k forks source link

mock: in order mock calls #1637

Closed ReyOrtiz closed 1 month ago

ReyOrtiz commented 2 months ago

Summary

Add helper method to declare the order of the mock calls.

Changes

Motivation

This is probably the only feature I miss from gomock.InOrder(), it is more intuitive and cleaner to declare the order of the mock calls. Probably most cases can be satisfied with this method.

InOrder(
    mockedService1.On("TheExampleMethod", 1, 2, 3).Return(4, nil),
    mockedService2.On("TheExampleMethod2", true).Return(),
    mockedService3.On("TheExampleMethod3", "abc", 3).Return(false, nil),
)

Related issues

Closes #1639

ReyOrtiz commented 1 month ago

unit test added

ReyOrtiz commented 1 month ago

Good comments, thanks! Requested changes applied.

jybp commented 1 month ago

Ah you beat me to it, thanks! And missed that existing PR

ReyOrtiz commented 1 month ago

Hello, any ETA on merging this PR?

brackendawson commented 1 month ago

Thanks @ReyOrtiz. This can be consumed now by gomock expats with: go get github.com/stretchr/testify@master. Once testify v1.10 is released it can be consumed as per the README. I'll have a look at drafting a release soon.

ReyOrtiz commented 1 month ago

Thanks @brackendawson for all the help! 🙏