Skip to content

Commit a59e20c

Browse files
committed
Fix tests
1 parent 10a0289 commit a59e20c

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

enterprise/server/test/integration/workflow/workflow_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"math"
77
"net/http"
88
"net/url"
9+
"os"
10+
"path/filepath"
911
"regexp"
1012
"runtime"
1113
"strconv"
@@ -57,6 +59,7 @@ sh_binary(
5759
"buildbuddy.yaml": `
5860
actions:
5961
- name: "Test action"
62+
bazel_use_cli: false
6063
triggers: { push: { branches: [ master ] } }
6164
bazel_commands: [ "build //:nop" ]
6265
os: ` + runtime.GOOS + `
@@ -65,6 +68,37 @@ actions:
6568
}
6669
}
6770

71+
// simpleRepoUseCLI simulates a test repo that should use the bb CLI for bazel commands.
72+
// USE_BAZEL_VERSION is set to a pre-built bazel binary, which speeds up the test.
73+
func simpleRepoUseCLI(t *testing.T) map[string]string {
74+
// The CLI expands all bazelrcs and appends `--ignore_all_rc_files` before invoking the testbazel binary
75+
// pointed to by USE_BAZEL_VERSION.
76+
// When the testbazel binary is invoked, it adds a --bazelrc at exec time, which is too late and is ignored due to `--ignore_all_rc_files`.
77+
// Here we explicitly add the bazelrc to the command.
78+
bazelrcPath := filepath.Join(os.Getenv("TEST_TMPDIR"), fmt.Sprintf("bazel-%s.bazelrc", testbazel.Version))
79+
return map[string]string{
80+
"BUILD": `
81+
sh_binary(
82+
name = "nop",
83+
srcs = ["nop.sh"],
84+
)
85+
`,
86+
"WORKSPACE": ``,
87+
"nop.sh": ``,
88+
"buildbuddy.yaml": fmt.Sprintf(`
89+
actions:
90+
- name: "Test action"
91+
bazel_use_cli: true
92+
triggers: { push: { branches: [ master ] } }
93+
bazel_commands: [ '--bazelrc=%s build //:nop' ]
94+
env:
95+
USE_BAZEL_VERSION: %q
96+
os: %s
97+
arch: %s
98+
`, bazelrcPath, testbazel.BinaryPath(t), runtime.GOOS, runtime.GOARCH),
99+
}
100+
}
101+
68102
// repoWithSlowScript simulates a test repo with the config files required to run a workflow
69103
// It sets up a slow script that takes a while to run so the CI runner does not return immediately,
70104
// giving tests that need to modify the workflow (Ex. for testing cancellation) time to complete
@@ -80,6 +114,7 @@ sh_binary(
80114
"buildbuddy.yaml": `
81115
actions:
82116
- name: "Slow test action"
117+
bazel_use_cli: false
83118
triggers: { push: { branches: [ master ] } }
84119
bazel_commands: [ "run //:sleep_forever_test" ]
85120
os: ` + runtime.GOOS + `
@@ -540,3 +575,30 @@ func TestInvalidYAML(t *testing.T) {
540575
func pointer[T any](val T) *T {
541576
return &val
542577
}
578+
579+
func TestBazelUseCLI(t *testing.T) {
580+
fakeGitProvider := testgit.NewFakeProvider()
581+
env, workflowService := setup(t, fakeGitProvider)
582+
bb := env.GetBuildBuddyServiceClient()
583+
584+
repoContentsMap := simpleRepoUseCLI(t)
585+
repoPath, commitSHA := makeRepo(t, repoContentsMap)
586+
repoURL := fmt.Sprintf("file://%s", repoPath)
587+
588+
ctx := env.WithUserID(context.Background(), env.UserID1)
589+
reqCtx := &ctxpb.RequestContext{
590+
UserId: &uidpb.UserId{Id: env.UserID1},
591+
GroupId: env.GroupID1,
592+
}
593+
repo := createWorkflow(t, env, repoURL)
594+
595+
triggerWebhook(t, ctx, fakeGitProvider, workflowService, repo, repoContentsMap, repoURL, commitSHA)
596+
597+
iid := waitForAnyWorkflowInvocationCreated(t, ctx, bb, reqCtx)
598+
inv := waitForInvocationStatus(t, ctx, bb, reqCtx, iid, inspb.InvocationStatus_COMPLETE_INVOCATION_STATUS)
599+
600+
require.True(t, inv.GetSuccess(), "workflow invocation should succeed")
601+
require.Equal(t, repoURL, inv.GetRepoUrl())
602+
require.Equal(t, commitSHA, inv.GetCommitSha())
603+
require.Equal(t, "CI_RUNNER", inv.GetRole())
604+
}

enterprise/server/workflow/service/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,8 +1277,8 @@ func (ws *workflowService) ciRunnerBazelCommand(ctx context.Context, wf *tables.
12771277
if wf.GitRepository != nil {
12781278
useCLI = wf.GitRepository.UseCLIInRemoteRunners
12791279
}
1280-
if workflowAction.UseCLI != nil {
1281-
useCLI = *workflowAction.UseCLI
1280+
if workflowAction.BazelUseCLI != nil {
1281+
useCLI = *workflowAction.BazelUseCLI
12821282
}
12831283
if useCLI {
12841284
return "bb"

0 commit comments

Comments
 (0)