Skip to content

Commit 689035e

Browse files
authored
Use KV map to mock update
1 parent d8351e3 commit 689035e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/Runner.Listener/Runner.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -409,19 +409,19 @@ private async Task<int> RunAsync(RunnerSettings settings, bool runOnce = false)
409409
autoUpdateInProgress = true;
410410
var runnerUpdateMessage = JsonUtility.FromString<AgentRefreshMessage>(message.Body);
411411
// Can mock the update for testing
412-
if (true || StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable("GITHUB_ACTIONS_RUNNER_IS_MOCK_UPDATE")))
412+
if (StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable("GITHUB_ACTIONS_RUNNER_IS_MOCK_UPDATE")))
413413
{
414414

415-
// the runnmock_update_messages.json file should be of format [{"targetVersion":"2.284.1"}, {"targetVersion":"2.285.0"}]
415+
// the mock_update_messages.json file should be of format { "2.283.2": {"targetVersion":"2.284.1"}, "2.284.1": {"targetVersion":"2.285.0"}}
416416
var mockUpdatesPath = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Root), "mock_update_messages.json");
417417
if (File.Exists(mockUpdatesPath))
418418
{
419-
var mockUpdateMessages = JsonUtility.FromString<List<AgentRefreshMessage>>(File.ReadAllText(mockUpdatesPath));
420-
if (mockUpdateMessages.Any())
419+
var mockUpdateMessages = JsonUtility.FromString<Dictionary<string, AgentRefreshMessage>>(File.ReadAllText(mockUpdatesPath));
420+
if (mockUpdateMessages.ContainsKey(BuildConstants.RunnerPackage.Version))
421421
{
422-
// Mock only the version
423-
_term.WriteLine($"Mocking update, using version {mockUpdateMessages.First().TargetVersion} instead of {runnerUpdateMessage.TargetVersion}");
424-
runnerUpdateMessage = new AgentRefreshMessage(runnerUpdateMessage.AgentId, mockUpdateMessages.First().TargetVersion, runnerUpdateMessage.Timeout);
422+
var mockTargetVersion = mockUpdateMessages[BuildConstants.RunnerPackage.Version].TargetVersion;
423+
_term.WriteLine($"Mocking update, using version {mockTargetVersion} instead of {runnerUpdateMessage.TargetVersion}");
424+
runnerUpdateMessage = new AgentRefreshMessage(runnerUpdateMessage.AgentId, mockTargetVersion, runnerUpdateMessage.Timeout);
425425
var temp = JsonUtility.ToString(mockUpdateMessages.Skip(1));
426426
File.WriteAllText(mockUpdatesPath, JsonUtility.ToString(mockUpdateMessages.Skip(1)));
427427
}

0 commit comments

Comments
 (0)