Giter Club home page Giter Club logo

gomock's People

Contributors

awreece avatar dsymonds avatar jacobsa avatar snarfed avatar

Watchers

 avatar

gomock's Issues

Provide a decent example use

Can we get a good example in the repository?  The code in the sample/ dir 
doesn't compile properly:

1001)~ % cd Software/go/src/pkg/gomock.googlecode.com/hg/sample 
1002)hg/sample % mockgen --source user.go
2011/09/30 20:18:38 Can't deduce package for a *ast.ChanType
1003)

I'm trying to figure out how to get this to work with my own code, but without 
any real working example, the sparse documentation makes using this package 
quite a challenge.

Original issue reported on code.google.com by seanerussell on 1 Oct 2011 at 12:29

False positives when using Times(0) on Call

We're using Times(0) to expect a call _NOT_ to be made.

To reproduce the problem, create a mock and a method. Test some code and expect 
a method not to be called within that code.
We used a call similar like this: mock.EXPECT().myMethod(Any()).Times(0)

I expected to get an error because an expectation didn't match but instead I 
don't see anything. And all the test are good/green so we get a false positive.

We're using the master branch at SHA: f465e13c1a71273ab234f1e40a327556b6518a27

We've been looking around and we suspect the exhausted should be check in 
controller finish aswel like you do for satisfied.

if !call.satisfied() {
    ctrl.t.Errorf("missing call(s) to %v", call)
    failures = true
} else if call.exhausted() {
    ctrl.t.Errorf("too many call(s) to %v", call)
    failures = true
}

This doesn't solve the problem completely though. You could also say Times(0) 
isn't supported and make the Times method more defensive and don't accept 0 as 
a valid parameter. But we would like to solve it instead :D

Original issue reported on code.google.com by [email protected] on 1 May 2014 at 8:35

Consult $GOPATH for auxilliary interface definitions

Currently, it is necessary to manually specify all dependencies when running 
mockgen on a file. For example, running `mockgen --source=temp.go` on the 
attached file produces the following error:
2011/10/11 02:40:03 Don't have any auxilliary interfaces for package "os"

It would be nice if it could check $GOPATH (or at least $GOROOT/src) for the 
interfaces.

Original issue reported on code.google.com by [email protected] on 11 Oct 2011 at 6:42

Attachments:

Output file created even on error

What steps will reproduce the problem?
run mockgen --source=temp.go --aux_files=flag=/invalid/path/here 
--destination=mock_temp.go

What is the expected output? What do you see instead?
Expected output is an error and no file created. Instead, a file is created.

Original issue reported on code.google.com by [email protected] on 11 Oct 2011 at 6:48

Attachments:

Not an issue,but a question:How to mock a interface and pass it by pointer?

Scenario is : caller pass mock to---->Method_0(mock),but Method_0(..) didn't 
call mock's method,and passed mock to------> Method_1(mock) 
,finally,mock.ToVerify() gets called in Method_1().Because Method_0 will COPY 
mock then pass new copied mock to Method_1(),actual method call will happend in 
this copy not the original,but verification still binds on original mock.So it 
will fail.So question is How to mock a  interface and pass it by pointer?

   In my current use case,http.ResponseWriter must be mocked ,but I think question should be applied to other similar use cases.

//test
func TestXXX(t *testing.T) {
       mock:=......stuff to create mock......

       //action
       p.Method_0(mock)

       //verify
       mock.EXPECT().ToVerify()
}

//pakage p
package p

Method_0(mock http.ReponseWriter){
    //created copy and pass copy to Method_1
     Method_1(mock)
}

Method_1(mock http.ReponseWriter){
      //mock method gets called here
     mock.Write(...) 
}

Original issue reported on code.google.com by [email protected] on 5 Sep 2012 at 5:53

Mockgen generates files with incorrect packages

When mockgen creates a file in a different package than the source file (ie the 
default case, in package mock_default_package), the original package and types 
are not imported.

See attached files:

