Skip to content
Merged
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
50 changes: 50 additions & 0 deletions src/GitVersion.App.Tests/ArgumentParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,56 @@ public void OverrideConfigBatchValidationDoesNotApplyAnyValues()
parser.GetOverrideConfiguration().ShouldBeEmpty();
}

[TestCase("config migrate --config GitVersion.yml")]
[TestCase("config migrate -c GitVersion.yml")]
[TestCase("--config GitVersion.yml config migrate")]
[TestCase("-c GitVersion.yml config migrate")]
public void ConfigMigrateParsesItsInputAndOutputOptions(string inputArguments)
{
var arguments = this.argumentParser.ParseArguments(
$"{inputArguments} --output GitVersion.v7.yml --force");

arguments.IsConfigurationMigration.ShouldBeTrue();
arguments.MigrationInputFile.ShouldBe("GitVersion.yml");
arguments.MigrationOutputFile.ShouldBe("GitVersion.v7.yml");
arguments.MigrationForce.ShouldBeTrue();
}

[Test]
public void ConfigMigrateUsesPositionalTargetPath()
{
var arguments = this.argumentParser.ParseArguments("path config migrate --in-place");

arguments.IsConfigurationMigration.ShouldBeTrue();
arguments.TargetPath.ShouldBe("path");
}

[Test]
public void ConfigMigrateRejectsOutputAndInPlaceTogether()
{
var exception = Should.Throw<WarningException>(() =>
this.argumentParser.ParseArguments("config migrate --output GitVersion.v7.yml --in-place"));

exception.Message.ShouldBe("Cannot use --output together with --in-place.");
}

[Test]
public void ConfigRequiresASubcommand()
{
var exception = Should.Throw<WarningException>(() => this.argumentParser.ParseArguments("config"));

exception.Message.ShouldBe("The 'config' command requires a subcommand. Use 'gitversion config migrate'.");
}

[Test]
public void TargetPathAllowsDirectoryNamedConfig()
{
var arguments = this.argumentParser.ParseArguments("--target-path config");

arguments.TargetPath.ShouldBe("config");
arguments.IsConfigurationMigration.ShouldBeFalse();
}

[Test]
public void EmptyMeansUseCurrentDirectory()
{
Expand Down
74 changes: 74 additions & 0 deletions src/GitVersion.App.Tests/ConfigurationMigrationExecutorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System.IO.Abstractions;
using GitVersion.Configuration;
using GitVersion.Tests;

namespace GitVersion.App.Tests;

[TestFixture]
public class ConfigurationMigrationExecutorTests
{
[Test]
public void InPlaceMigrationWarnsThatCommentsCannotBePreserved()
{
var directory = Directory.CreateTempSubdirectory();
try
{
var inputFile = Path.Combine(directory.FullName, "legacy.yml");
File.WriteAllText(inputFile, "next-version: 2.0.0");
var logMessages = new List<string>();
var executor = new ConfigurationMigrationExecutor(
new FileSystem(),
new TestConsoleAdapter(new StringBuilder()),
new TestLogger<ConfigurationMigrationExecutor>(logMessages.Add),
Substitute.For<IConfigurationFileLocator>(),
new ConfigurationMigrationService(new ConfigurationSerializer()));
var options = new GitVersionOptions { WorkingDirectory = directory.FullName };
options.ConfigurationMigrationInfo.IsMigration = true;
options.ConfigurationMigrationInfo.InputFile = inputFile;
options.ConfigurationMigrationInfo.InPlace = true;

executor.Execute(options).ShouldBe(0);

logMessages.ShouldContain(message => message.Contains("Comments cannot be preserved during migration.", StringComparison.Ordinal));
}
finally
{
directory.Delete(recursive: true);
}
}

[TestCase("workflow: GitHubFlow/v1\nnext-version: 2.0.0")]
[TestCase("calculation:\n workflow: GitHubFlow/v1\n next-version: 2.0.0")]
public void InPlaceMigrationWritesWorkflowAtRootAndIsIdempotent(string input)
{
var directory = Directory.CreateTempSubdirectory();
try
{
var inputFile = Path.Combine(directory.FullName, "GitVersion.yml");
File.WriteAllText(inputFile, input);
var executor = new ConfigurationMigrationExecutor(
new FileSystem(),
new TestConsoleAdapter(new StringBuilder()),
new TestLogger<ConfigurationMigrationExecutor>(),
Substitute.For<IConfigurationFileLocator>(),
new ConfigurationMigrationService(new ConfigurationSerializer()));
var options = new GitVersionOptions { WorkingDirectory = directory.FullName };
options.ConfigurationMigrationInfo.IsMigration = true;
options.ConfigurationMigrationInfo.InputFile = inputFile;
options.ConfigurationMigrationInfo.InPlace = true;

executor.Execute(options).ShouldBe(0);

var migrated = File.ReadAllText(inputFile);
migrated.ShouldContain("workflow: GitHubFlow/v1");
migrated.ShouldNotContain(" workflow:");
migrated.ShouldContain(" next-version: 2.0.0");
executor.Execute(options).ShouldBe(0);
File.ReadAllText(inputFile).ShouldBe(migrated);
}
finally
{
directory.Delete(recursive: true);
}
}
}
Loading
Loading