stretchr/testify

Allow dynamic returns based on arguments

Open

#350 geöffnet am 15. Sept. 2016

Auf GitHub ansehen
 (35 Kommentare) (59 Reaktionen) (0 zugewiesene Personen)Go (1.704 Forks)batch import
help wanted

Repository-Metriken

Stars
 (25.958 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 15h) (2 gemergte PRs in 30 T)

Beschreibung

C# Moq allows to return data based on call arguments.

testify/mock don't. It's possible to do using Run, but it's a big mess of code.

It would be great to have something like this:

myMock.On("Load", mock.AnythingOfType("string")).ReturnFn(func (token string) (*MyObj, error) {
    if isValid(token) {
        return someStuff(), nil
    } else {
        return nil, errors.New("Oh!")
    }
})

I can send a PR if someone like this idea.

Contributor Guide