@@ -121,3 +121,141 @@ func TestParseGoLock_IndirectPackages(t *testing.T) {
121121 },
122122 })
123123}
124+
125+ func TestParseGoLock_Replacements_One (t * testing.T ) {
126+ t .Parallel ()
127+
128+ packages , err := lockfile .ParseGoLock ("fixtures/go/replace-one.mod" )
129+
130+ if err != nil {
131+ t .Errorf ("Got unexpected error: %v" , err )
132+ }
133+
134+ expectPackages (t , packages , []lockfile.PackageDetails {
135+ {
136+ Name : "example.com/fork/net" ,
137+ Version : "1.4.5" ,
138+ Ecosystem : lockfile .GoEcosystem ,
139+ CompareAs : lockfile .GoEcosystem ,
140+ },
141+ })
142+ }
143+
144+ func TestParseGoLock_Replacements_Mixed (t * testing.T ) {
145+ t .Parallel ()
146+
147+ packages , err := lockfile .ParseGoLock ("fixtures/go/replace-mixed.mod" )
148+
149+ if err != nil {
150+ t .Errorf ("Got unexpected error: %v" , err )
151+ }
152+
153+ expectPackages (t , packages , []lockfile.PackageDetails {
154+ {
155+ Name : "example.com/fork/net" ,
156+ Version : "1.4.5" ,
157+ Ecosystem : lockfile .GoEcosystem ,
158+ CompareAs : lockfile .GoEcosystem ,
159+ },
160+ {
161+ Name : "golang.org/x/net" ,
162+ Version : "0.5.6" ,
163+ Ecosystem : lockfile .GoEcosystem ,
164+ CompareAs : lockfile .GoEcosystem ,
165+ },
166+ })
167+ }
168+
169+ func TestParseGoLock_Replacements_Local (t * testing.T ) {
170+ t .Parallel ()
171+
172+ packages , err := lockfile .ParseGoLock ("fixtures/go/replace-local.mod" )
173+
174+ if err != nil {
175+ t .Errorf ("Got unexpected error: %v" , err )
176+ }
177+
178+ expectPackages (t , packages , []lockfile.PackageDetails {
179+ {
180+ Name : "./fork/net" ,
181+ Version : "" ,
182+ Ecosystem : lockfile .GoEcosystem ,
183+ CompareAs : lockfile .GoEcosystem ,
184+ },
185+ {
186+ Name : "github.com/BurntSushi/toml" ,
187+ Version : "1.0.0" ,
188+ Ecosystem : lockfile .GoEcosystem ,
189+ CompareAs : lockfile .GoEcosystem ,
190+ },
191+ })
192+ }
193+
194+ func TestParseGoLock_Replacements_Different (t * testing.T ) {
195+ t .Parallel ()
196+
197+ packages , err := lockfile .ParseGoLock ("fixtures/go/replace-different.mod" )
198+
199+ if err != nil {
200+ t .Errorf ("Got unexpected error: %v" , err )
201+ }
202+
203+ expectPackages (t , packages , []lockfile.PackageDetails {
204+ {
205+ Name : "example.com/fork/foe" ,
206+ Version : "1.4.5" ,
207+ Ecosystem : lockfile .GoEcosystem ,
208+ CompareAs : lockfile .GoEcosystem ,
209+ },
210+ {
211+ Name : "example.com/fork/foe" ,
212+ Version : "1.4.2" ,
213+ Ecosystem : lockfile .GoEcosystem ,
214+ CompareAs : lockfile .GoEcosystem ,
215+ },
216+ })
217+ }
218+
219+ func TestParseGoLock_Replacements_NotRequired (t * testing.T ) {
220+ t .Parallel ()
221+
222+ packages , err := lockfile .ParseGoLock ("fixtures/go/replace-not-required.mod" )
223+
224+ if err != nil {
225+ t .Errorf ("Got unexpected error: %v" , err )
226+ }
227+
228+ expectPackages (t , packages , []lockfile.PackageDetails {
229+ {
230+ Name : "golang.org/x/net" ,
231+ Version : "0.5.6" ,
232+ Ecosystem : lockfile .GoEcosystem ,
233+ CompareAs : lockfile .GoEcosystem ,
234+ },
235+ {
236+ Name : "github.com/BurntSushi/toml" ,
237+ Version : "1.0.0" ,
238+ Ecosystem : lockfile .GoEcosystem ,
239+ CompareAs : lockfile .GoEcosystem ,
240+ },
241+ })
242+ }
243+
244+ func TestParseGoLock_Replacements_NoVersion (t * testing.T ) {
245+ t .Parallel ()
246+
247+ packages , err := lockfile .ParseGoLock ("fixtures/go/replace-no-version.mod" )
248+
249+ if err != nil {
250+ t .Errorf ("Got unexpected error: %v" , err )
251+ }
252+
253+ expectPackages (t , packages , []lockfile.PackageDetails {
254+ {
255+ Name : "example.com/fork/net" ,
256+ Version : "1.4.5" ,
257+ Ecosystem : lockfile .GoEcosystem ,
258+ CompareAs : lockfile .GoEcosystem ,
259+ },
260+ })
261+ }
0 commit comments