Skip to content

Commit 2f0f92d

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 b8601e9 commit 2f0f92d

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
@@ -141,15 +141,31 @@ private void sampleRepoNotifyCommit(GitSampleRepoRule sampleRepo) throws Excepti
141141
}
142142

143143
private void sampleRepo1ContentMaster() throws Exception {
144-
sampleRepo1ContentMaster(null);
144+
sampleRepo1ContentMaster(null, null);
145145
}
146146

147147
private void sampleRepo1ContentMaster(String subdir) throws Exception {
148+
sampleRepo1ContentMaster(subdir, null);
149+
}
150+
151+
private void sampleRepo1ContentMaster(String subdir, String addCustom) throws Exception {
148152
if (subdir != null && !(subdir.endsWith("/"))) subdir += "/";
149153
if (subdir == null) subdir = "";
150154
sampleRepo.init();
151155
sampleRepo.write(subdir + "vars/myecho.groovy", "def call() {echo 'something special'}");
152-
sampleRepo.git("add", subdir + "vars");
156+
if (addCustom == null) {
157+
sampleRepo.git("add", subdir + "vars");
158+
} else {
159+
if (addCustom == "") {
160+
if (subdir == "") {
161+
sampleRepo.git("add", ".");
162+
} else {
163+
sampleRepo.git("add", subdir);
164+
}
165+
} else {
166+
sampleRepo.git("add", addCustom);
167+
}
168+
}
153169
sampleRepo.git("commit", "--message=init");
154170
}
155171

@@ -1558,10 +1574,7 @@ public static class BasicSCMSource extends SCMSource {
15581574
}
15591575

15601576
@Test public void cloneModeLibraryPath() throws Exception {
1561-
sampleRepo.init();
1562-
sampleRepo.write("sub/path/vars/myecho.groovy", "def call() {echo 'something special'}");
1563-
sampleRepo.git("add", "sub");
1564-
sampleRepo.git("commit", "--message=init");
1577+
sampleRepo1ContentMaster("sub/path", "sub");
15651578
SCMSourceRetriever scm = new SCMSourceRetriever(new GitSCMSource(sampleRepo.toString()));
15661579
LibraryConfiguration lc = new LibraryConfiguration("root_sub_path", scm);
15671580
lc.setIncludeInChangesets(false);
@@ -1579,10 +1592,7 @@ public static class BasicSCMSource extends SCMSource {
15791592
}
15801593

15811594
@Test public void cloneModeLibraryPathSecurity() throws Exception {
1582-
sampleRepo.init();
1583-
sampleRepo.write("sub/path/vars/myecho.groovy", "def call() {echo 'something special'}");
1584-
sampleRepo.git("add", "sub");
1585-
sampleRepo.git("commit", "--message=init");
1595+
sampleRepo1ContentMaster("sub/path", "sub");
15861596
SCMSourceRetriever scm = new SCMSourceRetriever(new GitSCMSource(sampleRepo.toString()));
15871597
LibraryConfiguration lc = new LibraryConfiguration("root_sub_path", scm);
15881598
lc.setIncludeInChangesets(false);

0 commit comments

Comments
 (0)