...

Text file src/cmd/go/testdata/script/mod_get_update_unrelated_sum.txt

Documentation: cmd/go/testdata/script

     1# Check that 'go get' adds sums for updated modules if we had sums before,
     2# even if we didn't load packages from them.
     3# Verifies #44129.
     4
     5env fmt='{{.ImportPath}}: {{if .Error}}{{.Error.Err}}{{else}}ok{{end}}'
     6
     7# Control case: before upgrading, we have the sums we need.
     8# go list -deps -e -f $fmt .
     9# stdout '^rsc.io/quote: ok$'
    10# ! stdout rsc.io/sampler  # not imported by quote in this version
    11cp go.mod.orig go.mod
    12cp go.sum.orig go.sum
    13go mod tidy
    14cmp go.mod.orig go.mod
    15cmp go.sum.orig go.sum
    16
    17
    18# Upgrade a module. This also upgrades rsc.io/quote, and though we didn't load
    19# a package from it, we had the sum for its old version, so we need the
    20# sum for the new version, too.
    21go get example.com/upgrade@v0.0.2
    22grep '^rsc.io/quote v1.5.2 ' go.sum
    23
    24# The upgrade still breaks the build because the new version of quote imports
    25# rsc.io/sampler, and we don't have its zip sum.
    26go list -deps -e -f $fmt
    27stdout 'rsc.io/quote: ok'
    28stdout 'rsc.io/sampler: missing go.sum entry for module providing package rsc.io/sampler'
    29cp go.mod.orig go.mod
    30cp go.sum.orig go.sum
    31
    32
    33# Replace the old version with a directory before upgrading.
    34# We didn't need a sum for it before (even though we had one), so we won't
    35# fetch a new sum.
    36go mod edit -replace rsc.io/quote@v1.0.0=./dummy
    37go get example.com/upgrade@v0.0.2
    38! grep '^rsc.io/quote v1.5.2 ' go.sum
    39cp go.mod.orig go.mod
    40cp go.sum.orig go.sum
    41
    42
    43# Replace the new version with a directory before upgrading.
    44# We can't get a sum for a directory.
    45go mod edit -replace rsc.io/quote@v1.5.2=./dummy
    46go get example.com/upgrade@v0.0.2
    47! grep '^rsc.io/quote v1.5.2 ' go.sum
    48cp go.mod.orig go.mod
    49cp go.sum.orig go.sum
    50
    51
    52# Replace the new version with a different version.
    53# We should get a sum for that version.
    54go mod edit -replace rsc.io/quote@v1.5.2=rsc.io/quote@v1.5.1
    55go get example.com/upgrade@v0.0.2
    56! grep '^rsc.io/quote v1.5.2 ' go.sum
    57grep '^rsc.io/quote v1.5.1 ' go.sum
    58cp go.mod.orig go.mod
    59cp go.sum.orig go.sum
    60
    61
    62# Delete the new version's zip (but not mod) from the cache and go offline.
    63# 'go get' should fail when fetching the zip.
    64rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
    65env GOPROXY=off
    66! go get example.com/upgrade@v0.0.2
    67stderr '^go: upgraded rsc.io/quote v1.0.0 => v1.5.2: error finding sum for rsc.io/quote@v1.5.2: module lookup disabled by GOPROXY=off$'
    68
    69-- go.mod.orig --
    70module m
    71
    72go 1.16
    73
    74require (
    75	example.com/upgrade v0.0.1
    76	rsc.io/quote v1.0.0
    77)
    78
    79replace (
    80	example.com/upgrade v0.0.1 => ./upgrade1
    81	example.com/upgrade v0.0.2 => ./upgrade2
    82)
    83-- go.sum.orig --
    84rsc.io/quote v1.0.0 h1:kQ3IZQzPTiDJxSZI98YaWgxFEhlNdYASHvh+MplbViw=
    85rsc.io/quote v1.0.0/go.mod h1:v83Ri/njykPcgJltBc/gEkJTmjTsNgtO1Y7vyIK1CQA=
    86-- go.sum.want --
    87golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
    88rsc.io/quote v1.0.0 h1:kQ3IZQzPTiDJxSZI98YaWgxFEhlNdYASHvh+MplbViw=
    89rsc.io/quote v1.0.0/go.mod h1:v83Ri/njykPcgJltBc/gEkJTmjTsNgtO1Y7vyIK1CQA=
    90rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0=
    91rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
    92rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
    93-- use.go --
    94package use
    95
    96import (
    97	_ "example.com/upgrade"
    98	_ "rsc.io/quote"
    99)
   100-- upgrade1/go.mod --
   101module example.com/upgrade
   102
   103go 1.16
   104-- upgrade1/upgrade.go --
   105package upgrade
   106-- upgrade2/go.mod --
   107module example.com/upgrade
   108
   109go 1.16
   110
   111require rsc.io/quote v1.5.2 // indirect
   112-- upgrade2/upgrade.go --
   113package upgrade
   114-- dummy/go.mod --
   115module rsc.io/quote
   116
   117go 1.16
   118-- dummy/quote.go --
   119package quote
   120

View as plain text