|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +using Microsoft.VisualStudio.Services.Agent.Capabilities; |
| 5 | +using Microsoft.VisualStudio.Services.Agent.Util; |
| 6 | +using Moq; |
| 7 | +using System; |
| 8 | +using System.Collections.Generic; |
| 9 | +using System.Linq; |
| 10 | +using System.Threading; |
| 11 | +using System.Threading.Tasks; |
| 12 | +using Xunit; |
| 13 | + |
| 14 | +namespace Microsoft.VisualStudio.Services.Agent.Tests.Listener |
| 15 | +{ |
| 16 | + public sealed class PwshCapabilitiesProviderTestL0 |
| 17 | + { |
| 18 | + [Fact] |
| 19 | + [Trait("Level", "L0")] |
| 20 | + [Trait("Category", "Agent")] |
| 21 | + public async Task AddsPwshCapabilityWhenPwshExists() |
| 22 | + { |
| 23 | + using var hc = new TestHostContext(this); |
| 24 | + using var tokenSource = new CancellationTokenSource(); |
| 25 | + |
| 26 | + var pwshUtil = new Mock<IPwshExeUtil>(); |
| 27 | + pwshUtil.Setup(x => x.GetPath()).Returns("/usr/bin/pwsh"); |
| 28 | + hc.SetSingleton<IPwshExeUtil>(pwshUtil.Object); |
| 29 | + |
| 30 | + var provider = new PwshCapabilitiesProvider(); |
| 31 | + provider.Initialize(hc); |
| 32 | + |
| 33 | + List<Capability> capabilities = await provider.GetCapabilitiesAsync(new AgentSettings(), tokenSource.Token); |
| 34 | + |
| 35 | + Capability pwshCapability = capabilities.SingleOrDefault(x => string.Equals(x.Name, "Pwsh", StringComparison.Ordinal)); |
| 36 | + Assert.NotNull(pwshCapability); |
| 37 | + Assert.Equal("/usr/bin/pwsh", pwshCapability.Value); |
| 38 | + } |
| 39 | + |
| 40 | + [Fact] |
| 41 | + [Trait("Level", "L0")] |
| 42 | + [Trait("Category", "Agent")] |
| 43 | + public async Task ReturnsNoPwshCapabilityWhenPwshIsUnavailable() |
| 44 | + { |
| 45 | + using var hc = new TestHostContext(this); |
| 46 | + using var tokenSource = new CancellationTokenSource(); |
| 47 | + |
| 48 | + var pwshUtil = new Mock<IPwshExeUtil>(); |
| 49 | + pwshUtil.Setup(x => x.GetPath()).Throws(new InvalidOperationException("pwsh missing")); |
| 50 | + hc.SetSingleton<IPwshExeUtil>(pwshUtil.Object); |
| 51 | + |
| 52 | + var provider = new PwshCapabilitiesProvider(); |
| 53 | + provider.Initialize(hc); |
| 54 | + |
| 55 | + List<Capability> capabilities = await provider.GetCapabilitiesAsync(new AgentSettings(), tokenSource.Token); |
| 56 | + |
| 57 | + Assert.DoesNotContain(capabilities, x => string.Equals(x.Name, "Pwsh", StringComparison.Ordinal)); |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments