Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JENKINS-15681: Support for Cloudbees Folders
- Loading branch information
Showing
6 changed files
with
197 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/test/java/org/jvnet/hudson/plugins/thinbackup/backup/TestBackupWithCloudBeesFolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package org.jvnet.hudson.plugins.thinbackup.backup; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Calendar; | ||
import java.util.Collection; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Assert; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.plugins.thinbackup.TestHelper; | ||
import org.jvnet.hudson.plugins.thinbackup.ThinBackupPeriodicWork.BackupType; | ||
import org.jvnet.hudson.plugins.thinbackup.utils.Utils; | ||
import org.jvnet.hudson.plugins.thinbackup.ThinBackupPluginImpl; | ||
|
||
public class TestBackupWithCloudBeesFolder { | ||
private static final String TEST_FOLDER = "testFolder"; | ||
private File backupDir; | ||
private File jenkinsHome; | ||
private File cloudBeesFolder; | ||
|
||
@Before | ||
public void setup() throws IOException { | ||
File base = new File(System.getProperty("java.io.tmpdir")); | ||
backupDir = TestHelper.createBackupFolder(base); | ||
|
||
jenkinsHome = TestHelper.createBasicFolderStructure(base); | ||
cloudBeesFolder = TestHelper.createCloudBeesFolder(jenkinsHome, TEST_FOLDER); | ||
File jobDir = TestHelper.createJob(cloudBeesFolder, TestHelper.TEST_JOB_NAME); | ||
TestHelper.addNewBuildToJob(jobDir); | ||
|
||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
FileUtils.deleteDirectory(jenkinsHome); | ||
FileUtils.deleteDirectory(backupDir); | ||
FileUtils.deleteDirectory(new File(Utils.THINBACKUP_TMP_DIR)); | ||
} | ||
|
||
@Test | ||
public void testCloudBeesFolderBackup() throws Exception { | ||
final Calendar cal = Calendar.getInstance(); | ||
cal.set(Calendar.MINUTE, cal.get(Calendar.MINUTE - 10)); | ||
|
||
final ThinBackupPluginImpl mockPlugin = TestHelper.createMockPlugin(jenkinsHome, backupDir); | ||
new HudsonBackup(mockPlugin, BackupType.FULL, cal.getTime()).backup(); | ||
|
||
final File backup = new File(backupDir, backupDir.list()[0]); | ||
File rootJobsFolder = new File(backup, HudsonBackup.JOBS_DIR_NAME); | ||
String[] list = rootJobsFolder.list(); | ||
Assert.assertThat(list, Matchers.arrayContainingInAnyOrder(TEST_FOLDER)); | ||
|
||
File cloudBeesFolder = new File(rootJobsFolder, list[0]); | ||
list = cloudBeesFolder.list(); | ||
Assert.assertThat(list, Matchers.arrayContainingInAnyOrder(HudsonBackup.JOBS_DIR_NAME, HudsonBackup.CONFIG_XML)); | ||
|
||
File childJobsFolder = new File(cloudBeesFolder, HudsonBackup.JOBS_DIR_NAME); | ||
list = childJobsFolder.list(); | ||
Assert.assertThat(list, Matchers.arrayContainingInAnyOrder(TestHelper.TEST_JOB_NAME)); | ||
|
||
File jobFolder = new File(childJobsFolder, TestHelper.TEST_JOB_NAME); | ||
list = jobFolder.list(); | ||
Assert.assertThat(list, Matchers.arrayContainingInAnyOrder(HudsonBackup.BUILDS_DIR_NAME, HudsonBackup.CONFIG_XML)); | ||
} | ||
|
||
@Test | ||
public void testRecursiveFolderBackup() throws Exception { | ||
File subFolderDirectory = TestHelper.createCloudBeesFolder(cloudBeesFolder, "subFolder"); | ||
TestHelper.createJob(subFolderDirectory, "folderJob"); | ||
|
||
final Calendar cal = Calendar.getInstance(); | ||
cal.set(Calendar.MINUTE, cal.get(Calendar.MINUTE - 10)); | ||
|
||
final ThinBackupPluginImpl mockPlugin = TestHelper.createMockPlugin(jenkinsHome, backupDir); | ||
new HudsonBackup(mockPlugin, BackupType.FULL, cal.getTime()).backup(); | ||
|
||
File subFolderJobsBackupDirectory = new File(backupDir, backupDir.list()[0]+"/jobs/"+TEST_FOLDER+"/jobs/subFolder/jobs"); | ||
String[] list = subFolderJobsBackupDirectory.list(); | ||
Assert.assertThat(list , Matchers.arrayContainingInAnyOrder("folderJob")); | ||
|
||
File jobFolder = new File(subFolderJobsBackupDirectory, "folderJob"); | ||
list = jobFolder.list(); | ||
Assert.assertThat(list, Matchers.arrayContainingInAnyOrder(HudsonBackup.CONFIG_XML)); | ||
} | ||
|
||
} |
Oops, something went wrong.
85a3c94
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW probably irrelevant for these tests (since you seem to be working at the
File
level), butMockFolder
in newer cores can be used to test behavior against folder-likeItem
s.