Skip to content

Commit

Permalink
Check runner group when there is only default runner group. (#1172)
Browse files Browse the repository at this point in the history
* Check runner group when there is only `default` runner group.

* L0
  • Loading branch information
TingluoHuang authored Jul 2, 2021
1 parent 7c90b2a commit 09821e2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Runner.Listener/Configuration/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public async Task ConfigureAsync(CommandSettings command)
List<TaskAgentPool> 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();
Expand Down
43 changes: 43 additions & 0 deletions src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,48 @@ public async Task CanEnsureConfigure()
_runnerServer.Verify(x => x.AddAgentAsync(It.IsAny<int>(), It.Is<TaskAgent>(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<TaskAgentPool>() { new TaskAgentPool(_defaultRunnerGroupName) { Id = _defaultRunnerGroupId, IsInternal = true } };
_runnerServer.Setup(x => x.GetAgentPoolsAsync(It.IsAny<string>(), It.IsAny<TaskAgentPoolType>())).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<TaskAgentPoolNotFoundException>(() => configManager.ConfigureAsync(command));

Assert.Contains("notexists", ex.Message);

_runnerServer.Verify(x => x.GetAgentPoolsAsync(It.IsAny<string>(), It.Is<TaskAgentPoolType>(p => p == TaskAgentPoolType.Automation)), Times.Exactly(1));
}
}
}
}

0 comments on commit 09821e2

Please sign in to comment.