diff --git a/src/Runner.Listener/Configuration/ConfigurationManager.cs b/src/Runner.Listener/Configuration/ConfigurationManager.cs index 4254bbdff50..bd84de8338f 100644 --- a/src/Runner.Listener/Configuration/ConfigurationManager.cs +++ b/src/Runner.Listener/Configuration/ConfigurationManager.cs @@ -165,7 +165,7 @@ public async Task ConfigureAsync(CommandSettings command) List agentPools = await _runnerServer.GetAgentPoolsAsync(); TaskAgentPool defaultPool = agentPools?.Where(x => x.IsInternal).FirstOrDefault(); - if (agentPools?.Where(x => !x.IsHosted).Count() > 1) + if (agentPools?.Where(x => !x.IsHosted).Count() > 0) { poolName = command.GetRunnerGroupName(defaultPool?.Name); _term.WriteLine(); diff --git a/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs b/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs index 706a11cd75a..2fff42c4e02 100644 --- a/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs +++ b/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs @@ -189,5 +189,48 @@ public async Task CanEnsureConfigure() _runnerServer.Verify(x => x.AddAgentAsync(It.IsAny(), It.Is(a => a.Labels.Select(x => x.Name).ToHashSet().SetEquals(expectedLabels))), Times.Once); } } + + [Fact] + [Trait("Level", "L0")] + [Trait("Category", "ConfigurationManagement")] + public async Task ConfigureErrorOnMissingRunnerGroup() + { + using (TestHostContext tc = CreateTestContext()) + { + var expectedPools = new List() { new TaskAgentPool(_defaultRunnerGroupName) { Id = _defaultRunnerGroupId, IsInternal = true } }; + _runnerServer.Setup(x => x.GetAgentPoolsAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(expectedPools)); + + Tracing trace = tc.GetTrace(); + + trace.Info("Creating config manager"); + IConfigurationManager configManager = new ConfigurationManager(); + configManager.Initialize(tc); + + + trace.Info("Preparing command line arguments"); + var command = new CommandSettings( + tc, + new[] + { + "configure", + "--url", _expectedServerUrl, + "--name", _expectedAgentName, + "--runnergroup", "notexists", + "--work", _expectedWorkFolder, + "--auth", _expectedAuthType, + "--token", _expectedToken, + }); + trace.Info("Constructed."); + _store.Setup(x => x.IsConfigured()).Returns(false); + _configMgrAgentSettings = null; + + trace.Info("Ensuring all the required parameters are available in the command line parameter"); + var ex = await Assert.ThrowsAsync(() => configManager.ConfigureAsync(command)); + + Assert.Contains("notexists", ex.Message); + + _runnerServer.Verify(x => x.GetAgentPoolsAsync(It.IsAny(), It.Is(p => p == TaskAgentPoolType.Automation)), Times.Exactly(1)); + } + } } }