sanposhiho / gomockhandler

Mr. gomockhandler is the clever and more agile manager of golang/mock (uber/mock) 👔
MIT License
111 stars 9 forks source link

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

Closed s4s7 closed 9 months ago

s4s7 commented 9 months ago

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

https://github.com/uber-go/mock/commit/2c718f249a424ac6ce6e2afa28c3c17f95c51241 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
//
sanposhiho commented 9 months ago

@s4s7 Thanks for the investigation with such details. Fortunately, the change on gomock hasn't been released yet.

Based on the commit you shew, seemingly we should use --write_command_comment=false on mockgen internally (ref1, ref2). Are you willing to help contribute again? :)

Also, the difficulty here is the version difference. If users' installed mockgen is the older version, mockgen wouldn't accept write_command_comment flag and error out. Once the change on gomock side is released, we also have to cut the release, calling out this breaking change with it - the required action from users would be updating mockgen version on their local machine/CI.

s4s7 commented 9 months ago

I want to contribute again, thank you!

s4s7 commented 9 months ago

Sorry, I may have mislead you a bit. It seems that the gomockhandler -config=./gomockhandler.json check is already not working correctly in go.uber.org/mock/mockgen@v0.4.0.

I think we need to include a process that replaces // mockgen -destination=usecases/mock/tmp_xxx.go with // mockgen -destination=usecases/mock/xxx.go within the commented-out section to perfectly matche tmpFile(/mock/tmp_xxx.go) with the file(/mock/xxx.go) generated by mockgen.

sanposhiho commented 9 months ago

Do we miss something else? since https://github.com/uber-go/mock/commit/2c718f249a424ac6ce6e2afa28c3c17f95c51241 is not included in mockgenv0.4.0.

sanposhiho commented 9 months ago

Ah, now I got it: the command generated in mock files is implemented in past release, https://github.com/uber-go/mock/issues/104 proposed the way to disable it, and it comes to write_command_comment option now.

sanposhiho commented 9 months ago

Yeah, so we have to think the way of avoiding this issue without write_command_comment.

I think we need to include a process that replaces

Yup, looks good. Let's give it a try.

sanposhiho commented 9 months ago

Published https://github.com/sanposhiho/gomockhandler/tree/v1.5.0, try out it!