Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate legacy tests to //tests/core/go_download_sdk (a go_bazel_test) #2296

Merged
merged 1 commit into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ platforms:
- "-//tests/integration/googleapis:color_service_go_proto"
- "-//tests/integration/googleapis:color_service_proto"
- "-//tests/integration/googleapis:color_service_test"
- "-//tests/legacy/build_with_old_sdk:build_with_old_sdk"
- "-//tests/legacy/cgo_library_root_dir:cgo_library_root_dir"
- "-//tests/legacy/custom_go_toolchain:custom_go_toolchain"
- "-//tests/legacy/examples/cgo/example_command:example_command_test"
- "-//tests/legacy/examples/cgo/example_command:example_command_script"
- "-//tests/legacy/examples/cgo/example_command:example_command"
Expand Down Expand Up @@ -294,9 +292,7 @@ platforms:
- "-//tests/core/stdlib:buildid_test"
- "-//tests/examples/executable_name:executable_name"
- "-//tests/integration/googleapis:color_service_test"
- "-//tests/legacy/build_with_old_sdk:build_with_old_sdk"
- "-//tests/legacy/cgo_library_root_dir:cgo_library_root_dir"
- "-//tests/legacy/custom_go_toolchain:custom_go_toolchain"
- "-//tests/legacy/examples/cgo/example_command:example_command_test"
- "-//tests/legacy/examples/cgo/example_command:example_command_script"
- "-//tests/legacy/examples/cgo/example_command:example_command"
Expand Down
1 change: 1 addition & 0 deletions tests/core/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Contents
* `Basic go_test functionality <go_test/README.rst>`_
* `.. _#2067: https://github.com/bazelbuild/rules_go/issues/2067 <cgo/README.rst>`_
* `Runfiles functionality <runfiles/README.rst>`_
* `go_download_sdk <go_download_sdk/README.rst>`_
* `race instrumentation <race/README.rst>`_
* `stdlib functionality <stdlib/README.rst>`_
* `Basic go_binary functionality <go_binary/README.rst>`_
Expand Down
6 changes: 6 additions & 0 deletions tests/core/go_download_sdk/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
load("@io_bazel_rules_go//go/tools/bazel_testing:def.bzl", "go_bazel_test")

go_bazel_test(
name = "go_download_sdk_test",
srcs = ["go_download_sdk_test.go"],
)
7 changes: 7 additions & 0 deletions tests/core/go_download_sdk/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
go_download_sdk
===============

go_download_sdk_test
--------------------
Verifies that ``go_downlaod_sdk`` can be used to download a specific version
or a set of archives for various platforms.
122 changes: 122 additions & 0 deletions tests/core/go_download_sdk/go_download_sdk_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Copyright 2019 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_download_sdk_test

import (
"bytes"
"io/ioutil"
"testing"

"github.com/bazelbuild/rules_go/go/tools/bazel_testing"
)

func TestMain(m *testing.M) {
bazel_testing.TestMain(m, bazel_testing.Args{
Main: `
-- BUILD.bazel --
load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_test(
name = "version_test",
srcs = ["version_test.go"],
)

-- version_test.go --
package version_test

import (
"flag"
"runtime"
"testing"
)

var want = flag.String("version", "", "")

func Test(t *testing.T) {
if v := runtime.Version(); v != *want {
t.Errorf("got version %q; want %q", v, *want)
}
}
`,
})
}

func Test(t *testing.T) {
for _, test := range []struct {
desc, rule, wantVersion string
}{
{
desc: "version",
rule: `
load("@io_bazel_rules_go//go:deps.bzl", "go_download_sdk")

go_download_sdk(
name = "go_sdk",
version = "1.12.13",
)

`,
wantVersion: "go1.12.13",
}, {
desc: "custom_archives",
rule: `
load("@io_bazel_rules_go//go:deps.bzl", "go_download_sdk")

go_download_sdk(
name = "go_sdk",
sdks = {
"darwin_amd64": ("go1.12.13.darwin-amd64.tar.gz", "6d3de6f7d7c0e8162aaa009128839fa5afcba578dcbd6ff034a82419d82480e9"),
"linux_amd64": ("go1.12.13.linux-amd64.tar.gz", "da036454cb3353f9f507f0ceed4048feac611065e4e1818b434365eb32ac9bdc"),
"windows_amd64": ("go1.12.13.windows-amd64.zip", "c441a298e8b510d3cdabfd361885cd6762e33eaceb27cbb0eabe6757f9d1f07d"),
},
)
`,
wantVersion: "go1.12.13",
},
} {
t.Run(test.desc, func(t *testing.T) {
origWorkspaceData, err := ioutil.ReadFile("WORKSPACE")
if err != nil {
t.Fatal(err)
}

i := bytes.Index(origWorkspaceData, []byte("go_rules_dependencies()"))
if i < 0 {
t.Fatalf("%s: could not find call to go_rules_dependencies()")
}

buf := &bytes.Buffer{}
buf.Write(origWorkspaceData[:i])
buf.WriteString(test.rule)
buf.WriteString(`
go_rules_dependencies()

go_register_toolchains()
`)
if err := ioutil.WriteFile("WORKSPACE", buf.Bytes(), 0666); err != nil {
t.Fatal(err)
}
defer func() {
if err := ioutil.WriteFile("WORKSPACE", origWorkspaceData, 0666); err != nil {
t.Errorf("error restoring WORKSPACE: %v", err)
}
}()

if err := bazel_testing.RunBazel("test", "//:version_test", "--test_arg=-version="+test.wantVersion); err != nil {
t.Fatal(err)
}
})
}
}
24 changes: 0 additions & 24 deletions tests/legacy/build_with_old_sdk/BUILD.bazel

This file was deleted.

9 changes: 0 additions & 9 deletions tests/legacy/build_with_old_sdk/new_test.go

This file was deleted.

8 changes: 0 additions & 8 deletions tests/legacy/build_with_old_sdk/old_test.go

This file was deleted.

34 changes: 0 additions & 34 deletions tests/legacy/custom_go_toolchain/BUILD.bazel

This file was deleted.

14 changes: 0 additions & 14 deletions tests/legacy/custom_go_toolchain/version_test.go

This file was deleted.