|
| 1 | +// Copyright (c) 2025 Uber Technologies, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package noop |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/stretchr/testify/assert" |
| 22 | + "github.com/stretchr/testify/require" |
| 23 | + changepb "github.com/uber/submitqueue/api/base/change/protopb" |
| 24 | + strategypb "github.com/uber/submitqueue/api/base/mergestrategy/protopb" |
| 25 | + runwaymq "github.com/uber/submitqueue/api/runway/messagequeue" |
| 26 | + runwaypb "github.com/uber/submitqueue/api/runway/messagequeue/protopb" |
| 27 | +) |
| 28 | + |
| 29 | +func testRequest() *runwaymq.MergeRequest { |
| 30 | + return &runwaymq.MergeRequest{ |
| 31 | + Id: "queue-a/42", |
| 32 | + QueueName: "queue-a", |
| 33 | + Steps: []*runwaymq.MergeStep{ |
| 34 | + { |
| 35 | + StepId: "queue-a/1", |
| 36 | + Changes: []*changepb.Change{{Uris: []string{"github://uber/repo/pull/1/abcdef0123456789abcdef0123456789abcdef01"}}}, |
| 37 | + Strategy: strategypb.Strategy_REBASE, |
| 38 | + }, |
| 39 | + { |
| 40 | + StepId: "queue-a/2", |
| 41 | + Changes: []*changepb.Change{{Uris: []string{"github://uber/repo/pull/2/89abcdef0123456789abcdef0123456789abcdef"}}}, |
| 42 | + Strategy: strategypb.Strategy_MERGE, |
| 43 | + }, |
| 44 | + }, |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +func TestCheckMergeability(t *testing.T) { |
| 49 | + v := New() |
| 50 | + req := testRequest() |
| 51 | + |
| 52 | + res, err := v.CheckMergeability(context.Background(), req) |
| 53 | + require.NoError(t, err) |
| 54 | + |
| 55 | + assert.Equal(t, req.GetId(), res.GetId()) |
| 56 | + assert.Equal(t, runwaypb.Outcome_SUCCEEDED, res.GetOutcome()) |
| 57 | + require.Len(t, res.GetSteps(), 2) |
| 58 | + assert.Equal(t, "queue-a/1", res.GetSteps()[0].GetStepId()) |
| 59 | + assert.Empty(t, res.GetSteps()[0].GetOutputs()) |
| 60 | + assert.Equal(t, "queue-a/2", res.GetSteps()[1].GetStepId()) |
| 61 | + assert.Empty(t, res.GetSteps()[1].GetOutputs()) |
| 62 | +} |
| 63 | + |
| 64 | +func TestMerge(t *testing.T) { |
| 65 | + v := New() |
| 66 | + req := testRequest() |
| 67 | + |
| 68 | + res, err := v.Merge(context.Background(), req) |
| 69 | + require.NoError(t, err) |
| 70 | + |
| 71 | + assert.Equal(t, req.GetId(), res.GetId()) |
| 72 | + assert.Equal(t, runwaypb.Outcome_SUCCEEDED, res.GetOutcome()) |
| 73 | + require.Len(t, res.GetSteps(), 2) |
| 74 | + assert.Equal(t, "queue-a/1", res.GetSteps()[0].GetStepId()) |
| 75 | + require.Len(t, res.GetSteps()[0].GetOutputs(), 1) |
| 76 | + assert.NotEmpty(t, res.GetSteps()[0].GetOutputs()[0].GetId()) |
| 77 | + assert.Equal(t, "queue-a/2", res.GetSteps()[1].GetStepId()) |
| 78 | + require.Len(t, res.GetSteps()[1].GetOutputs(), 1) |
| 79 | + assert.NotEmpty(t, res.GetSteps()[1].GetOutputs()[0].GetId()) |
| 80 | +} |
| 81 | + |
| 82 | +func TestMerge_UniqueOutputIDs(t *testing.T) { |
| 83 | + v := New() |
| 84 | + req := testRequest() |
| 85 | + |
| 86 | + res1, err := v.Merge(context.Background(), req) |
| 87 | + require.NoError(t, err) |
| 88 | + res2, err := v.Merge(context.Background(), req) |
| 89 | + require.NoError(t, err) |
| 90 | + |
| 91 | + assert.NotEqual(t, res1.GetSteps()[0].GetOutputs()[0].GetId(), res2.GetSteps()[0].GetOutputs()[0].GetId()) |
| 92 | +} |
0 commit comments