diff --git a/extension/buildrunner/noop/BUILD.bazel b/extension/buildrunner/noop/BUILD.bazel new file mode 100644 index 0000000..f53beb2 --- /dev/null +++ b/extension/buildrunner/noop/BUILD.bazel @@ -0,0 +1,24 @@ +load("@rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "noop", + srcs = ["noop.go"], + importpath = "github.com/uber/submitqueue/extension/buildrunner/noop", + visibility = ["//visibility:public"], + deps = [ + "//entity", + "//extension/buildrunner", + ], +) + +go_test( + name = "noop_test", + srcs = ["noop_test.go"], + embed = [":noop"], + deps = [ + "//entity", + "//extension/buildrunner", + "@com_github_stretchr_testify//assert", + "@com_github_stretchr_testify//require", + ], +) diff --git a/extension/buildrunner/noop/noop.go b/extension/buildrunner/noop/noop.go new file mode 100644 index 0000000..6163743 --- /dev/null +++ b/extension/buildrunner/noop/noop.go @@ -0,0 +1,56 @@ +// Copyright (c) 2025 Uber Technologies, Inc. +// +// 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 noop provides a buildrunner.BuildRunner that performs no real +// work: every triggered build immediately succeeds. It is intended as a +// stub for wiring tests and as a best-case baseline where every build +// passes. +package noop + +import ( + "context" + "fmt" + "sync/atomic" + + "github.com/uber/submitqueue/entity" + "github.com/uber/submitqueue/extension/buildrunner" +) + +// runner is a buildrunner.BuildRunner that does no real work and reports +// every build as immediately succeeded. The atomic counter hands out +// unique build IDs and makes the type safe for concurrent use. +type runner struct { + counter atomic.Uint64 +} + +// New returns a buildrunner.BuildRunner that performs no real work. +func New() buildrunner.BuildRunner { + return &runner{} +} + +// Trigger returns a unique build ID without contacting any runner. +// Inputs are ignored. +func (r *runner) Trigger(_ context.Context, _ string, _ []entity.Change, _ []entity.Change, _ entity.BuildMetadata) (entity.BuildID, error) { + return entity.BuildID{ID: fmt.Sprintf("noop-%d", r.counter.Add(1))}, nil +} + +// Status always reports BuildStatusSucceeded with no metadata. +func (r *runner) Status(_ context.Context, _ entity.BuildID) (entity.BuildStatus, entity.BuildMetadata, error) { + return entity.BuildStatusSucceeded, nil, nil +} + +// Cancel is a no-op. +func (r *runner) Cancel(_ context.Context, _ entity.BuildID) error { + return nil +} diff --git a/extension/buildrunner/noop/noop_test.go b/extension/buildrunner/noop/noop_test.go new file mode 100644 index 0000000..436725c --- /dev/null +++ b/extension/buildrunner/noop/noop_test.go @@ -0,0 +1,61 @@ +// Copyright (c) 2025 Uber Technologies, Inc. +// +// 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 noop + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/uber/submitqueue/entity" + "github.com/uber/submitqueue/extension/buildrunner" +) + +func TestNew_ImplementsInterface(t *testing.T) { + var _ buildrunner.BuildRunner = New() +} + +func TestRunner_Trigger(t *testing.T) { + r := New() + ctx := context.Background() + + id1, err := r.Trigger(ctx, "queueA", + []entity.Change{{URIs: []string{"github://owner/repo/pull/1"}}}, + []entity.Change{{URIs: []string{"github://owner/repo/pull/2"}}}, + entity.BuildMetadata{"requester": "alice"}, + ) + require.NoError(t, err) + assert.NotEmpty(t, id1.ID) + + // IDs are unique across calls, even with empty inputs. + id2, err := r.Trigger(ctx, "queueA", nil, nil, nil) + require.NoError(t, err) + assert.NotEqual(t, id1, id2) +} + +func TestRunner_Status(t *testing.T) { + r := New() + + status, meta, err := r.Status(context.Background(), entity.BuildID{ID: "any-id"}) + require.NoError(t, err) + assert.Equal(t, entity.BuildStatusSucceeded, status) + assert.Empty(t, meta) +} + +func TestRunner_Cancel(t *testing.T) { + r := New() + assert.NoError(t, r.Cancel(context.Background(), entity.BuildID{ID: "any-id"})) +}