|
| 1 | +using System.Collections.Generic; |
| 2 | +using GitTools.Testing; |
| 3 | +using GitVersion.BuildServers; |
| 4 | +using NUnit.Framework; |
| 5 | +using Shouldly; |
| 6 | + |
| 7 | +namespace GitVersionExe.Tests |
| 8 | +{ |
| 9 | + public class JsonOutputOnBuildServerTest |
| 10 | + { |
| 11 | + [Test] |
| 12 | + public void BeingOnBuildServerDoesntOverrideOutputJson() |
| 13 | + { |
| 14 | + using var fixture = new RemoteRepositoryFixture(); |
| 15 | + fixture.Repository.MakeATaggedCommit("1.2.3"); |
| 16 | + fixture.Repository.MakeACommit(); |
| 17 | + |
| 18 | + var env = new KeyValuePair<string, string>(TeamCity.EnvironmentVariableName, "8.0.0"); |
| 19 | + |
| 20 | + var result = GitVersionHelper.ExecuteIn(fixture.LocalRepositoryFixture.RepositoryPath, arguments: " /output json", environments: env); |
| 21 | + |
| 22 | + result.ExitCode.ShouldBe(0); |
| 23 | + result.Output.ShouldStartWith("{"); |
| 24 | + result.Output.TrimEnd().ShouldEndWith("}"); |
| 25 | + } |
| 26 | + |
| 27 | + [Test] |
| 28 | + public void BeingOnBuildServerWithOutputJsonDoesNotFail() |
| 29 | + { |
| 30 | + using var fixture = new RemoteRepositoryFixture(); |
| 31 | + fixture.Repository.MakeATaggedCommit("1.2.3"); |
| 32 | + fixture.Repository.MakeACommit(); |
| 33 | + |
| 34 | + var env = new KeyValuePair<string, string>(TeamCity.EnvironmentVariableName, "8.0.0"); |
| 35 | + |
| 36 | + var result = GitVersionHelper.ExecuteIn(fixture.LocalRepositoryFixture.RepositoryPath, arguments: " /output json /output buildserver", environments: env); |
| 37 | + |
| 38 | + result.ExitCode.ShouldBe(0); |
| 39 | + const string version = "0.1.0+4"; |
| 40 | + result.Output.ShouldContain($"##teamcity[buildNumber '{version}']"); |
| 41 | + result.OutputVariables.ShouldNotBeNull(); |
| 42 | + result.OutputVariables.FullSemVer.ShouldBeEquivalentTo(version); |
| 43 | + } |
| 44 | + } |
| 45 | +} |
0 commit comments