1
1
using System . Collections . Generic ;
2
+ using System . IO ;
2
3
using GitVersion ;
3
4
using GitVersion . BuildAgents ;
4
5
using GitVersionCore . Tests . Helpers ;
@@ -15,6 +16,7 @@ public class GitHubActionsTests : TestBase
15
16
{
16
17
private IEnvironment environment ;
17
18
private GitHubActions buildServer ;
19
+ private string githubSetEnvironmentTempFilePath ;
18
20
19
21
[ SetUp ]
20
22
public void SetUp ( )
@@ -26,12 +28,21 @@ public void SetUp()
26
28
environment = sp . GetService < IEnvironment > ( ) ;
27
29
buildServer = sp . GetService < GitHubActions > ( ) ;
28
30
environment . SetEnvironmentVariable ( GitHubActions . EnvironmentVariableName , "true" ) ;
31
+
32
+ githubSetEnvironmentTempFilePath = Path . GetTempFileName ( ) ;
33
+ environment . SetEnvironmentVariable ( GitHubActions . GitHubSetEnvTempFileEnvironmentVariableName , githubSetEnvironmentTempFilePath ) ;
29
34
}
30
35
31
36
[ TearDown ]
32
37
public void TearDown ( )
33
38
{
34
39
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
+ }
35
46
}
36
47
37
48
[ Test ]
@@ -96,19 +107,17 @@ public void GetCurrentBranchShouldHandlePullRequests()
96
107
result . ShouldBe ( "refs/pull/1/merge" ) ;
97
108
}
98
109
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 ( )
102
112
{
103
113
// Assert
104
114
environment . GetEnvironmentVariable ( "GitVersion_Something" ) . ShouldBeNullOrWhiteSpace ( ) ;
105
115
106
116
// Act
107
- var result = buildServer . GenerateSetParameterMessage ( key , value ) ;
117
+ var result = buildServer . GenerateSetParameterMessage ( "GitVersion_Something" , "1.0.0" ) ;
108
118
109
119
// Assert
110
- result . ShouldContain ( s => true , 1 ) ;
111
- result . ShouldBeEquivalentTo ( new [ ] { expectedResult } ) ;
120
+ result . ShouldContain ( s => true , 0 ) ;
112
121
}
113
122
114
123
[ Test ]
@@ -141,11 +150,20 @@ public void ShouldWriteIntegration()
141
150
"Executing GenerateSetVersionMessage for 'GitHubActions'." ,
142
151
"" ,
143
152
"Executing GenerateBuildLogOutput for 'GitHubActions'." ,
144
- "\" GitVersion_Major=1.0.0 \" >> $GITHUB_ENV"
153
+ "Writing version variables to $GITHUB_ENV file for 'GitHubActions'. "
145
154
} ;
146
155
147
156
string . Join ( Environment . NewLine , list )
148
157
. 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 ) ;
149
167
}
150
168
151
169
[ Test ]
0 commit comments