@@ -104,3 +104,62 @@ go 1.24.0
104
104
require .Len (t , goMod .Replace , 1 )
105
105
assert .Contains (t , goMod .Replace [0 ].New .Path , "testdata/plugin/target" )
106
106
}
107
+
108
+ func TestMergeReplaceDirectives_DuplicateReplace (t * testing.T ) {
109
+ t .Parallel ()
110
+
111
+ tmp := t .TempDir ()
112
+ require .NoError (t , os .WriteFile (filepath .Join (tmp , "go.mod" ), []byte (`
113
+ module github.com/golangci/golangci-lint/v2
114
+ go 1.24.0
115
+ ` ), 0o644 ))
116
+ require .NoError (t , os .Mkdir (filepath .Join (tmp , "golangci-lint" ), 0o755 ))
117
+
118
+ // Both plugins define a replace directive for example.com/target.
119
+ b := NewBuilder (nil , & Configuration {Plugins : []* Plugin {
120
+ {Module : "example.com/plugin" , Path : "testdata/plugin" },
121
+ {Module : "example.com/plugin2" , Path : "testdata/plugin2" },
122
+ }}, tmp )
123
+
124
+ err := b .mergeReplaceDirectives (t .Context (), filepath .Join ("testdata" , "plugin" ))
125
+ require .NoError (t , err )
126
+
127
+ err = b .mergeReplaceDirectives (t .Context (), filepath .Join ("testdata" , "plugin2" ))
128
+ assert .ErrorContains (t , err , "duplicate replace directive for example.com/target" )
129
+ }
130
+
131
+ func TestMergeReplaceDirectives_DuplicateButDifferentVersion (t * testing.T ) {
132
+ t .Parallel ()
133
+
134
+ tmp := t .TempDir ()
135
+ require .NoError (t , os .WriteFile (filepath .Join (tmp , "go.mod" ), []byte (`
136
+ module github.com/golangci/golangci-lint/v2
137
+ go 1.24.0
138
+ ` ), 0o644 ))
139
+ require .NoError (t , os .Mkdir (filepath .Join (tmp , "golangci-lint" ), 0o755 ))
140
+
141
+ // Both plugins define a replace directive for example.com/target.
142
+ b := NewBuilder (nil , & Configuration {Plugins : []* Plugin {
143
+ {Module : "example.com/plugin" , Path : "testdata/plugin" },
144
+ {Module : "example.com/plugin3" , Path : "testdata/plugin3" },
145
+ }}, tmp )
146
+
147
+ err := b .mergeReplaceDirectives (t .Context (), filepath .Join ("testdata" , "plugin" ))
148
+ require .NoError (t , err )
149
+
150
+ err = b .mergeReplaceDirectives (t .Context (), filepath .Join ("testdata" , "plugin3" ))
151
+ require .NoError (t , err )
152
+
153
+ cmd := exec .CommandContext (t .Context (), "go" , "mod" , "edit" , "-json" )
154
+ cmd .Dir = b .repo
155
+ output , err := cmd .CombinedOutput ()
156
+ require .NoError (t , err )
157
+
158
+ var goMod struct {
159
+ Replace []struct { New struct { Path string } }
160
+ }
161
+ err = json .Unmarshal (output , & goMod )
162
+ require .NoError (t , err )
163
+
164
+ assert .Len (t , goMod .Replace , 2 )
165
+ }
0 commit comments