package test

type Foo interface {
    String() string
}

type Bar interface {
    DoSomething(f Foo)
}


the mocked Bar (in package mock_test) has the method 
func (m *MockBar) DoSomething(f Foo)

Where Foo should instead be test.Foo

Original issue reported on code.google.com by [email protected] on 31 Oct 2011 at 9:52

Attachments:

Allow for loose mocks

Loose mocks, i.e. mocks that simply return defaults for unexpected methods are 
fairly common in other mock frameworks. I experimentally added this to gomock 
and it seems to work. By allowing this I can skip the following call in my test:

storer.EXPECT().Allocate(gomock.Any(), gomock.Any()).AnyTimes()

In this case the storer is a mocked dependency of my SUT which I don't care 
about in this particular test. The default of it returning nil for the single 
error return is fine.

Original issue reported on code.google.com by [email protected] on 4 Mar 2014 at 9:24

mockgen creates unusable mock in some circumstances.

What steps will reproduce the problem?
1. Acquire https://github.com/fluffle/goirc/blob/master/event/registry.go
2. Run mockgen -source registry.go -destination mock_registry.go -package event

What is the expected output? What do you see instead?

There are two problems with the generated mock, both related to variadics:

1. Line 35, an errant comma is produced before the single variadic argument.

2. Lines 101 and 109, the variadic is of type ...interface{} not ...string.

The former should be an easy fix. The latter causes problems with 
reflect.DeepEqual as the types differ between the argument saved with the 
recorded call and the argument saved with the expected call.

[]interface{}{[]interface{}{"arg1", "arg2"}} != []interface{}{[]string{"arg1", 
"arg2"}}

What version of the product are you using? On what operating system?

Latest hg tip.

Please provide any additional information below.

http://www.pl0rt.org/~alex/mock_registry.patch

In a related note, reflect.DeepEqual also caused some confusion for me when 
comparing a character pulled from a string with indexing (string[1]) and a 
character 'c'. The latter is an int naturally, but is often coerced to a byte 
when doing string[0] == 'c' in code. Unfortunately, if your mock function is 
e.g. Warn(fmt string, args ...interface{}), and you do something like:

switch c := string[0]; c {
  default:
    Warn("Unknown char %c", c)
}

Mocking this correctly requires object.EXPECT().Warn("Unknown char %c", 
byte('c'))

Original issue reported on code.google.com by [email protected] on 13 Nov 2011 at 1:28

gomock creates mocks that fail golint

What steps will reproduce the problem?
1. run mockgen 
2. run golint
3. get errors

What is the expected output? What do you see instead?

I see the error listed below, I assumed gomock would at least put comment 
placeholders in the autogen'd code

"mock_repository.go:94:1: exported method MockFooRepository.PutBar should have 
comment or be unexported"

What version of the product are you using? On what operating system?
using golang 1.4 on osx

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 19 Feb 2015 at 6:43

Loading input failed: : exec: "C:\\[...]\\Temp\\gomock_reflect_569018487\\prog.bin": file does not exist

C:\Users\Bruno>mockgen net/http Client
2013/04/01 16:35:05 Loading input failed: exec: 
"C:\\Users\\Bruno\\AppData\\Local\\Temp\\gomock_reflect_674068563\\prog.bin": 
file does not exist

What steps will reproduce the problem?
1. mockgen net/http Client

What is the expected output? What do you see instead?
I have no idea since I'm using this tool for the first time. I wish to mock 
http.PostForm(). I saw the syntax with mockgen -h

What version of the product are you using? On what operating system?
go version go1.0.3
Windows 8 (64 bits)
Latest version of both gomock and mockgen

Original issue reported on code.google.com by [email protected] on 1 Apr 2013 at 8:35

Generated import conflict with reserved words

What steps will reproduce the problem?
1. Create an import that must be aliased before it can be used, like foo/case.go
2. import c "foo/case"
3. Generate a mock for it.

