From 09821e2169bf0c173658654fc59af2e7ed30c3bd Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Fri, 2 Jul 2021 09:31:54 -0700 Subject: [PATCH] Check runner group when there is only `default` runner group. (#1172) * Check runner group when there is only `default` runner group. * L0 --- .../Configuration/ConfigurationManager.cs | 2 +- .../Configuration/ConfigurationManagerL0.cs | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/Runner.Listener/Configuration/ConfigurationManager.cs b/src/Runner.Listener/Configuration/ConfigurationManager.cs index 4254bbdff..bd84de833 100644 --- a/src/Runner.Listener/Configuration/ConfigurationManager.cs +++ b/src/Runner.Listener/Configuration/ConfigurationManager.cs @@ -165,7 +165,7 @@ namespace GitHub.Runner.Listener.Configuration 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 706a11cd7..2fff42c4e 100644 --- a/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs +++ b/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs @@ -189,5 +189,48 @@ namespace GitHub.Runner.Common.Tests.Listener.Configuration _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)); + } + } } }