|
9 | 9 | namespace GitVersion.App.Tests; |
10 | 10 |
|
11 | 11 | [TestFixture] |
| 12 | +[NonParallelizable] |
12 | 13 | public class ArgumentParserTests : TestBase |
13 | 14 | { |
14 | 15 | private IEnvironment environment = null!; |
15 | 16 | private IArgumentParser argumentParser = null!; |
16 | 17 | private IFileSystem fileSystem = null!; |
| 18 | + private string? originalConfigurationVersion; |
17 | 19 |
|
18 | 20 | [SetUp] |
19 | 21 | public void SetUp() |
20 | 22 | { |
| 23 | + this.originalConfigurationVersion = System.Environment.GetEnvironmentVariable(ConfigurationVersionSelector.EnvironmentVariableName); |
| 24 | + System.Environment.SetEnvironmentVariable(ConfigurationVersionSelector.EnvironmentVariableName, "v6"); |
21 | 25 | var sp = ConfigureServices(services => services.AddModule(new GitVersionAppModule())); |
22 | 26 | this.environment = sp.GetRequiredService<IEnvironment>(); |
23 | 27 | this.argumentParser = sp.GetRequiredService<IArgumentParser>(); |
24 | 28 | this.fileSystem = sp.GetRequiredService<IFileSystem>(); |
25 | 29 | } |
26 | 30 |
|
| 31 | + [TearDown] |
| 32 | + public void TearDown() => |
| 33 | + System.Environment.SetEnvironmentVariable(ConfigurationVersionSelector.EnvironmentVariableName, this.originalConfigurationVersion); |
| 34 | + |
| 35 | + [Test] |
| 36 | + public void OverrideConfigSupportsNestedV7RootAndBranchPaths() |
| 37 | + { |
| 38 | + System.Environment.SetEnvironmentVariable(ConfigurationVersionSelector.EnvironmentVariableName, "v7"); |
| 39 | + |
| 40 | + var arguments = this.argumentParser.ParseArguments( |
| 41 | + "--override-config calculation.tag-prefix=custom- " + |
| 42 | + "--override-config calculation.branches.main.increment=Major " + |
| 43 | + "--override-config output.branches.main.pre-release-weight=42"); |
| 44 | + |
| 45 | + var normalized = ConfigurationDocumentMapper.Normalize( |
| 46 | + arguments.OverrideConfiguration!, ConfigurationVersion.V7, "test override"); |
| 47 | + ConfigurationHelper configurationHelper = new(normalized); |
| 48 | + var configuration = configurationHelper.Configuration; |
| 49 | + configuration.TagPrefixPattern.ShouldBe("custom-"); |
| 50 | + configuration.Branches["main"].Increment.ShouldBe(IncrementStrategy.Major); |
| 51 | + configuration.Branches["main"].PreReleaseWeight.ShouldBe(42); |
| 52 | + } |
| 53 | + |
| 54 | + [Test] |
| 55 | + public void OverrideConfigRejectsV6PathInV7WithReplacement() |
| 56 | + { |
| 57 | + System.Environment.SetEnvironmentVariable(ConfigurationVersionSelector.EnvironmentVariableName, "v7"); |
| 58 | + |
| 59 | + var exception = Should.Throw<WarningException>(() => |
| 60 | + this.argumentParser.ParseArguments("--override-config tag-prefix=custom-")); |
| 61 | + |
| 62 | + exception.Message.ShouldContain("calculation.tag-prefix"); |
| 63 | + exception.Message.ShouldContain("config migrate"); |
| 64 | + } |
| 65 | + |
| 66 | + [Test] |
| 67 | + public void OverrideConfigRejectsPropertyInWrongV7SectionWithReplacement() |
| 68 | + { |
| 69 | + System.Environment.SetEnvironmentVariable(ConfigurationVersionSelector.EnvironmentVariableName, "v7"); |
| 70 | + |
| 71 | + var exception = Should.Throw<WarningException>(() => |
| 72 | + this.argumentParser.ParseArguments("--override-config calculation.update-build-number=false")); |
| 73 | + |
| 74 | + exception.Message.ShouldContain("output.update-build-number"); |
| 75 | + } |
| 76 | + |
| 77 | + [Test] |
| 78 | + public void OverrideConfigSupportsV6BranchPath() |
| 79 | + { |
| 80 | + var arguments = this.argumentParser.ParseArguments("--override-config branches.main.increment=Major"); |
| 81 | + |
| 82 | + ConfigurationHelper configurationHelper = new(arguments.OverrideConfiguration); |
| 83 | + configurationHelper.Configuration.Branches["main"].Increment.ShouldBe(IncrementStrategy.Major); |
| 84 | + } |
| 85 | + |
| 86 | + [Test] |
| 87 | + public void OverrideConfigRejectsV7PathInV6WithReplacement() |
| 88 | + { |
| 89 | + var exception = Should.Throw<WarningException>(() => |
| 90 | + this.argumentParser.ParseArguments("--override-config output.update-build-number=false")); |
| 91 | + |
| 92 | + exception.Message.ShouldContain("update-build-number"); |
| 93 | + exception.Message.ShouldContain("config migrate"); |
| 94 | + } |
| 95 | + |
| 96 | + [Test] |
| 97 | + public void OverrideConfigBatchValidationDoesNotApplyAnyValues() |
| 98 | + { |
| 99 | + System.Environment.SetEnvironmentVariable(ConfigurationVersionSelector.EnvironmentVariableName, "v7"); |
| 100 | + var parser = new OverrideConfigurationOptionParser(); |
| 101 | + |
| 102 | + Should.Throw<WarningException>(() => parser.SetValues( |
| 103 | + ["calculation.tag-prefix=custom-", "tag-prefix=legacy"], "--override-config")); |
| 104 | + |
| 105 | + parser.GetOverrideConfiguration().ShouldBeEmpty(); |
| 106 | + } |
| 107 | + |
27 | 108 | [Test] |
28 | 109 | public void EmptyMeansUseCurrentDirectory() |
29 | 110 | { |
|
0 commit comments