aboutsummaryrefslogtreecommitdiff
path: root/tests/integration
diff options
context:
space:
mode:
authorFabian Meumertzheim <fabian@meumertzhe.im>2023-01-25 10:55:26 +0100
committerGitHub <noreply@github.com>2023-01-25 10:55:26 +0100
commitfe6975120bcaf6d43d367e4380d95f724e2cbba8 (patch)
tree348a34ec2213c1969f381a59f66d5da827ea0e91 /tests/integration
parentcf78385a58e278b542511d246bb1cef287d528e9 (diff)
downloadbazelbuild-rules_go-fe6975120bcaf6d43d367e4380d95f724e2cbba8.tar.gz
Make the toolchain's `go` binary available as a target (#3429)
This allows developers to use the `go` command provided by the registered toolchain to e.g. add dependencies to `go.mod`. This ensures that everyone uses the same version of Go and does not require a local installation of Go.
Diffstat (limited to 'tests/integration')
-rw-r--r--tests/integration/go_bin_runner/BUILD.bazel6
-rw-r--r--tests/integration/go_bin_runner/go_bin_runner_test.go49
2 files changed, 55 insertions, 0 deletions
diff --git a/tests/integration/go_bin_runner/BUILD.bazel b/tests/integration/go_bin_runner/BUILD.bazel
new file mode 100644
index 00000000..e7db9531
--- /dev/null
+++ b/tests/integration/go_bin_runner/BUILD.bazel
@@ -0,0 +1,6 @@
+load("//go/tools/bazel_testing:def.bzl", "go_bazel_test")
+
+go_bazel_test(
+ name = "go_bin_runner_test",
+ srcs = ["go_bin_runner_test.go"],
+)
diff --git a/tests/integration/go_bin_runner/go_bin_runner_test.go b/tests/integration/go_bin_runner/go_bin_runner_test.go
new file mode 100644
index 00000000..cb238f7b
--- /dev/null
+++ b/tests/integration/go_bin_runner/go_bin_runner_test.go
@@ -0,0 +1,49 @@
+// Copyright 2023 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package go_bin_runner_test
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "github.com/bazelbuild/rules_go/go/tools/bazel_testing"
+)
+
+func TestMain(m *testing.M) {
+ bazel_testing.TestMain(m, bazel_testing.Args{})
+}
+
+func TestGoEnv(t *testing.T) {
+ // Set an invalid GOROOT to test that the //go target still finds the expected hermetic GOROOT.
+ os.Setenv("GOROOT", "invalid")
+
+ bazelInfoOut, err := bazel_testing.BazelOutput("info", "output_base")
+ if err != nil {
+ t.Fatal(err)
+ }
+ outputBase := strings.TrimSpace(string(bazelInfoOut))
+
+ goEnvOut, err := bazel_testing.BazelOutput("run", "@io_bazel_rules_go//go", "--", "env", "GOROOT")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ goRoot := strings.TrimSpace(string(goEnvOut))
+ if goRoot != filepath.Join(outputBase, "external", "go_sdk") {
+ t.Fatalf("GOROOT was not equal to %s", filepath.Join(outputBase, "external", "go_sdk"))
+ }
+}