-
Notifications
You must be signed in to change notification settings - Fork 288
fix: prompt user to select agent queue for AzDO pipeline config #7707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vhvb1989
wants to merge
4
commits into
main
Choose a base branch
from
4248-azdoPipeline
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+220
−12
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
18ff60d
fix: prompt user to select agent queue for AzDO pipeline config (#4248)
vhvb1989 8fbc1c6
fix: address Copilot review feedback (iteration 1)
vhvb1989 a324e4b
fix: filter queues with nil/empty names to prevent panics (iteration 2)
vhvb1989 5310a15
fix: address Copilot review feedback (iteration 3)
vhvb1989 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package azdo | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/azure/azure-dev/cli/azd/pkg/input" | ||
| "github.com/azure/azure-dev/cli/azd/test/mocks/mockinput" | ||
| "github.com/microsoft/azure-devops-go-api/azuredevops/v7/taskagent" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestSelectAgentQueue(t *testing.T) { | ||
| t.Run("no queues returns error", func(t *testing.T) { | ||
| mockConsole := mockinput.NewMockConsole() | ||
|
|
||
| queue, err := selectAgentQueue(t.Context(), "project-1", nil, mockConsole) | ||
| assert.Nil(t, queue) | ||
| assert.ErrorContains(t, err, "no agent queues available in project project-1") | ||
| }) | ||
|
|
||
| t.Run("empty queues returns error", func(t *testing.T) { | ||
| mockConsole := mockinput.NewMockConsole() | ||
|
|
||
| queue, err := selectAgentQueue(t.Context(), "project-1", []taskagent.TaskAgentQueue{}, mockConsole) | ||
| assert.Nil(t, queue) | ||
| assert.ErrorContains(t, err, "no agent queues available in project project-1") | ||
| }) | ||
|
|
||
| t.Run("queues with nil names are filtered out", func(t *testing.T) { | ||
| mockConsole := mockinput.NewMockConsole() | ||
| queueId := 1 | ||
| queues := []taskagent.TaskAgentQueue{ | ||
| {Id: &queueId, Name: nil}, | ||
| } | ||
|
|
||
| queue, err := selectAgentQueue(t.Context(), "project-1", queues, mockConsole) | ||
| assert.Nil(t, queue) | ||
| assert.ErrorContains(t, err, "no agent queues available in project project-1") | ||
| }) | ||
|
|
||
| t.Run("queues with nil id are filtered out", func(t *testing.T) { | ||
| mockConsole := mockinput.NewMockConsole() | ||
| name := "Default" | ||
| queues := []taskagent.TaskAgentQueue{ | ||
| {Id: nil, Name: &name}, | ||
| } | ||
|
|
||
| queue, err := selectAgentQueue(t.Context(), "project-1", queues, mockConsole) | ||
| assert.Nil(t, queue) | ||
| assert.ErrorContains(t, err, "no agent queues available in project project-1") | ||
| }) | ||
|
|
||
| t.Run("nil name queues filtered leaving one valid", func(t *testing.T) { | ||
| mockConsole := mockinput.NewMockConsole() | ||
| id1 := 1 | ||
| id2 := 2 | ||
| validName := "Azure Pipelines" | ||
| queues := []taskagent.TaskAgentQueue{ | ||
| {Id: &id1, Name: nil}, | ||
| {Id: &id2, Name: &validName}, | ||
| } | ||
|
|
||
| queue, err := selectAgentQueue(t.Context(), "project-1", queues, mockConsole) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, queue) | ||
| assert.Equal(t, "Azure Pipelines", *queue.Name) | ||
| }) | ||
|
|
||
| t.Run("single queue auto-selects", func(t *testing.T) { | ||
| mockConsole := mockinput.NewMockConsole() | ||
| queueName := "Azure Pipelines" | ||
| queueId := 1 | ||
| queues := []taskagent.TaskAgentQueue{ | ||
| {Id: &queueId, Name: &queueName}, | ||
| } | ||
|
|
||
| queue, err := selectAgentQueue(t.Context(), "project-1", queues, mockConsole) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, queue) | ||
| assert.Equal(t, "Azure Pipelines", *queue.Name) | ||
| assert.Equal(t, 1, *queue.Id) | ||
| }) | ||
|
|
||
| t.Run("multiple queues prompts user", func(t *testing.T) { | ||
| mockConsole := mockinput.NewMockConsole() | ||
| mockConsole.WhenSelect(func(options input.ConsoleOptions) bool { | ||
| return strings.Contains(options.Message, "agent queue") | ||
| }).Respond(1) // select second queue | ||
vhvb1989 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| name1 := "Default" | ||
| id1 := 1 | ||
| name2 := "Azure Pipelines" | ||
| id2 := 2 | ||
| queues := []taskagent.TaskAgentQueue{ | ||
| {Id: &id1, Name: &name1}, | ||
| {Id: &id2, Name: &name2}, | ||
| } | ||
|
|
||
| queue, err := selectAgentQueue(t.Context(), "project-1", queues, mockConsole) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, queue) | ||
| assert.Equal(t, "Azure Pipelines", *queue.Name) | ||
| assert.Equal(t, 2, *queue.Id) | ||
| }) | ||
|
|
||
| t.Run("multiple queues selects first", func(t *testing.T) { | ||
| mockConsole := mockinput.NewMockConsole() | ||
| mockConsole.WhenSelect(func(options input.ConsoleOptions) bool { | ||
| return strings.Contains(options.Message, "agent queue") | ||
| }).Respond(0) // select first queue | ||
|
|
||
| name1 := "Default" | ||
| id1 := 1 | ||
| name2 := "Azure Pipelines" | ||
| id2 := 2 | ||
| queues := []taskagent.TaskAgentQueue{ | ||
| {Id: &id1, Name: &name1}, | ||
| {Id: &id2, Name: &name2}, | ||
| } | ||
|
|
||
| queue, err := selectAgentQueue(t.Context(), "project-1", queues, mockConsole) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, queue) | ||
| assert.Equal(t, "Default", *queue.Name) | ||
| assert.Equal(t, 1, *queue.Id) | ||
| }) | ||
|
|
||
| t.Run("select error is wrapped", func(t *testing.T) { | ||
| mockConsole := mockinput.NewMockConsole() | ||
| mockConsole.WhenSelect(func(options input.ConsoleOptions) bool { | ||
| return strings.Contains(options.Message, "agent queue") | ||
| }).RespondFn(func(_ input.ConsoleOptions) (any, error) { | ||
| return 0, fmt.Errorf("user cancelled") | ||
| }) | ||
|
|
||
| name1 := "Default" | ||
| id1 := 1 | ||
| name2 := "Azure Pipelines" | ||
| id2 := 2 | ||
| queues := []taskagent.TaskAgentQueue{ | ||
| {Id: &id1, Name: &name1}, | ||
| {Id: &id2, Name: &name2}, | ||
| } | ||
|
|
||
| queue, err := selectAgentQueue(t.Context(), "project-1", queues, mockConsole) | ||
| assert.Nil(t, queue) | ||
| assert.ErrorContains(t, err, "selecting agent queue") | ||
| assert.ErrorContains(t, err, "user cancelled") | ||
| }) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.