11using System . Collections . Generic ;
2+ using System . IO ;
23using GitVersion ;
34using GitVersion . BuildAgents ;
45using GitVersionCore . Tests . Helpers ;
@@ -15,6 +16,7 @@ public class GitHubActionsTests : TestBase
1516 {
1617 private IEnvironment environment ;
1718 private GitHubActions buildServer ;
19+ private string githubSetEnvironmentTempFilePath ;
1820
1921 [ SetUp ]
2022 public void SetUp ( )
@@ -26,12 +28,21 @@ public void SetUp()
2628 environment = sp . GetService < IEnvironment > ( ) ;
2729 buildServer = sp . GetService < GitHubActions > ( ) ;
2830 environment . SetEnvironmentVariable ( GitHubActions . EnvironmentVariableName , "true" ) ;
31+
32+ githubSetEnvironmentTempFilePath = Path . GetTempFileName ( ) ;
33+ environment . SetEnvironmentVariable ( GitHubActions . GitHubSetEnvTempFileEnvironmentVariableName , githubSetEnvironmentTempFilePath ) ;
2934 }
3035
3136 [ TearDown ]
3237 public void TearDown ( )
3338 {
3439 environment . SetEnvironmentVariable ( GitHubActions . EnvironmentVariableName , null ) ;
40+ environment . SetEnvironmentVariable ( GitHubActions . GitHubSetEnvTempFileEnvironmentVariableName , null ) ;
41+ if ( githubSetEnvironmentTempFilePath != null && File . Exists ( githubSetEnvironmentTempFilePath ) )
42+ {
43+ File . Delete ( githubSetEnvironmentTempFilePath ) ;
44+ githubSetEnvironmentTempFilePath = null ;
45+ }
3546 }
3647
3748 [ Test ]
@@ -96,19 +107,17 @@ public void GetCurrentBranchShouldHandlePullRequests()
96107 result . ShouldBe ( "refs/pull/1/merge" ) ;
97108 }
98109
99- [ TestCase ( "Something" , "1.0.0" ,
100- "\" GitVersion_Something=1.0.0\" >> $GITHUB_ENV" ) ]
101- public void GetSetParameterMessage ( string key , string value , string expectedResult )
110+ [ Test ]
111+ public void GetSetParameterMessage ( )
102112 {
103113 // Assert
104114 environment . GetEnvironmentVariable ( "GitVersion_Something" ) . ShouldBeNullOrWhiteSpace ( ) ;
105115
106116 // Act
107- var result = buildServer . GenerateSetParameterMessage ( key , value ) ;
117+ var result = buildServer . GenerateSetParameterMessage ( "GitVersion_Something" , "1.0.0" ) ;
108118
109119 // Assert
110- result . ShouldContain ( s => true , 1 ) ;
111- result . ShouldBeEquivalentTo ( new [ ] { expectedResult } ) ;
120+ result . ShouldContain ( s => true , 0 ) ;
112121 }
113122
114123 [ Test ]
@@ -141,11 +150,20 @@ public void ShouldWriteIntegration()
141150 "Executing GenerateSetVersionMessage for 'GitHubActions'." ,
142151 "" ,
143152 "Executing GenerateBuildLogOutput for 'GitHubActions'." ,
144- "\" GitVersion_Major=1.0.0 \" >> $GITHUB_ENV"
153+ "Writing version variables to $GITHUB_ENV file for 'GitHubActions'. "
145154 } ;
146155
147156 string . Join ( Environment . NewLine , list )
148157 . ShouldBe ( string . Join ( Environment . NewLine , expected ) ) ;
158+
159+ var expectedFileContents = new List < string >
160+ {
161+ "GitVersion_Major=1.0.0"
162+ } ;
163+
164+ var actualFileContents = File . ReadAllLines ( githubSetEnvironmentTempFilePath ) ;
165+
166+ actualFileContents . ShouldBe ( expectedFileContents ) ;
149167 }
150168
151169 [ Test ]
0 commit comments