GithubHelp home page GithubHelp logo

zagrev / go-mock-gen-failure Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 1.25 MB

This project demonstrates an error using mockgen with Go 1.12.9, where changing an interface after the tests already use the mock causes mockgen to fail because the tests don't compile

Go 100.00%

go-mock-gen-failure's Introduction

Go mockgen generate mock failure

This project demonstrates the failure of mockgen when re-generating the mocks for a changed interface. When the unit tests were written and the mocks originally gneerated, everything works as expected. But once the mocks exists, and the interface changes, then mockgen fails to generate new mocks because the tests fail to compile.

You can check this in this project using the tags "pre-change", "post-change", and "post-remove". I use the command mockgen -source some-interface.go -package main -destination some-interface_mock.go to generate the mock.

At the pre-change tag, the code compiles and runs the 1 unit test.

At the post-change tag, the code fails to compile, and mockgen fails to generate new mock code.

go-mock-gen-failure]$ go build
go-mock-gen-failure]$ 
go-mock-gen-failure]$ mockgen -source some-interface.go -package main -destination some-interface_mock.go
go-mock-gen-failure/some_test.go:19:34: too many arguments
go-mock-gen-failure/some_test.go:24:34: too many arguments
2019/11/11 21:59:05 Loading input failed: loading package failed
go-mock-gen-failure]$

When I remove the mock file to regenerate it...

go-mock-gen-failure]$ rm *_mock.go
go-mock-gen-failure]$
go-mock-gen-failure]$ mockgen -source some-interface.go -package main -destination some-interface_mock.go
go-mock-gen-failure/some_test.go:14:13: undeclared name: NewMockSome
2019/11/11 22:03:51 Loading input failed: loading package failed
go-mock-gen-failure]$

go-mock-gen-failure's People

Contributors

ustef avatar

Watchers

 avatar  avatar

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.