Code Monkey home page Code Monkey logo

gomockhandler's Introduction

gomockhandler's People

Contributors

0tarof avatar fsmiamoto avatar kno3a87 avatar riita10069 avatar s4s7 avatar sanposhiho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gomockhandler's Issues

Eliminate the need to install mockgen

Let's eliminate the need to install mockgen.


We currently require users to install it. But, unexpected behaviors may occur due to differences in mockgen behavior depending on which mockgen the user has installed.
Ideally, we should generate mocks without using user-installed mockgen and we can achieve that if we can import mockgen.


But currently, almost all logic of mockgen cannot be imported, because it is placed in main package.
So, I propose to fork golang/mock, add changes to make it importable, and use the fork to import mockgen.

And, I raised the issue for golang/mock.
golang/mock#609

add -f flag

In Source mode, skip generation if the source file is not changed.

-f flag will not skip the generation of mocks.

Format json config

To make it easier to read json.
(In the future, it will not be necessary for users to look at the json directly.)

configuration file is not readable

Now, we support configuration gomockhandler.json.

And to add new mock on config, users have to execute cmd like this, and config for new mock will be added on gomockhandler.json.
gomockhandler -config=/path/to/gomockhandler.json -source=foo.go -destination=./mock/ [other mockgen options]

But, PR reviewers cannot see what command will be registered, and it makes PR review a little hard.

So, I want to add new optional configuration file or add information on config file to resolve this.

The checksum value of the tmp file and the gomockhandler.json got different When running the check command.

Version

Actual behavior

Despite the mock being up to date, the gomockhandler -config=./gomockhandler.json check command reports a different checksum value, leading to the determination that it is not the latest version.

[ERROR] mock is not up to date. destination: usecases/mock/xxx.go

Expected behavior

gomockhandler -config=./gomockhandler.json check command works correctly.

Why this issue occurred

uber-go/mock@2c718f2 was merged and is affecting gomockhandler, causing the check command to not work correctly.

Detail

The checksum values differ because the file paths for the destination specified in the comments within code A and code B are different.

code A : generated code by go.uber.org/mock/mockgen

// Code generated by MockGen. DO NOT EDIT.
// Source: github.com/org/repo/api/usecases (interfaces: xxx)
//
// Generated by this command:
//
//      mockgen -destination=usecases/mock/xxx.go -package=usecases_mock github.com/org/repo/api/usecases xxx
//

code B : tmp file code to calculate checksum in this line

// Code generated by MockGen. DO NOT EDIT.
// Source: github.com/org/repo/api/usecases (interfaces: xxx)
//
// Generated by this command:
//
//      mockgen -destination=usecases/mock/tmp_xxx.go -package=usecases_mock github.com/org/repo/api/usecases xxx
//

the order on generated configuration is randomly changed

Currently if we do gomockhandler mockgen order of content randomly changed, although there is no changes.
For Example:

// before
{
	"mocks": {
		"a_mock.go": {
			"checksum": "xxxxxxxxxxx",
			"source_checksum": "aaaaaaaaaaaaa",
			"mode": "SOURCE_MODE",
			"source_mode_runner": {
				"source": "a.go",
				"destination": "a_mock.go",
				"package": "main"
			}
		},
		"b_mock.go": {
			"checksum": "yyyyyyyyyyyy",
			"source_checksum": "bbbbbbbbbbb",
			"mode": "SOURCE_MODE",
			"source_mode_runner": {
				"source": "b.go",
				"destination": "b_mock.go",
				"package": "main"
			}
		}
}
// after
{
	"mocks": {
		"b_mock.go": {
			"checksum": "yyyyyyyyyyyy",
			"source_checksum": "bbbbbbbbbbb",
			"mode": "SOURCE_MODE",
			"source_mode_runner": {
				"source": "b.go",
				"destination": "b_mock.go",
				"package": "main"
			}
		},
		"a_mock.go": {
			"checksum": "xxxxxxxxxxx",
			"source_checksum": "aaaaaaaaaaaaa",
			"mode": "SOURCE_MODE",
			"source_mode_runner": {
				"source": "a.go",
				"destination": "a_mock.go",
				"package": "main"
			}
		}
}

This behavior becomes some noise when we manage config file by git.
I recommend those contents to be dictionary order to avoid this problem.

I think the part below leads this phenomenon.

for v2Name, v2Value := range in.Mocks {

Thank you.

Specify excluded path(s)

Being able to specify paths ignored by gomockhandler could be useful.

For example, one of my projects has a vendor folder where code from an external repository is being stored. In that folder, there are mock files. Those are not managed by gomockhandler and therefore, gomockhandler check complains about it. Given that those files come from outside of my project, I don't think having gomockhandler managing them would be a good idea.

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.