Skip to content

Commit 7b49914

Browse files
committed
SCMSourceRetrieverTest.java: extend sampleRepo1ContentMaster() with optional addCustom path arg; refactor to simplify cloneModeLibraryPath() and cloneModeLibraryPathSecurity()
Signed-off-by: Jim Klimov <[email protected]>
1 parent 9a41258 commit 7b49914

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/test/java/org/jenkinsci/plugins/workflow/libs/SCMSourceRetrieverTest.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,31 @@ private void sampleRepoNotifyCommit(GitSampleRepoRule sampleRepo) throws Excepti
146146
}
147147

148148
private void sampleRepo1ContentMaster() throws Exception {
149-
sampleRepo1ContentMaster(null);
149+
sampleRepo1ContentMaster(null, null);
150150
}
151151

152152
private void sampleRepo1ContentMaster(String subdir) throws Exception {
153+
sampleRepo1ContentMaster(subdir, null);
154+
}
155+
156+
private void sampleRepo1ContentMaster(String subdir, String addCustom) throws Exception {
153157
if (subdir != null && !(subdir.endsWith("/"))) subdir += "/";
154158
if (subdir == null) subdir = "";
155159
sampleRepo.init();
156160
sampleRepo.write(subdir + "vars/myecho.groovy", "def call() {echo 'something special'}");
157-
sampleRepo.git("add", subdir + "vars");
161+
if (addCustom == null) {
162+
sampleRepo.git("add", subdir + "vars");
163+
} else {
164+
if (addCustom == "") {
165+
if (subdir == "") {
166+
sampleRepo.git("add", ".");
167+
} else {
168+
sampleRepo.git("add", subdir);
169+
}
170+
} else {
171+
sampleRepo.git("add", addCustom);
172+
}
173+
}
158174
sampleRepo.git("commit", "--message=init");
159175
}
160176

@@ -1563,10 +1579,7 @@ public static class BasicSCMSource extends SCMSource {
15631579
}
15641580

15651581
@Test public void cloneModeLibraryPath() throws Exception {
1566-
sampleRepo.init();
1567-
sampleRepo.write("sub/path/vars/myecho.groovy", "def call() {echo 'something special'}");
1568-
sampleRepo.git("add", "sub");
1569-
sampleRepo.git("commit", "--message=init");
1582+
sampleRepo1ContentMaster("sub/path", "sub");
15701583
SCMSourceRetriever scm = new SCMSourceRetriever(new GitSCMSource(sampleRepo.toString()));
15711584
LibraryConfiguration lc = new LibraryConfiguration("root_sub_path", scm);
15721585
lc.setIncludeInChangesets(false);
@@ -1584,10 +1597,7 @@ public static class BasicSCMSource extends SCMSource {
15841597
}
15851598

15861599
@Test public void cloneModeLibraryPathSecurity() throws Exception {
1587-
sampleRepo.init();
1588-
sampleRepo.write("sub/path/vars/myecho.groovy", "def call() {echo 'something special'}");
1589-
sampleRepo.git("add", "sub");
1590-
sampleRepo.git("commit", "--message=init");
1600+
sampleRepo1ContentMaster("sub/path", "sub");
15911601
SCMSourceRetriever scm = new SCMSourceRetriever(new GitSCMSource(sampleRepo.toString()));
15921602
LibraryConfiguration lc = new LibraryConfiguration("root_sub_path", scm);
15931603
lc.setIncludeInChangesets(false);

0 commit comments

Comments
 (0)