Skip to content

Commit 80a0a57

Browse files
committed
Fix tests
1 parent 10a0289 commit 80a0a57

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ sh_binary(
5757
"buildbuddy.yaml": `
5858
actions:
5959
- name: "Test action"
60+
bazel_use_cli: false
6061
triggers: { push: { branches: [ master ] } }
6162
bazel_commands: [ "build //:nop" ]
6263
os: ` + runtime.GOOS + `
@@ -65,6 +66,32 @@ actions:
6566
}
6667
}
6768

69+
// simpleRepoUseCLI simulates a test repo that should use the bb CLI for bazel commands.
70+
// USE_BAZEL_VERSION is set to a pre-built bazel binary, which speeds up the test.
71+
func simpleRepoUseCLI(t *testing.T) map[string]string {
72+
return map[string]string{
73+
"BUILD": `
74+
sh_binary(
75+
name = "nop",
76+
srcs = ["nop.sh"],
77+
)
78+
`,
79+
"WORKSPACE": ``,
80+
"nop.sh": ``,
81+
"buildbuddy.yaml": fmt.Sprintf(`
82+
actions:
83+
- name: "Test action"
84+
bazel_use_cli: true
85+
triggers: { push: { branches: [ master ] } }
86+
bazel_commands: [ "build --enable_workspace --noenable_bzlmod //:nop" ]
87+
env:
88+
USE_BAZEL_VERSION: %q
89+
os: %s
90+
arch: %s
91+
`, testbazel.BinaryPath(t), runtime.GOOS, runtime.GOARCH),
92+
}
93+
}
94+
6895
// repoWithSlowScript simulates a test repo with the config files required to run a workflow
6996
// It sets up a slow script that takes a while to run so the CI runner does not return immediately,
7097
// giving tests that need to modify the workflow (Ex. for testing cancellation) time to complete
@@ -80,6 +107,7 @@ sh_binary(
80107
"buildbuddy.yaml": `
81108
actions:
82109
- name: "Slow test action"
110+
bazel_use_cli: false
83111
triggers: { push: { branches: [ master ] } }
84112
bazel_commands: [ "run //:sleep_forever_test" ]
85113
os: ` + runtime.GOOS + `
@@ -540,3 +568,30 @@ func TestInvalidYAML(t *testing.T) {
540568
func pointer[T any](val T) *T {
541569
return &val
542570
}
571+
572+
func TestUseCLI(t *testing.T) {
573+
fakeGitProvider := testgit.NewFakeProvider()
574+
env, workflowService := setup(t, fakeGitProvider)
575+
bb := env.GetBuildBuddyServiceClient()
576+
577+
repoContentsMap := simpleRepoUseCLI(t)
578+
repoPath, commitSHA := makeRepo(t, repoContentsMap)
579+
repoURL := fmt.Sprintf("file://%s", repoPath)
580+
581+
ctx := env.WithUserID(context.Background(), env.UserID1)
582+
reqCtx := &ctxpb.RequestContext{
583+
UserId: &uidpb.UserId{Id: env.UserID1},
584+
GroupId: env.GroupID1,
585+
}
586+
repo := createWorkflow(t, env, repoURL)
587+
588+
triggerWebhook(t, ctx, fakeGitProvider, workflowService, repo, repoContentsMap, repoURL, commitSHA)
589+
590+
iid := waitForAnyWorkflowInvocationCreated(t, ctx, bb, reqCtx)
591+
inv := waitForInvocationStatus(t, ctx, bb, reqCtx, iid, inspb.InvocationStatus_COMPLETE_INVOCATION_STATUS)
592+
593+
require.True(t, inv.GetSuccess(), "workflow invocation should succeed")
594+
require.Equal(t, repoURL, inv.GetRepoUrl())
595+
require.Equal(t, commitSHA, inv.GetCommitSha())
596+
require.Equal(t, "CI_RUNNER", inv.GetRole())
597+
}

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)