Skip to content

Update version tests to use the new test framework #4443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,38 +1,20 @@
using System;
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Net.Http;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Azure.Functions.Cli.Common;
using Azure.Functions.Cli.Helpers;
using Azure.Functions.Cli.Tests.E2E.Helpers;
using FluentAssertions;
using Moq.Protected;
using Moq;
using Xunit;
using Xunit.Abstractions;
using static Azure.Functions.Cli.Helpers.VersionHelper;
using FluentAssertions;

namespace Azure.Functions.Cli.Tests.E2E
namespace Azure.Functions.Cli.Tests
{
public class VersionTests : BaseE2ETest
public class VersionHelperTests
{
public VersionTests(ITestOutputHelper output) : base(output) { }

[Theory]
[InlineData("-v")]
[InlineData("-version")]
[InlineData("--version")]
public async Task version(string args)
{
await CliTester.Run(new RunConfiguration
{
Commands = new[] { args },
OutputContains = new[] { "4." },
CommandTimeout = TimeSpan.FromSeconds(30)
}, _output);
}

[Fact]
public async Task IsRunningAnOlderVersion_ShouldReturnTrue_WhenVersionIsOlder()
{
Expand Down
32 changes: 32 additions & 0 deletions test/Cli/Func.E2E.Tests/Commands/FuncVersion/VersionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Azure.Functions.Cli.TestFramework.Assertions;
using Azure.Functions.Cli.TestFramework.Commands;
using Xunit;
using Xunit.Abstractions;

namespace Azure.Functions.Cli.E2E.Tests.Commands.FuncVersion
{
public class VersionTests(ITestOutputHelper log) : BaseE2ETests(log)
{
[Theory]
[InlineData("-v")]
[InlineData("-version")]
[InlineData("--version")]
public void Version_DisplaysVersionNumber(string args)
{
var testName = nameof(Version_DisplaysVersionNumber);
var versionCommand = new FuncVersionCommand(FuncPath, testName, Log);

// Execute the command
var result = versionCommand
.WithWorkingDirectory(WorkingDirectory)
.Execute(new[] { args });

// Verify the output contains a version number starting with "4."
result.Should().HaveStdOutContaining("4.");
result.Should().ExitWith(0);
}
}
}
34 changes: 34 additions & 0 deletions test/Cli/TestFramework/Commands/FuncVersionCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Xunit.Abstractions;

namespace Azure.Functions.Cli.TestFramework.Commands
{
public class FuncVersionCommand(string funcPath, string testName, ITestOutputHelper log) : FuncCommand(log)
{
private readonly string _commandName = "version";
private readonly string _funcPath = funcPath;
private readonly string _testName = testName;

protected override CommandInfo CreateCommand(IEnumerable<string> args)
{
var arguments = new List<string> { _commandName }.Concat(args).ToList();

if (WorkingDirectory is null)
{
throw new InvalidOperationException("Working Directory must be set");
}

var commandInfo = new CommandInfo()
{
FileName = _funcPath,
Arguments = arguments,
WorkingDirectory = WorkingDirectory,
TestName = _testName,
};

return commandInfo;
}
}
}