Skip to content

Commit

Permalink
[bazel] //autoroll/go/repo_manager:repo_manager_test: Fix tests to wo…
Browse files Browse the repository at this point in the history
…rk on RBE.

Bug: skia:11110
Change-Id: I87ef4ce1dd33ae6bbf399022188a307f42c878a7
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/362160
Commit-Queue: Leandro Lovisolo <lovisolo@google.com>
Reviewed-by: Eric Boren <borenet@google.com>
  • Loading branch information
LeandroLovisolo authored and Skia Commit-Bot committed Jan 30, 2021
1 parent f60a23d commit 5dba627
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions autoroll/go/repo_manager/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ go_test(
"//autoroll/go/repo_manager/child",
"//autoroll/go/repo_manager/parent",
"//autoroll/go/revision",
"//bazel/go/bazel",
"//go/chrome_branch/mocks",
"//go/cipd/mocks",
"//go/common",
"//go/deepequal/assertdeep",
"//go/depot_tools",
"//go/depot_tools/deps_parser",
"//go/exec",
"//go/gerrit",
Expand All @@ -76,6 +78,7 @@ go_test(
"//go/mockhttpclient",
"//go/recipe_cfg",
"//go/skerr",
"//go/sklog",
"//go/testutils",
"//go/testutils/unittest",
"//go/util",
Expand Down
20 changes: 20 additions & 0 deletions autoroll/go/repo_manager/github_cipd_deps_repo_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"
"testing"
Expand All @@ -20,14 +21,18 @@ import (
"go.skia.org/infra/autoroll/go/repo_manager/child"
"go.skia.org/infra/autoroll/go/repo_manager/parent"
"go.skia.org/infra/autoroll/go/revision"
"go.skia.org/infra/bazel/go/bazel"
"go.skia.org/infra/go/cipd/mocks"
infra_common "go.skia.org/infra/go/common"
"go.skia.org/infra/go/deepequal/assertdeep"
"go.skia.org/infra/go/depot_tools"
"go.skia.org/infra/go/depot_tools/deps_parser"
"go.skia.org/infra/go/exec"
"go.skia.org/infra/go/git"
git_testutils "go.skia.org/infra/go/git/testutils"
"go.skia.org/infra/go/mockhttpclient"
"go.skia.org/infra/go/recipe_cfg"
"go.skia.org/infra/go/sklog"
"go.skia.org/infra/go/testutils"
"go.skia.org/infra/go/testutils/unittest"
"go.skia.org/infra/go/util"
Expand Down Expand Up @@ -88,6 +93,19 @@ func setupGithubCipdDEPS(t *testing.T, cfg *config.ParentChildRepoManagerConfig)
require.NoError(t, err)
ctx := context.Background()

// Under Bazel and RBE, there is no pre-existing depot_tools repository checkout for tests to use,
// so depot_tools.Get() will try to clone the depot_tools repository. However, the delegate "run"
// function of the exec.CommandCollector below skips any "git clone" commands. For this reason, we
// clone said repository here before setting up the aforementioned delegate "run" function, and
// make the checkout available to the caller test case via the corresponding environment variable.
originalDepotToolsTestEnvVar := os.Getenv(depot_tools.DEPOT_TOOLS_TEST_ENV_VAR)
if bazel.InRBE() {
depotToolsDir := filepath.Join(wd, "depot_tools")
_, err := git.NewCheckout(ctx, infra_common.REPO_DEPOT_TOOLS, wd)
require.NoError(t, err)
require.NoError(t, os.Setenv(depot_tools.DEPOT_TOOLS_TEST_ENV_VAR, depotToolsDir))
}

// Create parent repo.
parent := git_testutils.GitInit(t, ctx)
parent.Add(ctx, "DEPS", fmt.Sprintf(`
Expand All @@ -113,6 +131,7 @@ deps = {
mockRun.SetDelegateRun(func(ctx context.Context, cmd *exec.Command) error {
if strings.Contains(cmd.Name, "git") {
if cmd.Args[0] == "clone" || cmd.Args[0] == "fetch" || cmd.Args[0] == "reset" {
sklog.Infof("Skipping command: %s %s", cmd.Name, strings.Join(cmd.Args, " "))
return nil
}
if cmd.Args[0] == "checkout" && cmd.Args[1] == "remote/"+git.DefaultBranch {
Expand All @@ -138,6 +157,7 @@ deps = {

cleanup := func() {
testutils.RemoveAll(t, wd)
require.NoError(t, os.Setenv(depot_tools.DEPOT_TOOLS_TEST_ENV_VAR, originalDepotToolsTestEnvVar))
parent.Cleanup()
}

Expand Down

0 comments on commit 5dba627

Please sign in to comment.