-
Notifications
You must be signed in to change notification settings - Fork 499
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
In tests, replace go mod download with a mock executable #1449
Conversation
…ed by a test function. This speeds up the test execution since no interaction with github is needed.
pkg/module/go_get_fetcher.go
Outdated
@@ -105,8 +105,7 @@ func downloadModule(goBinaryName string, envVars []string, fs afero.Fs, gopath, | |||
const op errors.Op = "module.downloadModule" | |||
uri := strings.TrimSuffix(module, "/") | |||
fullURI := fmt.Sprintf("%s@%s", uri, version) | |||
|
|||
cmd := exec.Command(goBinaryName, "mod", "download", "-json", fullURI) | |||
cmd := cmd(goBinaryName, "mod", "download", "-json", fullURI) |
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.
While it technically works, I would argue against shadowing the new package-level cmd
variable like this. Either rename the package variable or use a different local variable.
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.
In most cases, we certainly should not mock go mod download
this is for a few reasons:
-
Athens has a hard-dependency on the Go command. In other words, if the Go command does not exist, Athens will not work.
-
If we mock the Go command, then we're not gonna be able to catch subtle differences in evolving Go versions. Let's say Go released v1.15 and they accidentally broke
go mod download
, our tests will at least catch those.
Is there a use-case I'm missing here? Thanks ✌️
@marwan-at-work that was my understanding as well, but the investigation issue was open and it looked something fun to implement :-) |
To me, the value-add is that this change allows the unit tests to be run in complete isolation (i.e. no network, no fetching a repo from GH, no waiting on that repo to actually be copied across the wire, etc.). Also, what the test is currently asserting is that I feel that verifying the end-to-end Athens-> |
From slack: Athens doesn't really have much logic besides "download a module and store it". Any logic that doesn't use go mod download (such as the Filter File and the Download File), they already run their unit tests without the Go binary (AFAIK). For example, our Storage tests don't use the Go binary because the Storage layer doesn't care where the "bytes" come from, we just care to unit test the storage's CRUD operations. As for the network and isolation, if someone doesn't have a "network" or the right "go" binary, then the tests should fail, because Athens effectively won't work in that isolated environment. it might be worth identifying exactly which unit tests should not use the go binary? |
So, there are 5 tests covered in What we test there is the interaction with the go binary (parsing the resulting json, and behaving accordingly, like checking the various files are where the json say they are). I don't have a strong opinion on this. On one hand we are testing in isolation (and the tests run waaaay faster), on the other hand we may skip breaking changes in how go behaves and testing against real |
I think this touches on a discussion of what the difference between unit, integration and end-to-end tests is. I agree that for now, our tests should holistically be covering Athens' interaction with the real Without going too out of scope of this PR, I personally think we should increase test coverage from our end-to-end tests ( As always, I certainly don't want my opinion to become the decision, and I'm 💯% open to having a vote or more discussion on this! Background: #1359 came from a discussion in a previous office hours |
Ref #1368 because I think this would close that too |
my vote is to keep things the same since |
I'm fine with whatever path, although I still believe it's a good idea to have unit tests without external dependencies (even for code that is using |
@fedepaol what do you think about expanding the end-to-end tests a bit instead of adding the mock executable to unit tests? |
@arschles not sure I understood. Ideally, we could replace the (basic) e2e script with something more articulate (which makes sense), and once we have wide coverage of the interaction with the go process in e2e we can merge this and have the local test be faster. (Or you are just suggesting to expand the e2e tests a bit, not related to this pr) |
@fedepaol yup, that's exactly what I'm suggesting. Once we have expanded e2e tests, we could then introduce this PR with the mock executable. What do you think? |
@arschles sounds like a plan. |
@fedepaol makes sense, thanks for creating that issue 😄 |
I'm going to label this on hold until #1474 is done |
Just my 2 cents, I still don't feel confident in mocking
|
Either continuing (or even trying to implement 1 in e2e) or closing this is fine to me, as long as we reach consensus on bringing this forward. Next time I'll wait a bit longer and ask around first, so I am sure the issue I am implementing is something we really want, attempting to reduce the waste of time and helping on some other issue. |
It sounds like we have a long way to go before we can continue with this, because we need to do (1) and offline mode. Let's keep this open and keep the on hold tag. We can come back to it whenever those two things are done. |
Closing, we might repoen if needed |
What is the problem I am trying to address?
As described in #1359 , we can test the interaction with the go executable bt replacing it with a local mock backed by a test function, as described in https://www.youtube.com/watch?v=8hQG7QlcLBk
By doing this, we are not testing the interaction with the real go executable but since we are not hitting github any more the execution of those tests is faster.
There are still a couple of tests that need the real executable.
Mention the issue number it fixes or add the details of the changes if it doesn't have a specific issue.
Fixes #1359
Edit from @arschles: Fixes #1368