Skip to content

Commit

Permalink
[WIP] Add remote bazel integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
maggie-lou committed Apr 19, 2024
1 parent 1c067d2 commit f737538
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
11 changes: 11 additions & 0 deletions buildbuddy.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
actions:
- name: Maggie
container_image: ubuntu-20.04
triggers:
push:
branches:
- "master"
pull_request:
branches:
- "*"
bazel_commands:
- test cli/remotebazel/integration/... --test_env=BB_PROBER_ORG_API_KEY --config=linux-workflows --config=race --test_tag_filters=-performance,-webdriver,-docker,-bare
- name: Test
container_image: ubuntu-20.04
triggers:
Expand Down
24 changes: 24 additions & 0 deletions cli/remotebazel/integration/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load("@io_bazel_rules_go//go:def.bzl", "go_test")

package(default_visibility = ["//cli:__subpackages__"])

go_test(
name = "integration_test",
srcs = ["remote_bazel_test.go"],
exec_properties = {
"test.workload-isolation-type": "firecracker",
"test.recycle-runner": "true",
"test.runner-recycling-key": "remote-bazel-integration",
# The tests clone git repos, so make sure they have enough resources to do so
"test.EstimatedComputeUnits": "4",
"test.EstimatedFreeDiskBytes": "10GB",
# Use an image with bazelisk installed
"test.container-image": "docker://gcr.io/flame-public/rbe-ubuntu20-04-workflows@sha256:271e5e3704d861159c75b8dd6713dbe5a12272ec8ee73d17f89ed7be8026553f",
"include-secrets": "true",
},
deps = [
"//cli/remotebazel",
"//server/testutil/testshell",
"@com_github_stretchr_testify//require",
],
)
38 changes: 38 additions & 0 deletions cli/remotebazel/integration/remote_bazel_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package integration_test

import (
"fmt"
"os"
"testing"

"github.com/buildbuddy-io/buildbuddy/cli/remotebazel"
"github.com/buildbuddy-io/buildbuddy/server/testutil/testshell"
"github.com/stretchr/testify/require"
)

func TestWithPublicRepo(t *testing.T) {
apiKey := os.Getenv("BB_PROD_PROBER_ORG_API_KEY")
fmt.Printf("Api key is %s", apiKey)
// Root dir is persisted on recycled runners
rootDir := "/root/workspace/remote-bazel-integration-test"
err := os.Setenv("HOME", rootDir)
require.NoError(t, err)

err = os.MkdirAll(rootDir, 0755)
require.NoError(t, err)
err = os.Chdir(rootDir)
require.NoError(t, err)

if _, err := os.Stat(fmt.Sprintf("%s/bazel-gazelle", rootDir)); os.IsNotExist(err) {
output := testshell.Run(t, rootDir, "git clone https://github.com/bazelbuild/bazel-gazelle --filter=blob:none --depth=1")
require.NotContains(t, output, "fatal")
}

err = os.Chdir(fmt.Sprintf("%s/bazel-gazelle", rootDir))
require.NoError(t, err)

// TODO: Run a server and executor locally to run this against
exitCode, err := remotebazel.HandleRemoteBazel([]string{"help", fmt.Sprintf("--remote_header=x-buildbuddy-api-key=%s", apiKey)})
require.NoError(t, err)
require.Equal(t, 0, exitCode)
}
4 changes: 4 additions & 0 deletions server/testutil/testshell/testshell.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testshell

import (
"fmt"
"os/exec"
"testing"

Expand All @@ -12,6 +13,9 @@ func Run(t testing.TB, workDir, script string) string {
cmd := exec.Command("/usr/bin/env", "bash", "-e", "-c", script)
cmd.Dir = workDir
b, err := cmd.CombinedOutput()
if err != nil {
fmt.Printf("Script %q failed: %s", script, string(b))
}
require.NoError(t, err, "script %q failed: %s", script, string(b))
return string(b)
}

0 comments on commit f737538

Please sign in to comment.