Skip to content

Commit 71a2874

Browse files
committed
Test mergeReplaceDirectives with nested replace directives
1 parent d666a5d commit 71a2874

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

pkg/commands/internal/builder_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func Test_sanitizeVersion(t *testing.T) {
6363
func TestMergeReplaceDirectives(t *testing.T) {
6464
t.Parallel()
6565

66-
// Create a temporary module structure:
66+
// Create a temporary module with the following structure:
6767
// tmp/
6868
// go.mod
6969
// golangci-lint/
@@ -78,6 +78,9 @@ go 1.24.0
7878
{Module: "example.com/plugin", Path: "testdata/plugin"},
7979
}}, tmp)
8080

81+
// Merge replace directives from the plugin's go.mod into the temporary
82+
// repo. Only the plugin's own replace rules are applied; transitive
83+
// replaces from its dependencies are not automatically merged.
8184
err := b.mergeReplaceDirectives(t.Context(), filepath.Join("testdata", "plugin"))
8285
require.NoError(t, err)
8386

@@ -92,6 +95,12 @@ go 1.24.0
9295
err = json.Unmarshal(output, &goMod)
9396
require.NoError(t, err)
9497

98+
// The go.mod file should include a replace directive for
99+
// example.com/target, pointing to the local path, because
100+
// example.com/plugin's go.mod defines it. However, it should not include a
101+
// replace directive for example.com/other, since example.com/plugin does
102+
// not directly depend on it, and go mod ignores such transitive
103+
// replacements.
95104
require.Len(t, goMod.Replace, 1)
96105
assert.Contains(t, goMod.Replace[0].New.Path, "testdata/plugin/target")
97106
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
module example.com/target
22

33
go 1.24.0
4+
5+
require example.com/other v0.0.0
6+
7+
replace example.com/other => ./other
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module example.com/other
2+
3+
go 1.24.0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package other
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
package target
2+
3+
import _ "example.com/other"

0 commit comments

Comments
 (0)