What is the expected output? What do you see instead?
The generated mock includes import case "foo/case", which causes syntax error: 
unexpected case.
The expected output would be a mock including a non-reserved word, like import 
case0 ...

Original issue reported on code.google.com by [email protected] on 20 Feb 2014 at 1:44

gomock fails to generate functions with closure as arguments

gomock will fail on the following interface:

type Bad interface {
    DoSomething(func() string)
}

with the error: "2011/10/09 17:05:54 Can't deduce package for a *ast.FuncType"

It seems like "packagesOfType()" on line 228 cannot handle function types.

Original issue reported on code.google.com by [email protected] on 9 Oct 2011 at 9:08

Request for blocking calls.

I would like to add support for mocking a blocking call.

Example syntax could be:

mockSocket.EXPECT().Read().Block()

signalChan := make(chan bool)
mockSocket.EXPECT().Read().BlockUntil(signalChan).Return([]{0}, nil)

Original issue reported on code.google.com by [email protected] on 12 Sep 2011 at 6:48

Mockgen produces incorrect output

What steps will reproduce the problem?
Mockgen produces invalid output on the attached file.

What is the expected output? What do you see instead?
The function on line 64 of the produced output has incorrect arguments.

mockgen --source=log_outer.go --destination=mock_log_outer.go --package=golog

GOROOT/src/pkg/gomock.googlecode.com/hg$ hg identify
aca9ae018061 go.r60

GOROOT$ hg identify
9c743824e7d6+ tip
(I'm working on a patch to the json package, the only files I have modified are 
in the json folder)

Ubuntu 10.04 Intel x86

Original issue reported on code.google.com by [email protected] on 11 Oct 2011 at 7:11

Attachments:

mockgen cannot mock interfaces with embedded interfaces

When running mockgen on the net.go file part of the standard library, I receive 
an unpleasant error. After some exploration, I determined that it fails on the 
net.Error interface (mockgen successfully runs on the attached file)

areece@areece-laptop:~$ mockgen --source=go/src/pkg/net/net.go 
panic: interface conversion: ast.Expr is *ast.SelectorExpr, not *ast.FuncType

goroutine 1 [running]:
main.(*generator).ScanImports(0x5ccebc, 0x1870e8c0, 0x0)
    /home/areece/go/src/pkg/gomock.googlecode.com/hg/mockgen/mockgen.go:237 +0x734
main.main()
    /home/areece/go/src/pkg/gomock.googlecode.com/hg/mockgen/mockgen.go:82 +0x4ca

goroutine 2 [chan send]:
main._func_001(0x18700db8, 0x18700dc8, 0x0)
    /home/areece/go/src/pkg/gomock.googlecode.com/hg/mockgen/mockgen.go:146 +0x2da
created by main.iterInterfaces
    /home/areece/go/src/pkg/gomock.googlecode.com/hg/mockgen/mockgen.go:150 +0xa8


What version of the product are you using? On what operating system?
Ubuntu 10.04

areece@areece-laptop:~/go$ hg summary
parent: 9652:c9da4512c385 tip
 weekly.html: remove note about exp/template -> template move.
branch: default
commit: (clean)
update: (current)

Original issue reported on code.google.com by [email protected] on 15 Sep 2011 at 6:04

Attachments:

GoMock Embedded Interfaces Don't Keep Package Name

I saw a previous issue relating to GoMock Embedded Interfaces, but it was 
closed out.

If I have an interface that has a function that returns another Interface, 
gomock doesn't generate the files with the correct package names.

Original issue reported on code.google.com by [email protected] on 9 Apr 2014 at 12:05

mockgen can't generate interfaces that embed them from a separate file

While mockgen can generate a mock for an embedded interface, its limited that 
the interface being embedded has to be present in the same file. If the 
interface to embed is in the same package, but not the same file gomock is 
unable to locate it and will fail with "unknown embedded interface".

Original issue reported on code.google.com by [email protected] on 12 Dec 2014 at 9:35

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.