You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we build tests that aren't external, we have two versions for the package under test:
the package from the go_library() target that we're trying to test
the _{name}#lib package that re-compiles that package with all the test sources
Before we would have two different import paths for these two versions of the package. They're both available in the test binary, where the test version of the package is available as import "{name}_test_lib".
This causes a bunch of problems and confusion:
The package initialisation might happen twice which has causes issues registering various things that are meant to be unique
Components that are compiled against the production package expect the production types, which are not compatible with the test version
There are a few cases internally where a non-exported test imports the non-test version of the package to avoid type conflicts between the two versions of the packages.
This PR links the test version of the package into the binary, with the same import path as the prod version. This means there's no distinction.
Tatskaari
changed the title
Fix issue where we have duplicate packages in tests
[Breaking] Fix issue where we have duplicate packages in tests
Oct 1, 2024
Why is this breaking? Is it just because it stops this behaviour of registering things twice?
Yeah, there are a number of places in core3 where a test package imports itself. This is fine right now because the test vs. prod packages are different. Going forward this will be a cyclic import.
Why is this breaking? Is it just because it stops this behaviour of registering things twice?
Yeah, there are a number of places in core3 where a test package imports itself. This is fine right now because the test vs. prod packages are different. Going forward this will be a cyclic import.
Right, thanks.
I think those are degenerate and they shouldn't have been doing that (albeit it was allowed and so eventually someone will try to do that thing). I don't think that would have worked with go build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When we build tests that aren't external, we have two versions for the package under test:
go_library()target that we're trying to test_{name}#libpackage that re-compiles that package with all the test sourcesBefore we would have two different import paths for these two versions of the package. They're both available in the test binary, where the test version of the package is available as
import "{name}_test_lib".This causes a bunch of problems and confusion:
There are a few cases internally where a non-exported test imports the non-test version of the package to avoid type conflicts between the two versions of the packages.
This PR links the test version of the package into the binary, with the same import path as the prod version. This means there's no distinction.
TODO gate this behind a feature flag.