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

     1  env GO111MODULE=on
     2  
     3  # download with version should print nothing.
     4  # It should not load retractions from the .mod file from the latest version.
     5  go mod download rsc.io/quote@v1.5.0
     6  ! stdout .
     7  ! stderr .
     8  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info
     9  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod
    10  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip
    11  ! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.info
    12  ! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod
    13  
    14  # download of an invalid path should report the error
    15  [short] skip
    16  ! go mod download this.domain.is.invalid/somemodule@v1.0.0
    17  stderr 'this.domain.is.invalid'
    18  ! go mod download -json this.domain.is.invalid/somemodule@v1.0.0
    19  stdout '"Error": ".*this.domain.is.invalid.*"'
    20  
    21  # download -json with version should print JSON
    22  go mod download -json 'rsc.io/quote@<=v1.5.0'
    23  stdout '^\t"Path": "rsc.io/quote"'
    24  stdout '^\t"Version": "v1.5.0"'
    25  stdout '^\t"Info": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.0.info"'
    26  stdout '^\t"GoMod": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.0.mod"'
    27  stdout '^\t"Zip": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.0.zip"'
    28  stdout '^\t"Sum": "h1:6fJa6E\+wGadANKkUMlZ0DhXFpoKlslOQDCo259XtdIE="'  # hash of testdata/mod version, not real version!
    29  stdout '^\t"GoModSum": "h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe\+TKr0="'
    30  ! stdout '"Error"'
    31  
    32  # download queries above should not have added to go.mod.
    33  go list -m all
    34  ! stdout rsc.io
    35  
    36  # download query should have downloaded go.mod for the highest release version
    37  # in order to find retractions when resolving the query '@<=v1.5.0'.
    38  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.info
    39  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod
    40  ! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
    41  
    42  # add to go.mod so we can test non-query downloads
    43  go mod edit -require rsc.io/quote@v1.5.3-pre1
    44  ! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info
    45  ! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod
    46  ! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip
    47  
    48  # module loading will page in the info and mod files
    49  go list -m -mod=mod all
    50  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info
    51  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod
    52  ! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip
    53  
    54  # download will fetch and unpack the zip file
    55  go mod download
    56  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info
    57  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod
    58  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip
    59  exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.3-pre1
    60  
    61  # download repopulates deleted files and directories independently.
    62  rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info
    63  go mod download
    64  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.info
    65  rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod
    66  go mod download
    67  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.mod
    68  rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip
    69  go mod download
    70  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip
    71  rm -r $GOPATH/pkg/mod/rsc.io/quote@v1.5.3-pre1
    72  go mod download
    73  exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.3-pre1
    74  
    75  # download reports the locations of downloaded files
    76  go mod download -json
    77  stdout '^\t"Path": "rsc.io/quote"'
    78  stdout '^\t"Version": "v1.5.3-pre1"'
    79  stdout '^\t"Info": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.3-pre1.info"'
    80  stdout '^\t"GoMod": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.3-pre1.mod"'
    81  stdout '^\t"Zip": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.3-pre1.zip"'
    82  stdout '^\t"Dir": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)rsc.io(\\\\|/)quote@v1.5.3-pre1"'
    83  
    84  # download will follow replacements
    85  go mod edit -require rsc.io/quote@v1.5.1 -replace rsc.io/quote@v1.5.1=rsc.io/quote@v1.5.2
    86  go mod download
    87  ! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.1.zip
    88  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
    89  
    90  # download will not follow replacements for explicit module queries
    91  go mod download -json rsc.io/quote@v1.5.1
    92  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.1.zip
    93  
    94  # download reports errors encountered when locating modules
    95  ! go mod download bad/path
    96  stderr '^go: module bad/path: not a known dependency$'
    97  ! go mod download bad/path@latest
    98  stderr '^go: bad/path@latest: malformed module path "bad/path": missing dot in first path element$'
    99  ! go mod download rsc.io/quote@v1.999.999
   100  stderr '^go: rsc.io/quote@v1.999.999: reading .*/v1.999.999.info: 404 Not Found$'
   101  ! go mod download -json bad/path
   102  stdout '^\t"Error": "module bad/path: not a known dependency"'
   103  
   104  # download main module produces a warning or error
   105  go mod download m
   106  stderr '^go: skipping download of m that resolves to the main module\n'
   107  ! go mod download m@latest
   108  stderr '^go: m@latest: malformed module path "m": missing dot in first path element$'
   109  
   110  # download without arguments updates go.mod and go.sum after loading the
   111  # build list, but does not save sums for downloaded zips.
   112  cd update
   113  cp go.mod.orig go.mod
   114  ! exists go.sum
   115  go mod download
   116  cmp go.mod.update go.mod
   117  cmp go.sum.update go.sum
   118  cp go.mod.orig go.mod
   119  rm go.sum
   120  
   121  # download with arguments (even "all") does update go.mod and go.sum.
   122  go mod download rsc.io/sampler
   123  cmp go.mod.update go.mod
   124  grep '^rsc.io/sampler v1.3.0 ' go.sum
   125  cp go.mod.orig go.mod
   126  rm go.sum
   127  
   128  go mod download all
   129  cmp go.mod.update go.mod
   130  grep '^rsc.io/sampler v1.3.0 ' go.sum
   131  
   132  # https://golang.org/issue/44435: At go 1.17 or higher, 'go mod download'
   133  # (without arguments) should only download the modules explicitly required in
   134  # the go.mod file, not (presumed-irrelevant) transitive dependencies.
   135  #
   136  # (If the go.mod file is inconsistent, the version downloaded should be the
   137  # selected version from the broader graph, but the go.mod file will also be
   138  # updated to list the correct versions. If at some point we change 'go mod
   139  # download' to stop updating for consistency, then it should fail if the
   140  # requirements are inconsistent.)
   141  
   142  rm go.sum
   143  cp go.mod.orig go.mod
   144  go mod edit -go=1.17
   145  cp go.mod.update go.mod.go117
   146  go mod edit -go=1.17 go.mod.go117
   147  
   148  go clean -modcache
   149  go mod download
   150  cmp go.mod go.mod.go117
   151  
   152  go list -e -m all
   153  stdout '^rsc.io/quote v1.5.2$'
   154  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
   155  stdout '^rsc.io/sampler v1.3.0$'
   156  ! exists $GOPATH/pkg/mod/cache/download/rsc.io/sampler/@v/v1.2.1.zip
   157  exists $GOPATH/pkg/mod/cache/download/rsc.io/sampler/@v/v1.3.0.zip
   158  stdout '^golang\.org/x/text v0.0.0-20170915032832-14c0d48ead0c$'
   159  ! exists $GOPATH/pkg/mod/cache/download/golang.org/x/text/@v/v0.0.0-20170915032832-14c0d48ead0c.zip
   160  cmp go.mod go.mod.go117
   161  
   162  # However, 'go mod download all' continues to download the selected version
   163  # of every module reported by 'go list -m all'.
   164  
   165  cp go.mod.orig go.mod
   166  go mod edit -go=1.17
   167  go clean -modcache
   168  go mod download all
   169  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
   170  ! exists $GOPATH/pkg/mod/cache/download/rsc.io/sampler/@v/v1.2.1.zip
   171  exists $GOPATH/pkg/mod/cache/download/rsc.io/sampler/@v/v1.3.0.zip
   172  exists $GOPATH/pkg/mod/cache/download/golang.org/x/text/@v/v0.0.0-20170915032832-14c0d48ead0c.zip
   173  cmp go.mod go.mod.go117
   174  
   175  cd ..
   176  
   177  # allow go mod download without go.mod
   178  env GO111MODULE=auto
   179  rm go.mod
   180  rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.2.1.zip
   181  go mod download rsc.io/quote@v1.2.1
   182  exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.2.1.zip
   183  
   184  # download -x with version should print
   185  # the underlying commands such as contacting GOPROXY.
   186  go mod download -x rsc.io/quote@v1.0.0
   187  ! stdout .
   188  stderr 'get '$GOPROXY
   189  
   190  -- go.mod --
   191  module m
   192  
   193  -- update/go.mod.orig --
   194  module m
   195  
   196  go 1.16
   197  
   198  require (
   199  	rsc.io/quote v1.5.2
   200  	rsc.io/sampler v1.2.1 // older version than in build list
   201  )
   202  -- update/go.mod.update --
   203  module m
   204  
   205  go 1.16
   206  
   207  require (
   208  	rsc.io/quote v1.5.2
   209  	rsc.io/sampler v1.3.0 // older version than in build list
   210  )
   211  -- update/go.sum.update --
   212  golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
   213  rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
   214  rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
   215  

View as plain text