| 1 |
env GO111MODULE=on |
| 2 |
|
| 3 |
# Replacement should not use a vendor directory as the target. |
| 4 |
! go mod vendor |
| 5 |
stderr 'replacement path ./vendor/not-rsc.io/quote/v3 inside vendor directory' |
| 6 |
|
| 7 |
cp go.mod1 go.mod |
| 8 |
rm -r vendor |
| 9 |
|
| 10 |
# Before vendoring, we expect to see the original directory. |
| 11 |
go list -f '{{with .Module}}{{.Version}}{{end}} {{.Dir}}' rsc.io/quote/v3 |
| 12 |
stdout 'v3.0.0' |
| 13 |
stdout '.*[/\\]not-rsc.io[/\\]quote[/\\]v3' |
| 14 |
|
| 15 |
# Since all dependencies are replaced, 'go mod vendor' should not |
| 16 |
# have to download anything from the network. |
| 17 |
go mod vendor |
| 18 |
! stderr 'downloading' |
| 19 |
! stderr 'finding' |
| 20 |
|
| 21 |
# After vendoring, we expect to see the replacement in the vendor directory, |
| 22 |
# without attempting to look up the non-replaced version. |
| 23 |
cmp vendor/rsc.io/quote/v3/quote.go local/not-rsc.io/quote/v3/quote.go |
| 24 |
|
| 25 |
go list -mod=vendor -f '{{with .Module}}{{.Version}}{{end}} {{.Dir}}' rsc.io/quote/v3 |
| 26 |
stdout 'v3.0.0' |
| 27 |
stdout '.*[/\\]vendor[/\\]rsc.io[/\\]quote[/\\]v3' |
| 28 |
! stderr 'finding' |
| 29 |
! stderr 'lookup disabled' |
| 30 |
|
| 31 |
# 'go list' should provide the original replacement directory as the module's |
| 32 |
# replacement path. |
| 33 |
go list -mod=vendor -f '{{with .Module}}{{with .Replace}}{{.Path}}{{end}}{{end}}' rsc.io/quote/v3 |
| 34 |
stdout '.*[/\\]not-rsc.io[/\\]quote[/\\]v3' |
| 35 |
|
| 36 |
# The same module can't be used as two different paths. |
| 37 |
cd multiple-paths |
| 38 |
! go mod vendor |
| 39 |
stderr 'rsc.io/quote/[email protected] used for two different module paths \(not-rsc.io/quote/v3 and rsc.io/quote/v3\)' |
| 40 |
|
| 41 |
-- go.mod -- |
| 42 |
module example.com/replace |
| 43 |
|
| 44 |
require rsc.io/quote/v3 v3.0.0 |
| 45 |
replace rsc.io/quote/v3 => ./vendor/not-rsc.io/quote/v3 |
| 46 |
|
| 47 |
-- go.mod1 -- |
| 48 |
module example.com/replace |
| 49 |
|
| 50 |
require rsc.io/quote/v3 v3.0.0 |
| 51 |
replace rsc.io/quote/v3 => ./local/not-rsc.io/quote/v3 |
| 52 |
|
| 53 |
-- imports.go -- |
| 54 |
package replace |
| 55 |
|
| 56 |
import _ "rsc.io/quote/v3" |
| 57 |
|
| 58 |
-- local/not-rsc.io/quote/v3/go.mod -- |
| 59 |
module not-rsc.io/quote/v3 |
| 60 |
|
| 61 |
-- local/not-rsc.io/quote/v3/quote.go -- |
| 62 |
package quote |
| 63 |
|
| 64 |
-- multiple-paths/main.go -- |
| 65 |
package main |
| 66 |
import ( |
| 67 |
"fmt" |
| 68 |
"rsc.io/quote/v3" |
| 69 |
) |
| 70 |
func main() { |
| 71 |
fmt.Println(quote.GoV3()) |
| 72 |
} |
| 73 |
-- multiple-paths/go.mod -- |
| 74 |
module quoter |
| 75 |
require ( |
| 76 |
rsc.io/quote/v3 v3.0.0 |
| 77 |
not-rsc.io/quote/v3 v3.0.0 |
| 78 |
) |
| 79 |
replace not-rsc.io/quote/v3 => rsc.io/quote/v3 v3.0.0 |
| 80 |
-- multiple-paths/go.sum -- |
| 81 |
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= |
| 82 |
rsc.io/quote/v3 v3.0.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= |
| 83 |
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= |
| 84 |
|
| 85 |
-- vendor/not-rsc.io/quote/v3/go.mod -- |
| 86 |
module not-rsc.io/quote/v3 |
| 87 |
|
| 88 |
-- vendor/not-rsc.io/quote/v3/quote.go -- |
| 89 |
package quote |