Skip to content

Commit

Permalink
added test for the output with build server and json when running in …
Browse files Browse the repository at this point in the history
…build server
  • Loading branch information
arturcic committed Mar 12, 2020
1 parent d0f8a3c commit 101dea6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 29 deletions.
6 changes: 5 additions & 1 deletion src/GitVersionExe.Tests/ExecutionResults.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using GitVersion.OutputVariables;
Expand All @@ -21,7 +22,10 @@ public virtual VersionVariables OutputVariables
{
get
{
var outputVariables = JsonConvert.DeserializeObject<Dictionary<string, string>>(Output);
var jsonStartIndex = Output.IndexOf("{", StringComparison.Ordinal);
var json = Output.Substring(jsonStartIndex);

var outputVariables = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
return VersionVariables.FromDictionary(outputVariables);
}
}
Expand Down
27 changes: 0 additions & 27 deletions src/GitVersionExe.Tests/JsonOutputOnBuildServer.cs

This file was deleted.

45 changes: 45 additions & 0 deletions src/GitVersionExe.Tests/JsonOutputOnBuildServerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Collections.Generic;
using GitTools.Testing;
using GitVersion.BuildServers;
using NUnit.Framework;
using Shouldly;

namespace GitVersionExe.Tests
{
public class JsonOutputOnBuildServerTest
{
[Test]
public void BeingOnBuildServerDoesntOverrideOutputJson()
{
using var fixture = new RemoteRepositoryFixture();
fixture.Repository.MakeATaggedCommit("1.2.3");
fixture.Repository.MakeACommit();

var env = new KeyValuePair<string, string>(TeamCity.EnvironmentVariableName, "8.0.0");

var result = GitVersionHelper.ExecuteIn(fixture.LocalRepositoryFixture.RepositoryPath, arguments: " /output json", environments: env);

result.ExitCode.ShouldBe(0);
result.Output.ShouldStartWith("{");
result.Output.TrimEnd().ShouldEndWith("}");
}

[Test]
public void BeingOnBuildServerWithOutputJsonDoesNotFail()
{
using var fixture = new RemoteRepositoryFixture();
fixture.Repository.MakeATaggedCommit("1.2.3");
fixture.Repository.MakeACommit();

var env = new KeyValuePair<string, string>(TeamCity.EnvironmentVariableName, "8.0.0");

var result = GitVersionHelper.ExecuteIn(fixture.LocalRepositoryFixture.RepositoryPath, arguments: " /output json /output buildserver", environments: env);

result.ExitCode.ShouldBe(0);
const string version = "0.1.0+4";
result.Output.ShouldContain($"##teamcity[buildNumber '{version}']");
result.OutputVariables.ShouldNotBeNull();
result.OutputVariables.FullSemVer.ShouldBeEquivalentTo(version);
}
}
}
2 changes: 1 addition & 1 deletion src/GitVersionExe/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public Arguments ParseArguments(string[] commandLineArguments)
{
if (!Enum.TryParse(v, true, out OutputType outputType))
{
throw new WarningException($"Value '{value}' cannot be parsed as output type, please use 'json' or 'buildserver'");
throw new WarningException($"Value '{v}' cannot be parsed as output type, please use 'json' or 'buildserver'");
}

arguments.Output.Add(outputType);
Expand Down

0 comments on commit 101dea6

Please sign in to comment.