Closed GoogleCodeExporter closed 9 years ago
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 dsymo...@golang.org
on 5 Sep 2012 at 7:45
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 Alexande...@gmail.com
on 5 Sep 2012 at 9:24
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 dsymo...@golang.org
on 5 Sep 2012 at 1:02
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 Alexande...@gmail.com
on 11 Sep 2012 at 5:14
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 dsymo...@golang.org
on 11 Sep 2012 at 5:16
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 Alexande...@gmail.com
on 11 Sep 2012 at 5:45
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 dsymo...@golang.org
on 11 Sep 2012 at 5:48
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 Alexande...@gmail.com
on 12 Sep 2012 at 5:52
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 dsymo...@golang.org
on 12 Sep 2012 at 5:55
Original issue reported on code.google.com by
Alexande...@gmail.com
on 5 Sep 2012 at 5:53