@@ -117,12 +117,35 @@ public class SCMSourceRetrieverTest {
117
117
@ Rule public GitSampleRepoRule sampleRepo2 = new GitSampleRepoRule ();
118
118
@ Rule public SubversionSampleRepoRule sampleRepoSvn = new SubversionSampleRepoRule ();
119
119
120
- @ Issue ("JENKINS-40408" )
121
- @ Test public void lease () throws Exception {
120
+ // Repetitive helpers for test cases
121
+ private void sampleRepo1ContentMaster () throws Exception {
122
+ sampleRepo1ContentMaster (null );
123
+ }
124
+
125
+ private void sampleRepo1ContentMaster (String subdir ) throws Exception {
126
+ if (subdir != null && !(subdir .endsWith ("/" ))) subdir += "/" ;
127
+ if (subdir == null ) subdir = "" ;
122
128
sampleRepo .init ();
123
- sampleRepo .write ("vars/myecho.groovy" , "def call() {echo 'something special'}" );
124
- sampleRepo .git ("add" , "vars" );
129
+ sampleRepo .write (subdir + "vars/myecho.groovy" , "def call() {echo 'something special'}" );
130
+ sampleRepo .git ("add" , subdir + "vars" );
125
131
sampleRepo .git ("commit" , "--message=init" );
132
+ }
133
+
134
+ private void sampleRepo1ContentMasterAddLibraryCommit () throws Exception {
135
+ sampleRepo1ContentMasterAddLibraryCommit (null );
136
+ }
137
+
138
+ private void sampleRepo1ContentMasterAddLibraryCommit (String subdir ) throws Exception {
139
+ if (subdir != null && !(subdir .endsWith ("/" ))) subdir += "/" ;
140
+ if (subdir == null ) subdir = "" ;
141
+ sampleRepo .write ("vars/myecho.groovy" , "def call() {echo 'something even more special'}" );
142
+ sampleRepo .git ("add" , "vars" );
143
+ sampleRepo .git ("commit" , "--message=library_commit" );
144
+ }
145
+
146
+ @ Issue ("JENKINS-40408" )
147
+ @ Test public void lease () throws Exception {
148
+ sampleRepo1ContentMaster ();
126
149
GlobalLibraries .get ().setLibraries (Collections .singletonList (
127
150
new LibraryConfiguration ("echoing" ,
128
151
new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true )))));
@@ -143,10 +166,7 @@ public class SCMSourceRetrieverTest {
143
166
144
167
@ Issue ("JENKINS-41497" )
145
168
@ Test public void includeChanges () throws Exception {
146
- sampleRepo .init ();
147
- sampleRepo .write ("vars/myecho.groovy" , "def call() {echo 'something special'}" );
148
- sampleRepo .git ("add" , "vars" );
149
- sampleRepo .git ("commit" , "--message=init" );
169
+ sampleRepo1ContentMaster ();
150
170
GlobalLibraries .get ().setLibraries (Collections .singletonList (
151
171
new LibraryConfiguration ("include_changes" ,
152
172
new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true )))));
@@ -157,9 +177,7 @@ public class SCMSourceRetrieverTest {
157
177
WorkflowRun a = r .buildAndAssertSuccess (p );
158
178
r .assertLogContains ("something special" , a );
159
179
}
160
- sampleRepo .write ("vars/myecho.groovy" , "def call() {echo 'something even more special'}" );
161
- sampleRepo .git ("add" , "vars" );
162
- sampleRepo .git ("commit" , "--message=library_commit" );
180
+ sampleRepo1ContentMasterAddLibraryCommit ();
163
181
try (WorkspaceList .Lease lease = r .jenkins .toComputer ().getWorkspaceList ().acquire (base )) {
164
182
WorkflowRun b = r .buildAndAssertSuccess (p );
165
183
List <ChangeLogSet <? extends ChangeLogSet .Entry >> changeSets = b .getChangeSets ();
@@ -177,10 +195,7 @@ public class SCMSourceRetrieverTest {
177
195
178
196
@ Issue ("JENKINS-41497" )
179
197
@ Test public void dontIncludeChanges () throws Exception {
180
- sampleRepo .init ();
181
- sampleRepo .write ("vars/myecho.groovy" , "def call() {echo 'something special'}" );
182
- sampleRepo .git ("add" , "vars" );
183
- sampleRepo .git ("commit" , "--message=init" );
198
+ sampleRepo1ContentMaster ();
184
199
LibraryConfiguration lc = new LibraryConfiguration ("dont_include_changes" , new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true )));
185
200
lc .setIncludeInChangesets (false );
186
201
GlobalLibraries .get ().setLibraries (Collections .singletonList (lc ));
@@ -190,9 +205,7 @@ public class SCMSourceRetrieverTest {
190
205
try (WorkspaceList .Lease lease = r .jenkins .toComputer ().getWorkspaceList ().acquire (base )) {
191
206
WorkflowRun a = r .buildAndAssertSuccess (p );
192
207
}
193
- sampleRepo .write ("vars/myecho.groovy" , "def call() {echo 'something even more special'}" );
194
- sampleRepo .git ("add" , "vars" );
195
- sampleRepo .git ("commit" , "--message=library_commit" );
208
+ sampleRepo1ContentMasterAddLibraryCommit ();
196
209
try (WorkspaceList .Lease lease = r .jenkins .toComputer ().getWorkspaceList ().acquire (base )) {
197
210
WorkflowRun b = r .buildAndAssertSuccess (p );
198
211
List <ChangeLogSet <? extends ChangeLogSet .Entry >> changeSets = b .getChangeSets ();
@@ -203,10 +216,7 @@ public class SCMSourceRetrieverTest {
203
216
204
217
@ Issue ("JENKINS-38609" )
205
218
@ Test public void libraryPath () throws Exception {
206
- sampleRepo .init ();
207
- sampleRepo .write ("sub/path/vars/myecho.groovy" , "def call() {echo 'something special'}" );
208
- sampleRepo .git ("add" , "sub" );
209
- sampleRepo .git ("commit" , "--message=init" );
219
+ sampleRepo1ContentMaster ("sub/path" );
210
220
SCMSourceRetriever scm = new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true ));
211
221
LibraryConfiguration lc = new LibraryConfiguration ("root_sub_path" , scm );
212
222
lc .setIncludeInChangesets (false );
@@ -220,10 +230,7 @@ public class SCMSourceRetrieverTest {
220
230
221
231
@ Issue ("JENKINS-38609" )
222
232
@ Test public void libraryPathSecurity () throws Exception {
223
- sampleRepo .init ();
224
- sampleRepo .write ("sub/path/vars/myecho.groovy" , "def call() {echo 'something special'}" );
225
- sampleRepo .git ("add" , "sub" );
226
- sampleRepo .git ("commit" , "--message=init" );
233
+ sampleRepo1ContentMaster ("sub/path" );
227
234
SCMSourceRetriever scm = new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true ));
228
235
LibraryConfiguration lc = new LibraryConfiguration ("root_sub_path" , scm );
229
236
lc .setIncludeInChangesets (false );
@@ -1471,10 +1478,7 @@ public static class BasicSCMSource extends SCMSource {
1471
1478
1472
1479
@ Issue ("JENKINS-66629" )
1473
1480
@ Test public void renameDeletesOldLibsWorkspace () throws Exception {
1474
- sampleRepo .init ();
1475
- sampleRepo .write ("vars/myecho.groovy" , "def call() {echo 'something special'}" );
1476
- sampleRepo .git ("add" , "vars" );
1477
- sampleRepo .git ("commit" , "--message=init" );
1481
+ sampleRepo1ContentMaster ();
1478
1482
GlobalLibraries .get ().setLibraries (Collections .singletonList (
1479
1483
new LibraryConfiguration ("delete_removes_libs_workspace" ,
1480
1484
new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true )))));
@@ -1495,10 +1499,7 @@ public static class BasicSCMSource extends SCMSource {
1495
1499
1496
1500
@ Issue ("JENKINS-66629" )
1497
1501
@ Test public void deleteRemovesLibsWorkspace () throws Exception {
1498
- sampleRepo .init ();
1499
- sampleRepo .write ("vars/myecho.groovy" , "def call() {echo 'something special'}" );
1500
- sampleRepo .git ("add" , "vars" );
1501
- sampleRepo .git ("commit" , "--message=init" );
1502
+ sampleRepo1ContentMaster ();
1502
1503
GlobalLibraries .get ().setLibraries (Collections .singletonList (
1503
1504
new LibraryConfiguration ("delete_removes_libs_workspace" ,
1504
1505
new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true )))));
0 commit comments