Skip to content

Commit bfc980f

Browse files
CopilotAArnott
andcommitted
Add test for NBGV_SetCloudBuildVersionVars property
Co-authored-by: AArnott <[email protected]>
1 parent 16a0fed commit bfc980f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/Nerdbank.GitVersioning.Tests/SomeGitBuildIntegrationTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,41 @@ public async Task NativeVersionInfo_CreateNativeResourceDll()
714714
}
715715
#endif
716716

717+
[Theory]
718+
[Trait("TestCategory", "FailsInCloudTest")]
719+
[MemberData(nameof(CloudBuildVariablesData))]
720+
public async Task SetCloudBuildVersionVars_CanBeDisabled(IReadOnlyDictionary<string, string> properties, string expectedMessage, bool setAllVariables)
721+
{
722+
using (ApplyEnvironmentVariables(properties))
723+
{
724+
// Disable SetCloudBuildVersionVars target
725+
this.testProject.AddProperty("NBGV_SetCloudBuildVersionVars", "false");
726+
727+
var versionOptions = new VersionOptions
728+
{
729+
Version = SemanticVersion.Parse("1.0"),
730+
CloudBuild = new VersionOptions.CloudBuildOptions { SetAllVariables = setAllVariables, SetVersionVariables = true },
731+
};
732+
this.WriteVersionFile(versionOptions);
733+
this.InitializeSourceControl();
734+
735+
BuildResults buildResult = await this.BuildAsync();
736+
this.AssertStandardProperties(versionOptions, buildResult);
737+
738+
// Assert GitBuildVersion was NOT set because we disabled the target
739+
string notExpectedMessage = UnitTestCloudBuildPrefix + expectedMessage
740+
.Replace("{NAME}", "GitBuildVersion")
741+
.Replace("{VALUE}", buildResult.BuildVersion);
742+
Assert.DoesNotContain(notExpectedMessage, buildResult.LoggedEvents.Select(e => e.Message.TrimEnd()));
743+
744+
// Assert GitBuildVersionSimple was NOT set
745+
notExpectedMessage = UnitTestCloudBuildPrefix + expectedMessage
746+
.Replace("{NAME}", "GitBuildVersionSimple")
747+
.Replace("{VALUE}", buildResult.BuildVersionSimple);
748+
Assert.DoesNotContain(notExpectedMessage, buildResult.LoggedEvents.Select(e => e.Message.TrimEnd()));
749+
}
750+
}
751+
717752
/// <inheritdoc/>
718753
protected override GitContext CreateGitContext(string path, string committish = null) => throw new NotImplementedException();
719754
}

0 commit comments

Comments
 (0)