Pass env to gentestmain so it will correctly filter (#3785)

This is a fairly simple change and the test is also simple. Without the
addition test.bzl, the new cgo_required test fails to compile. It's more
of a regression test than anything else.
diff --git a/go/private/rules/test.bzl b/go/private/rules/test.bzl
index 0ec8dd8..1283776 100644
--- a/go/private/rules/test.bzl
+++ b/go/private/rules/test.bzl
@@ -120,6 +120,7 @@
         executable = go.toolchain._builder,
         arguments = [arguments],
         toolchain = GO_TOOLCHAIN_LABEL,
+        env = go.env,
     )
 
     test_gc_linkopts = gc_linkopts(ctx)
diff --git a/tests/core/cgo/BUILD.bazel b/tests/core/cgo/BUILD.bazel
index cc12203..558f7f5 100644
--- a/tests/core/cgo/BUILD.bazel
+++ b/tests/core/cgo/BUILD.bazel
@@ -472,3 +472,9 @@
     srcs = ["use_c_symbol_through_go.c"],
     deps = [":use_transitive_symbol"],
 )
+
+go_test(
+    name = "cgo_required",
+    srcs = ["cgo_required_test.go"],
+    pure = "on",
+)
diff --git a/tests/core/cgo/cgo_required_test.go b/tests/core/cgo/cgo_required_test.go
new file mode 100644
index 0000000..af5df7c
--- /dev/null
+++ b/tests/core/cgo/cgo_required_test.go
@@ -0,0 +1,10 @@
+//go:build cgo
+// +build cgo
+
+package cgo_required
+
+import "testing"
+
+// Without correct filtering, gentestmain will try to link against this test
+// that does not exist with pure = True
+func TestHelloWorld(t *testing.T) {}