-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
Handle replacements properly for runDev() #69
Conversation
Thank you, @simnalamburt! If you don't mind, since you've stumbled upon an edge case, do you mind adding few tests to further validate the logic? We'd hate to break existing users while fixing a bug. |
I’m not familiar with xcaddy internals (this is my first day with xcaddy,
and I’ve never used go for last 3 years) so actually I don’t know how to do
it. Can you give me some brief guide of how to test this?
2021년 8월 30일 (월) 04:46, Mohammed Al Sahaf ***@***.***>님이 작성:
… Thank you, @simnalamburt <https://github.com/simnalamburt>! If you don't
mind, since you've stumbled upon an edge case, do you mind adding few tests
to further validate the logic? We'd hate to break existing users while
fixing a bug.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#69 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABB235NAYJXHDTVGTSOPBNTT7KFCBANCNFSM5DAOIM4Q>
.
|
I think unit tests would go a long way, at least. Might have to split some of the logic into a separate function to do that effectively. Basically checking that the input and outputs are as expected. https://pkg.go.dev/testing is your friend. 👍 |
It's more robust in this way
1. Handle all possible replacements properly for runDev() Replacement targets are not always paths. Reference: https://pkg.go.dev/cmd/go/internal/list#pkg-variables 2. Parse replacement info from 'go list -m -json all' It's more robust in this way
Maybe I can separate executing |
I think I’ve done some basic testing :) Please feel free to take a look! |
Omg the test was UNIX specific 🤦 hang on |
Yay for tests 🙂 |
`go list -m -json all` contains all informations we need so we don't need extra `go list -m -json` call.
Let me try to make the issue clearer. Note the slashes here:
|
OK I think I fixed windows build, but now I failed Go 1.16 build due to the use of |
For this you have to use the older style |
Note: I tried not to split main_unix_test.go and main_windows_test.go, but their JSON looks too different so it was really hard to generate two JSON in one test code. |
If only Go supported the ternary condition operator 😂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! One minor nitpick then it's all right.
I changed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to handle one last minor nitpick. Perfecto. Thanks @simnalamburt!
Follow-up to #69 I had a situation where caddy/v2 v2.4.6 was in my go.mod and a replace on it to use local caddy repo. When I ran `xcaddy run` to test a caddy module, it failed to run because the replace included the version v2.4.6, even though somehow the buildenv go.mod had v2.6.1 (the latest), and the replace directive specified @v2.4.6 only, so the replacement didn't happen. I don't think versions in the replacement source/origin are really that useful for xcaddy. If experience proves this wrong, we can figure out a better solution.
Closes #68
runDev()
. Replacement targets are not always paths.go list -m -json all
. It's more robust in this way.I have tested all possible cases with replacements like below. So hopefully replacements won't cause any issue further at least for the
runDev()
.Use forked version of xcaddy if you want to test this PR:
References