Giter Site home page Giter Site logo

Mocking Variadic Functions about testify HOT 8 CLOSED

stretchr avatar stretchr commented on May 22, 2024
Mocking Variadic Functions

from testify.

Comments (8)

robdaemon avatar robdaemon commented on May 22, 2024

I've been looking at this - the issue happens around here: https://github.com/stretchr/testify/blob/master/assert/assertions.go#L40

Specifically, you end up with an expected of: []interface {}(nil) and an actual of []interface {}{}

I'll look and see if I can figure out why, but my initial instinct is that this is a Go issue.

I did find a workaround, which seems particularly nasty:

mockRedis.On("Send", "MULTI", reflect.Zero(reflect.TypeOf([]interface{}{})).Interface()).Return(nil)

from testify.

mveytsman avatar mveytsman commented on May 22, 2024

Thanks for looking into this @robdaemon, I hope you figure it out. And yeah, that's a nasty workaround :)

from testify.

vladimirvivien avatar vladimirvivien commented on May 22, 2024

Any update on this possible variadic issue ?

from testify.

ernesto-jimenez avatar ernesto-jimenez commented on May 22, 2024

@vladimirvivien I'll look into it.

In the mean time, if the actual value is not important, a posible workaround would be using AnythingOfType.

An example working around the fact that we cannot compare anonymous funcs: #159 (comment)

from testify.

ernesto-jimenez avatar ernesto-jimenez commented on May 22, 2024

Everything seems to work OK.

I've added some tests in PR #175

@robdaemon, @robdaemon:

Here's the solution:

var expected []interface{}
mockRedis.On("Send", "MULTI", expected).Return(nil)

No need for the reflect workaround.

Do you have any other use cases failing? Otherwise we'll just close this issue

Best,
Ernesto

from testify.

ernesto-jimenez avatar ernesto-jimenez commented on May 22, 2024

@mveytsman @robdaemon @vladimirvivien any comments? or can I close the issue? :)

from testify.

vladimirvivien avatar vladimirvivien commented on May 22, 2024

@ernesto-jimenez please close, I got around using the Any type in my assertion. Thanks for looking into this.

from testify.

ernesto-jimenez avatar ernesto-jimenez commented on May 22, 2024

closing, thanks!

from testify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.