Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gomonkey breaks tests on macOS #1178

Closed
akojo opened this issue Apr 14, 2022 · 6 comments
Closed

gomonkey breaks tests on macOS #1178

akojo opened this issue Apr 14, 2022 · 6 comments

Comments

@akojo
Copy link
Contributor

akojo commented Apr 14, 2022

Describe the bug
Since macOS doesn't allow writing to text section of programs, trying to use gomonkey will panic.

To Reproduce
Steps to reproduce the behavior:

  1. Clone the repo
  2. Run make test
  3. Test will fail with following error
--- FAIL: TestFormater_FormatAPI (0.01s)
    --- PASS: TestFormater_FormatAPI/Format_Test (0.01s)
    --- FAIL: TestFormater_FormatAPI/TestWithMonkeyFilepathAbs (0.00s)
panic: permission denied [recovered]
	panic: permission denied

goroutine 37 [running]:
testing.tRunner.func1.2({0x102df5e60, 0x103110928})
	~/sdk/go1.17.6/src/testing/testing.go:1209 +0x258
testing.tRunner.func1(0x1400023a680)
	~/sdk/go1.17.6/src/testing/testing.go:1212 +0x284
panic({0x102df5e60, 0x103110928})
	~/sdk/go1.17.6/src/runtime/panic.go:1038 +0x21c
github.com/agiledragon/gomonkey/v2.modifyBinary(0x1029c7880, {0x14000218978, 0x18, 0x18})
	~/go/pkg/mod/github.com/agiledragon/gomonkey/[email protected]/modify_binary_darwin.go:11 +0x134
github.com/agiledragon/gomonkey/v2.replace(0x1029c7880, 0x1400022dd70)
	~/go/pkg/mod/github.com/agiledragon/gomonkey/[email protected]/patch.go:196 +0xb8
github.com/agiledragon/gomonkey/v2.(*Patches).ApplyCore(0x14000313a58, {0x102dd2580, 0x102e53198, 0x13}, {0x102dd2580, 0x1400022dd70, 0x13})
	~/go/pkg/mod/github.com/agiledragon/gomonkey/[email protected]/patch.go:158 +0x120
github.com/agiledragon/gomonkey/v2.(*Patches).ApplyFunc(0x140001d2a58, {0x102dd2580, 0x102e53198}, {0x102dd2580, 0x1400022dd70})
	~/go/pkg/mod/github.com/agiledragon/gomonkey/[email protected]/patch.go:66 +0x1cc
github.com/agiledragon/gomonkey/v2.ApplyFunc(...)
	~/go/pkg/mod/github.com/agiledragon/gomonkey/[email protected]/patch.go:24
github.com/swaggo/swag.TestFormater_FormatAPI.func3(0x1400023a680)
	~/src/swag/formater_test.go:63 +0x254
testing.tRunner(0x1400023a680, 0x102e52558)
	~/sdk/go1.17.6/src/testing/testing.go:1259 +0xfc
created by testing.(*T).Run
	~/sdk/go1.17.6/src/testing/testing.go:1306 +0x328
FAIL	github.com/swaggo/swag	0.212s
FAIL
make: *** [test] Error 1

Expected behavior
Tests succeed

Your swag version
master

Your go version
1.17.6

Desktop (please complete the following information):

  • OS: macOS Monterey 12.3

Additional context
See for example agiledragon/gomonkey#70

@ubogdan
Copy link
Contributor

ubogdan commented Apr 15, 2022

@akojo Would you mind taking a look at this issue? I don't own a MacOS.

@akojo
Copy link
Contributor Author

akojo commented Apr 16, 2022

Yep, I'll take a stab at rewriting the offending tests so that they don't use gomonkey. Though that means I have to also rewrite part of the feature to make it testable without monkey patching.

@ubogdan
Copy link
Contributor

ubogdan commented Apr 16, 2022

Thanks.

@ubogdan
Copy link
Contributor

ubogdan commented Apr 28, 2022

Unfortunately, I can't reproduce it on macOS Monterey 12.3.1.

$ go version
go version go1.18.1 darwin/amd64

$ go version
go version go1.17.6 darwin/amd64

@akojo
Copy link
Contributor Author

akojo commented Apr 28, 2022

I'm guessing it only affects arm64 macs. I'm working on a PR that fixes the issue. Took me a while because I got a bit carried away while refactoring the code 😄

@ubogdan
Copy link
Contributor

ubogdan commented Apr 28, 2022

Do you have an eta for this? I'm working on some rewrite for parser.go and It may be nice to not slow you down due to conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants