Skip to content

Commit ded5bac

Browse files
committed
test: cover configuration migration compatibility
1 parent 52966a2 commit ded5bac

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

src/GitVersion.Configuration.Tests/Configuration/ConfigurationMigrationServiceTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using SharpYaml;
2+
13
namespace GitVersion.Configuration.Tests;
24

35
[TestFixture]
@@ -44,6 +46,29 @@ public void AcceptsNestedConfigurationAndProducesDeterministicOutput()
4446
this.migrationService.Migrate(result).ShouldBe(result);
4547
}
4648

49+
[Test]
50+
public void MigratesConfiguredValuesWithoutAddingDefaults()
51+
{
52+
const string input = """
53+
workflow: GitHubFlow/v1
54+
mode: ContinuousDeployment
55+
update-build-number: false
56+
branches:
57+
main:
58+
increment: Minor
59+
pre-release-weight: 42
60+
""";
61+
62+
var result = this.migrationService.Migrate(input);
63+
64+
result.ShouldContain("workflow: GitHubFlow/v1");
65+
result.ShouldContain("mode: ContinuousDeployment");
66+
result.ShouldContain("update-build-number: false");
67+
result.ShouldContain("increment: Minor");
68+
result.ShouldContain("pre-release-weight: 42");
69+
result.ShouldNotContain("tag-prefix:");
70+
}
71+
4772
[Test]
4873
public void RejectsMixedConfiguration()
4974
{
@@ -54,4 +79,12 @@ public void RejectsMixedConfiguration()
5479

5580
Should.Throw<ConfigurationException>(() => this.migrationService.Migrate(input));
5681
}
82+
83+
[Test]
84+
public void RejectsMalformedYaml()
85+
{
86+
const string input = "branches: [";
87+
88+
Should.Throw<YamlException>(() => this.migrationService.Migrate(input));
89+
}
5790
}

src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,45 @@ public void WarnsOnceWhenExplicitV6LoadsAConfigurationFile()
467467
logMessages.ShouldContain(message => message.Contains("gitversion config migrate", StringComparison.Ordinal));
468468
}
469469

470+
[TestCase(null)]
471+
[TestCase("v7")]
472+
public void DoesNotWarnWhenV6IsNotExplicitlySelected(string? configurationVersion)
473+
{
474+
System.Environment.SetEnvironmentVariable(ConfigurationVersionSelector.EnvironmentVariableName, configurationVersion);
475+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: "");
476+
var logMessages = new List<string>();
477+
var loggerFactory = new TestLoggerFactory(logMessages.Add);
478+
var options = Options.Create(new GitVersionOptions { WorkingDirectory = this.repoPath });
479+
var sp = ConfigureServices(services =>
480+
{
481+
services.AddSingleton(options);
482+
loggerFactory.RegisterWith(services);
483+
});
484+
this.configurationProvider = (ConfigurationProvider)sp.GetRequiredService<IConfigurationProvider>();
485+
486+
this.configurationProvider.ProvideForDirectory(this.repoPath);
487+
488+
logMessages.ShouldNotContain(message => message.Contains("temporary v6 compatibility mode", StringComparison.Ordinal));
489+
}
490+
491+
[Test]
492+
public void DoesNotWarnForExplicitV6BuiltInDefaults()
493+
{
494+
var logMessages = new List<string>();
495+
var loggerFactory = new TestLoggerFactory(logMessages.Add);
496+
var options = Options.Create(new GitVersionOptions { WorkingDirectory = this.repoPath });
497+
var sp = ConfigureServices(services =>
498+
{
499+
services.AddSingleton(options);
500+
loggerFactory.RegisterWith(services);
501+
});
502+
this.configurationProvider = (ConfigurationProvider)sp.GetRequiredService<IConfigurationProvider>();
503+
504+
this.configurationProvider.ProvideForDirectory(this.repoPath);
505+
506+
logMessages.ShouldNotContain(message => message.Contains("temporary v6 compatibility mode", StringComparison.Ordinal));
507+
}
508+
470509
[Test]
471510
public void DoesNotWarnWhenExplicitV6ConfigurationFailsNormalization()
472511
{

0 commit comments

Comments
 (0)