Comments (9)
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.
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.
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.
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.
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.
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.
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.
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.
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)
- Request for blocking calls. HOT 2
- Loading input failed: : exec: "C:\\[...]\\Temp\\gomock_reflect_569018487\\prog.bin": file does not exist HOT 8
- Generated import conflict with reserved words HOT 2
- Allow for loose mocks HOT 1
- GoMock Embedded Interfaces Don't Keep Package Name HOT 2
- False positives when using Times(0) on Call HOT 2
- mockgen can't generate interfaces that embed them from a separate file
- gomock creates mocks that fail golint HOT 2
- mockgen cannot mock interfaces with embedded interfaces HOT 12
- Provide a decent example use HOT 3
- gomock fails to generate functions with closure as arguments HOT 4
- Consult $GOPATH for auxilliary interface definitions HOT 3
- Output file created even on error HOT 4
- Mockgen produces incorrect output HOT 2
- Mockgen generates files with incorrect packages HOT 6
- mockgen creates unusable mock in some circumstances. HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gomock.