...

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

Documentation: cmd/go/testdata/script

     1env GO111MODULE=on
     2[short] skip
     3
     4# With good go.sum, verify succeeds by avoiding download.
     5cp go.sum.good go.sum
     6go mod verify
     7! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip
     8
     9# With bad go.sum, verify succeeds by avoiding download.
    10cp go.sum.bad go.sum
    11go mod verify
    12! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip
    13
    14# With bad go.sum, sync (which must download) fails.
    15rm go.sum
    16cp go.sum.bad go.sum
    17! go mod tidy
    18stderr 'checksum mismatch'
    19! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip
    20
    21# With good go.sum, sync works.
    22rm go.sum
    23cp go.sum.good go.sum
    24go mod tidy
    25exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip
    26exists $GOPATH/pkg/mod/rsc.io/quote@v1.1.0/quote.go
    27
    28# go.sum should have the new checksum for go.mod
    29grep '^rsc.io/quote v1.1.0/go.mod ' go.sum
    30
    31# verify should work
    32go mod verify
    33
    34# basic loading of module graph should detect incorrect go.mod files.
    35go mod graph
    36cp go.sum.bad2 go.sum
    37! go mod graph
    38stderr 'go.mod: checksum mismatch'
    39
    40# go.sum should be created and updated automatically.
    41rm go.sum
    42go mod tidy
    43grep '^rsc.io/quote v1.1.0/go.mod ' go.sum
    44grep '^rsc.io/quote v1.1.0 ' go.sum
    45
    46# verify should fail on a missing ziphash. tidy should restore it.
    47rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.ziphash
    48! go mod verify
    49stderr '^rsc.io/quote v1.1.0: missing ziphash: open '$GOPATH'[/\\]pkg[/\\]mod[/\\]cache[/\\]download[/\\]rsc.io[/\\]quote[/\\]@v[/\\]v1.1.0.ziphash'
    50go mod tidy
    51exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.ziphash
    52go mod verify
    53
    54# Packages below module root should not be mentioned in go.sum.
    55rm go.sum
    56go mod edit -droprequire rsc.io/quote
    57go get rsc.io/quote/buggy
    58grep '^rsc.io/quote v1.5.2/go.mod ' go.sum
    59! grep buggy go.sum
    60
    61# non-existent packages below module root should not be mentioned in go.sum
    62go mod edit -droprequire rsc.io/quote
    63! go list rsc.io/quote/morebuggy
    64grep '^rsc.io/quote v1.5.2/go.mod ' go.sum
    65! grep buggy go.sum
    66
    67-- go.mod --
    68module x
    69require rsc.io/quote v1.1.0
    70
    71-- x.go --
    72package x
    73import _ "rsc.io/quote"
    74
    75-- go.sum.good --
    76rsc.io/quote v1.1.0 h1:a3YaZoizPtXyv6ZsJ74oo2L4/bwOSTKMY7MAyo4O/0c=
    77
    78-- go.sum.bad --
    79rsc.io/quote v1.1.0 h1:a3YaZoizPtXyv6ZsJ74oo2L4/bwOSTKMY7MAyo4O/1c=
    80
    81-- go.sum.bad2 --
    82rsc.io/quote v1.1.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl1=

View as plain text