Giter Club home page Giter Club logo

Comments (9)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 26, 2024
Your question doesn't make sense. The mock you create is a concrete type of the 
form *T, and *T implements the mocked interface. You are not passing a copy of 
the object when you use it as an interface value.

Original comment by [email protected] on 5 Sep 2012 at 7:45

  • Changed state: Invalid
  • Added labels: ****
  • Removed labels: ****

from gomock.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 26, 2024
What do you mean?
I ran this command line to generate,and want to get a mock of 
http.ResponseWriter:
---------------------------------------------------------------
mockgen --source go/src/pkg/net/http/server.go -> 
/home/alex/IdeaProjects/AWS/src/activity/mock_server.go
---------------------------------------------------------------

Original comment by [email protected] on 5 Sep 2012 at 9:24

  • Added labels: ****
  • Removed labels: ****

from gomock.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 26, 2024
Look in mock_server.go. There's a NewMockResponseWriter that returns
*MockResponseWriter, which satisfies the http.ResponseWriter
interface. You pass the *MockResponseWriter to the relevant
function/method.

Original comment by [email protected] on 5 Sep 2012 at 1:02

  • Added labels: ****
  • Removed labels: ****

from gomock.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 26, 2024
I tried it,got an error:
cannot use responseWriterMock (type *MockResponseWriter) as type 
*http.ResponseWriter in function argument:
*http.ResponseWriter is pointer to interface, not interface

Original comment by [email protected] on 11 Sep 2012 at 5:14

  • Added labels: ****
  • Removed labels: ****

from gomock.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 26, 2024
Yeah? It's telling you what you're doing wrong: your code should be
taking an http.ResponseWriter, not a pointer to it.

Original comment by [email protected] on 11 Sep 2012 at 5:16

  • Added labels: ****
  • Removed labels: ****

from gomock.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 26, 2024
I come from java,so I can't make sure whether I have understood it 
correctly:during passing an interface,a copy will be made,and then all 
operations won't happened in the original but the copy,so verification will 
fail,right?:

func m_0(wr *http.ResponseWriter){
//here, a copy of wr will be passed into m_1,if change the signature of m_1 to
// m_1(wr http.ResponseWriter),all verification will fail,right?
     m_1(wr)
}

func m_1(wr *http.ResponseWriter){
    (*wr).Write(..)
}

Original comment by [email protected] on 11 Sep 2012 at 5:45

  • Added labels: ****
  • Removed labels: ****

from gomock.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 26, 2024
I think you need to go learn about interfaces before trying to use
gomock. Perhaps start here:
http://golang.org/doc/effective_go.html#interfaces_and_types

Original comment by [email protected] on 11 Sep 2012 at 5:48

  • Added labels: ****
  • Removed labels: ****

from gomock.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 26, 2024
I still can't solve this problem,would you please give a more detailed 
explanation?I want to verify wr.Write(..) do get invoked as following?

func m_0(wr *http.ResponseWriter){
     m_1(wr)
}

func m_1(wr *http.ResponseWriter){
    (*wr).Write(..)
}

Original comment by [email protected] on 12 Sep 2012 at 5:52

  • Added labels: ****
  • Removed labels: ****

from gomock.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 26, 2024
Like I said back in #5, you should not be using pointers to interfaces.

This isn't GoMock specific. Please take further questions to the golang-nuts 
mailing list.

Original comment by [email protected] on 12 Sep 2012 at 5:55

  • Added labels: ****
  • Removed labels: ****

from gomock.

Related Issues (17)

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.