Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions extension/buildrunner/noop/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
56 changes: 56 additions & 0 deletions extension/buildrunner/noop/noop.go
Original file line number Diff line number Diff line change
@@ -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
}
61 changes: 61 additions & 0 deletions extension/buildrunner/noop/noop_test.go
Original file line number Diff line number Diff line change
@@ -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"}))
}
Loading