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

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

View as plain text