@@ -117,12 +117,35 @@ public class SCMSourceRetrieverTest {
117117 @ Rule public GitSampleRepoRule sampleRepo2 = new GitSampleRepoRule ();
118118 @ Rule public SubversionSampleRepoRule sampleRepoSvn = new SubversionSampleRepoRule ();
119119
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 = "" ;
122128 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" );
125131 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 ();
126149 GlobalLibraries .get ().setLibraries (Collections .singletonList (
127150 new LibraryConfiguration ("echoing" ,
128151 new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true )))));
@@ -143,10 +166,7 @@ public class SCMSourceRetrieverTest {
143166
144167 @ Issue ("JENKINS-41497" )
145168 @ 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 ();
150170 GlobalLibraries .get ().setLibraries (Collections .singletonList (
151171 new LibraryConfiguration ("include_changes" ,
152172 new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true )))));
@@ -157,9 +177,7 @@ public class SCMSourceRetrieverTest {
157177 WorkflowRun a = r .buildAndAssertSuccess (p );
158178 r .assertLogContains ("something special" , a );
159179 }
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 ();
163181 try (WorkspaceList .Lease lease = r .jenkins .toComputer ().getWorkspaceList ().acquire (base )) {
164182 WorkflowRun b = r .buildAndAssertSuccess (p );
165183 List <ChangeLogSet <? extends ChangeLogSet .Entry >> changeSets = b .getChangeSets ();
@@ -177,10 +195,7 @@ public class SCMSourceRetrieverTest {
177195
178196 @ Issue ("JENKINS-41497" )
179197 @ 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 ();
184199 LibraryConfiguration lc = new LibraryConfiguration ("dont_include_changes" , new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true )));
185200 lc .setIncludeInChangesets (false );
186201 GlobalLibraries .get ().setLibraries (Collections .singletonList (lc ));
@@ -190,9 +205,7 @@ public class SCMSourceRetrieverTest {
190205 try (WorkspaceList .Lease lease = r .jenkins .toComputer ().getWorkspaceList ().acquire (base )) {
191206 WorkflowRun a = r .buildAndAssertSuccess (p );
192207 }
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 ();
196209 try (WorkspaceList .Lease lease = r .jenkins .toComputer ().getWorkspaceList ().acquire (base )) {
197210 WorkflowRun b = r .buildAndAssertSuccess (p );
198211 List <ChangeLogSet <? extends ChangeLogSet .Entry >> changeSets = b .getChangeSets ();
@@ -203,10 +216,7 @@ public class SCMSourceRetrieverTest {
203216
204217 @ Issue ("JENKINS-38609" )
205218 @ 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" );
210220 SCMSourceRetriever scm = new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true ));
211221 LibraryConfiguration lc = new LibraryConfiguration ("root_sub_path" , scm );
212222 lc .setIncludeInChangesets (false );
@@ -220,10 +230,7 @@ public class SCMSourceRetrieverTest {
220230
221231 @ Issue ("JENKINS-38609" )
222232 @ 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" );
227234 SCMSourceRetriever scm = new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true ));
228235 LibraryConfiguration lc = new LibraryConfiguration ("root_sub_path" , scm );
229236 lc .setIncludeInChangesets (false );
@@ -1471,10 +1478,7 @@ public static class BasicSCMSource extends SCMSource {
14711478
14721479 @ Issue ("JENKINS-66629" )
14731480 @ 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 ();
14781482 GlobalLibraries .get ().setLibraries (Collections .singletonList (
14791483 new LibraryConfiguration ("delete_removes_libs_workspace" ,
14801484 new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true )))));
@@ -1495,10 +1499,7 @@ public static class BasicSCMSource extends SCMSource {
14951499
14961500 @ Issue ("JENKINS-66629" )
14971501 @ 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 ();
15021503 GlobalLibraries .get ().setLibraries (Collections .singletonList (
15031504 new LibraryConfiguration ("delete_removes_libs_workspace" ,
15041505 new SCMSourceRetriever (new GitSCMSource (null , sampleRepo .toString (), "" , "*" , "" , true )))));
0 commit comments