Skip to content

Conversation

@jonathansharman
Copy link

@jonathansharman jonathansharman commented Sep 5, 2025

Documentation

DELTA-2596: Mock treats foo/v2 and bar/v2 as conflicting imports (aliasing one to v3)

Description

This fixes a bug introduced in #10, in which mock considers different packages with the same version number to have the same package name, causing it to alias one of them to an incremented version number in the mock file. For example, the following imports...

"github.com/nicheinc/foo/v2"
"github.com/nicheinc/bar/v2"

...could be aliased to...

"github.com/nicheinc/foo/v2"
v3 "github.com/nicheinc/bar/v2"

This PR addresses this by using package import info to look up each import's real package name, rather than assuming that the base of the import path is the package name.

Testing Considerations

This is a little difficult to write an integration test for in the examples directory because I would need to import some versioned modules. I didn't want to introduce otherwise irrelevant dependencies to mock just to test this bug fix.

So instead I've just confirmed locally that this fixes the issues reported here and here.

Versioning

Patch.

Jonathan Sharman added 2 commits September 5, 2025 09:12
This correctly accounts for versioned packages e.g. foo/v3, which is currently treated as if its package name is v3.
@jonathansharman jonathansharman changed the title Fix/versions as packages Fix incorrect renaming of versioned packages Sep 5, 2025
Copy link

@tckastanek tckastanek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch on this. Can confirm this is working for me in https://github.com/nicheinc/lead/pull/977

}

// LocalName returns the name that can be used to reference the imported package
// locally: [Name] if nonempty or else the last element of [Path].
Copy link

@tckastanek tckastanek Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR specifically: Is this an indication that I should give up on trying to get these Go comment links to work? I still add them sometimes and I have no idea why anymore a they never do anything 😅

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Godoc links should work, but they need a sufficiently qualified name for something that actually appears as a heading in the rendered Godoc page. 👀 I mindlessly threw brackets around Name last time, but it occurred to me that struct fields aren't linkable - they're just shown in the definition for the containing type.

Conversely, I could have linked to the [Method] type or to the [Import.String] method, for instance, because those do have their own entries!

@jonathansharman jonathansharman merged commit baadd0b into main Sep 5, 2025
@jonathansharman jonathansharman deleted the fix/versions-as-packages branch September 5, 2025 17:51
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

Successfully merging this pull request may close these issues.

3 participants