github.com/bazelbuild/bazel-gazelle@v0.36.1-0.20240520142334-61b277ba6fed/language/go/stubs_test.go (about)

     1  /*
     2  	Copyright 2018 The Bazel Authors. All rights reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  package golang
    17  
    18  func init() {
    19  	// Replace some functions with test stubs. This avoids a dependency on
    20  	// the go command in the actual test, which is sandboxed.
    21  	goListModules = goListModulesStub
    22  	goModDownload = goModDownloadStub
    23  }
    24  
    25  func goListModulesStub(dir string) ([]byte, error) {
    26  	return []byte(`{
    27  	"Path": "github.com/bazelbuild/bazel-gazelle",
    28  	"Main": true,
    29  	"Dir": "/tmp/tmp.XxZ9HCw1Mq",
    30  	"GoMod": "/tmp/tmp.XxZ9HCw1Mq/go.mod"
    31  }
    32  {
    33  	"Path": "github.com/BurntSushi/toml",
    34  	"Version": "v0.3.1",
    35  	"Time": "2017-03-28T06:15:53Z",
    36  	"Indirect": true,
    37  	"Dir": "/usr/local/google/home/jayconrod/go/pkg/mod/github.com/!burnt!sushi/toml@v0.3.1",
    38  	"GoMod": "/usr/local/google/home/jayconrod/go/pkg/mod/cache/download/github.com/!burnt!sushi/toml/@v/v0.3.1.mod"
    39  }
    40  {
    41  	"Path": "github.com/bazelbuild/buildtools",
    42  	"Version": "v0.0.0-20190202002759-027686e28d67",
    43  	"Time": "2018-02-26T16:48:55Z",
    44  	"Dir": "/usr/local/google/home/jayconrod/go/pkg/mod/github.com/bazelbuild/buildtools@v0.0.0-20190202002759-027686e28d67",
    45  	"GoMod": "/usr/local/google/home/jayconrod/go/pkg/mod/cache/download/github.com/bazelbuild/buildtools/@v/v0.0.0-20190202002759-027686e28d67.mod"
    46  }
    47  {
    48  	"Path": "github.com/davecgh/go-spew",
    49  	"Version": "v1.1.1",
    50  	"Time": "2016-10-29T20:57:26Z",
    51  	"Indirect": true,
    52  	"Dir": "/usr/local/google/home/jayconrod/go/pkg/mod/github.com/davecgh/go-spew@v1.1.1",
    53  	"GoMod": "/usr/local/google/home/jayconrod/go/pkg/mod/cache/download/github.com/davecgh/go-spew/@v/v1.1.1.mod"
    54  }
    55  {
    56  	"Path": "github.com/fork/go-toml",
    57  	"Version": "v0.0.0-20190116191733-b6c0e53d7304",
    58  	"Time": "2016-10-29T20:57:26Z",
    59  	"Dir": "/usr/local/google/home/jayconrod/go/pkg/mod/github.com/fork/!go-toml@v1.0.0",
    60  	"GoMod": "/usr/local/google/home/jayconrod/go/pkg/mod/cache/download/github.com/fork/go-toml@v/v1.0.0.mod"
    61  }
    62  {
    63  	"Path": "github.com/pelletier/go-toml",
    64  	"Version": "v1.0.1",
    65  	"Time": "2017-09-24T18:42:18Z",
    66  	"Dir": "/usr/local/google/home/jayconrod/go/pkg/mod/github.com/pelletier/go-toml@v1.0.1",
    67  	"Replace": {
    68  		"Path": "github.com/fork/go-toml",
    69  		"Version": "v0.0.0-20190425002759-70bc0436ed16",
    70  		"Time": "2017-04-06T11:16:28Z",
    71  		"Dir": "/usr/local/google/home/jayconrod/go/pkg/mod/github.com/fork/!go-toml@v1.0.1",
    72          "GoMod": "/usr/local/google/home/jayconrod/go/pkg/mod/cache/download/github.com/fork/go-toml@v/v1.0.1.mod"
    73  	},
    74  	"GoMod": "/usr/local/google/home/jayconrod/go/pkg/mod/cache/download/github.com/pelletier/go-toml/@v/v1.0.1.mod"
    75  }
    76  {
    77  	"Path": "golang.org/x/tools",
    78  	"Version": "v0.0.0-20190122202912-9c309ee22fab",
    79  	"Time": "2017-08-24T19:54:20Z",
    80  	"Dir": "/usr/local/google/home/jayconrod/go/pkg/mod/golang.org/x/tools@v0.0.0-20190122202912-9c309ee22fab",
    81  	"GoMod": "/usr/local/google/home/jayconrod/go/pkg/mod/cache/download/golang.org/x/tools/@v/v0.0.0-20190122202912-9c309ee22fab.mod"
    82  }
    83  {
    84  	"Path": "gopkg.in/check.v1",
    85  	"Version": "v1.0.0-20180628173108-788fd7840127",
    86  	"Time": "2016-12-08T18:13:25Z",
    87  	"Indirect": true,
    88  	"Dir": "/usr/local/google/home/jayconrod/go/pkg/mod/gopkg.in/check.v1@v1.0.0-20180628173108-788fd7840127",
    89  	"GoMod": "/usr/local/google/home/jayconrod/go/pkg/mod/cache/download/gopkg.in/check.v1/@v/v1.0.0-20180628173108-788fd7840127.mod"
    90  }
    91  {
    92  	"Path": "gopkg.in/yaml.v2",
    93  	"Version": "v2.2.2",
    94  	"Time": "2018-03-28T19:50:20Z",
    95  	"Indirect": true,
    96  	"Dir": "/usr/local/google/home/jayconrod/go/pkg/mod/gopkg.in/yaml.v2@v2.2.2",
    97  	"GoMod": "/usr/local/google/home/jayconrod/go/pkg/mod/cache/download/gopkg.in/yaml.v2/@v/v2.2.2.mod"
    98  }
    99  `), nil
   100  }
   101  
   102  func goModDownloadStub(dir string, args []string) ([]byte, error) {
   103  	return []byte(`{
   104  	"Path": "golang.org/x/tools",
   105  	"Version": "v0.0.0-20190122202912-9c309ee22fab",
   106  	"Info": "/home/jay/go/pkg/mod/cache/download/golang.org/x/tools/@v/v0.0.0-20190122202912-9c309ee22fab.info",
   107  	"GoMod": "/home/jay/go/pkg/mod/cache/download/golang.org/x/tools/@v/v0.0.0-20190122202912-9c309ee22fab.mod",
   108  	"Zip": "/home/jay/go/pkg/mod/cache/download/golang.org/x/tools/@v/v0.0.0-20190122202912-9c309ee22fab.zip",
   109  	"Dir": "/home/jay/go/pkg/mod/golang.org/x/tools@v0.0.0-20190122202912-9c309ee22fab",
   110  	"Sum": "h1:FkAkwuYWQw+IArrnmhGlisKHQF4MsZ2Nu/fX4ttW55o=",
   111  	"GoModSum": "h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ="
   112  }
   113  `), nil
   114  }